hmmlearn GMMHMM中的参数参数未按预期工作



我有一维(单一特征(数据,我想将GMMHMM拟合到其中。有两个隐藏状态,我知道每个状态输出的概率分布。也就是说,我知道先验分布,因此知道GMM参数。因此,我不希望hmmlearn对象更新GMM的均值covars权重

我想使用paramsinit_paramsarguments来实现这一点,方法是将它们设置为仅更新startprobtransmat

但hmmlearn最终也更新了均值covars权重。我如何阻止它更新这些,并让它只更新startprobtransmat

这是我的代码

# Initialize the GMMHMM
means_prior = known_means
covars_prior = known_covars
weights_prior = known_weights
gmm_hmm = hmm.GMMHMM(n_components=n_comps, n_mix=n_mix, weights_prior=weights_prior,
means_prior=means_prior, covars_prior=covars_prior,
covariance_type='spherical', params='st', init_params='st')
gmm_hmm.means_ = means_prior
gmm_hmm.weights_ = weights_prior
gmm_hmm.covars_ = covars_prior
print('Before fitting...')
print('means')
print(gmm_hmm.means_)
print('weights')
print(gmm_hmm.weights_)
print('covars')
print(gmm_hmm.covars_)
# Fit the GMMHMM to the input sequence
gmm_hmm.fit(input_sequence)
print('After fitting...')
print('means')
print(gmm_hmm.means_)
print('weights')
print(gmm_hmm.weights_)
print('covars')
print(gmm_hmm.covars_)

您可以看到权重covar发生了变化,尽管意味着保持不变。

Before fitting...
means
[[[51.30211436]
[53.32515359]]
[[63.47895865]
[57.19121711]]]
weights
[[0.58624271 0.41375729]
[0.48605807 0.51394193]]
covars
[[ 0.6483754   1.2042972 ]
[13.85258908  1.04639497]]
After fitting...
means
[[[51.16975532]
[54.19504787]]
[[65.82853658]
[54.25868767]]]
weights
[[0.88971249 0.11028751]
[0.30707459 0.69292541]]
covars
[[ 0.56903044  0.70862057]
[14.77828965  0.56072741]]

非常感谢你的帮助!

GMMHMM文档

init_params:控制在训练前初始化哪些参数。可以包含startprob的"s"、transmat的"t"、means的"m"、covars的"c"和GMM混合权重的"w"的任意组合。默认为所有参数

params:控制在训练过程中更新哪些参数。可以包含startprob的"s"、transmat的"t"、means的"m"、covars的"c"以及GMM混合权重的"w"的任意组合。默认为所有参数

从文档中:https://hmmlearn.readthedocs.io/en/latest/api.html#hmmlearn.hmm.GaussianHMM初始化模型时,请尝试使用startprob_priortransmat_prior参数。

model = hmm.GaussianHMM(n_components=n_components, startprob_prior=pi_mat, transmat_prior=a_mat)

相关内容

  • 没有找到相关文章

最新更新