使用 HMMLEARN 0.2.1,我得到了这个错误
Traceback (most recent call last):
File "hmmlearn_ex.py", line 48, in <module>
hidden_states = model.predict(X)
File "/usr/local/lib/python3.5/site-packages/hmmlearn-0.2.1-py3.5- linux-x86_64.egg/hmmlearn/base.py", line 336, in predict
_, state_sequence = self.decode(X, lengths)
File "/usr/local/lib/python3.5/site-packages/hmmlearn-0.2.1-py3.5-linux-x86_64.egg/hmmlearn/base.py", line 296, in decode
self._check()
File "/usr/local/lib/python3.5/site-packages/hmmlearn-0.2.1-py3.5-linux-x86_64.egg/hmmlearn/hmm.py", line 180, in _check
super(GaussianHMM, self)._check()
File "/usr/local/lib/python3.5/site-packages/hmmlearn-0.2.1-py3.5-linux-x86_64.egg/hmmlearn/base.py", line 527, in _check. format(self.transmat_.sum(axis=1)))
ValueError: rows of transmat_ must sum to 1.0 (got
[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 0. 1. 1. 0. 1. 1. 1. 1. 0. 1. 1. 1. 1. 1. 0. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 0. 1. 1. 0. 1. 1. 1. 1. 0. 1. 1. 1. 1. 1. 1. 0. 1. 1. 1. 0. 1. 1. 1.])
下面是我的代码:
import numpy as np
import speech_data_conso
import hmmlearn
from hmmlearn.hmm import GaussianHMM, MultinomialHMM
#Parameters
speech_data_conso.DELTA = False
SET = 'A'
load_savemodel = True
batch_size_1 = 200 # 9600
validate_batch_size_1 = 20 # 2400
learning_rate = 0.001 # 0.001
training_iter = 30000000 # 300000
n_states = 7
if speech_data_conso.DELTA :
MODEL_PATH = '/home/jirayu/Desktop/MFCC/DELTA/MODEL/SET_' + SET + '/MODEL.tfl' # for save model
RESULT_PATH = '/home/jirayu/Desktop/MFCC/DELTA/MODEL/SET_' + SET + '/result.log'
#DATA_DIR='/home/jirayu/Desktop/MFCC/SET_A/MISS6/'
TRAINING_DIR_1 = '/home/jirayu/Desktop/MFCC/DELTA/SET_' + SET + '/TRAIN/'
VALIDATION_DIR_1 = '/home/jirayu/Desktop/MFCC/DELTA/SET_' + SET + '/INPUT/'
else :
MODEL_PATH = '/home/jirayu/Desktop/MFCC/NO-DELTA/MODEL/SET_' + SET + '/MODEL.tfl' # for save model
RESULT_PATH = '/home/jirayu/Desktop/MFCC/NO-DELTA/MODEL/SET_' + SET + '/result.log'
#DATA_DIR='/home/jirayu/Desktop/MFCC/SET_A/MISS6/'
TRAINING_DIR_1 = '/home/jirayu/Desktop/MFCC/NO-DELTA/SET_' + SET + '/TRAIN/'
VALIDATION_DIR_1 = '/home/jirayu/Desktop/MFCC/NO-DELTA/SET_' + SET + '/INPUT/'
# training batch - 1
speech_data_conso.DATA_DIR = TRAINING_DIR_1
batch=speech_data_conso.spectro_batch_generator(batch_size_1)
X,Y,Z=next(batch)
# validation batch - 1
speech_data_conso.DATA_DIR = VALIDATION_DIR_1
batch=speech_data_conso.spectro_batch_generator(validate_batch_size_1)
P,Q,R=next(batch)
diff = np.diff(X)
input_x = np.column_stack([diff, Z])
model = GaussianHMM(n_components=120, covariance_type="diag", n_iter=10, init_params="st").fit(input_x)
#model = MultinomialHMM(n_components=n_states).fit(input_x)
hidden_states = model.predict(P)
print("done")
########################################################################## #####
# Print trained parameters and plot
print("Transition matrix")
print(model.transmat_)
print()
print("Means and vars of each hidden state")
for i in range(model.n_components):
print("{0}th hidden state".format(i))
print("mean = ", model.means_[i])
print("var = ", np.diag(model.covars_[i]))
print()
请帮助我将需要使用 HMM 进行研究,我确信我以正确的方式实现了这段代码,并且还在互联网上研究了我做对了,许多人在 hmmlearn 最新版本中仍然没有解决同样的问题
同样在预测时(我切换到使用 GMMHMM 进行训练):
warnings.warn(msg, category=DeprecationWarning)
Traceback (most recent call last):
File "hmmlearn_ex.py", line 49, in <module>
hidden_states = model.predict(P)
File "/usr/local/lib/python3.5/site-packages/hmmlearn-0.2.1-py3.5- linux-x86_64.egg/hmmlearn/base.py", line 336, in predict
_, state_sequence = self.decode(X, lengths)
File "/usr/local/lib/python3.5/site-packages/hmmlearn-0.2.1-py3.5-linux-x86_64.egg/hmmlearn/base.py", line 296, in decode
self._check()
File "/usr/local/lib/python3.5/site-packages/hmmlearn-0.2.1-py3.5-linux-x86_64.egg/hmmlearn/hmm.py", line 713, in _check
super(GMMHMM, self)._check()
File "/usr/local/lib/python3.5/site-packages/hmmlearn-0.2.1-py3.5-linux-x86_64.egg/hmmlearn/base.py", line 519, in _check
.format(self.startprob_.sum()))
ValueError: startprob_ 总和必须为 1.0(得到 nan)