[英]ValueError when working with hidden_markov in python
I'm getting the following error when I run the train.hmm()
运行
train.hmm()
时出现以下错误
ValueError: operands could not be broadcast together with shapes (7,20) (1,7)
I know what a broadcast error is and went through the docs. 我知道广播错误是什么,并通过了文档。 But I cannot change dimensions of the matrix as it will pop an error in another place.
但是我无法更改矩阵的尺寸,因为它将在另一个地方弹出错误。 The code is as given below.
代码如下。
start_probability = np.matrix( '0.5 0.02 0.18 0.05 0.01 0.2 0.04 ')
transition_probability = np.matrix('0.9 0.012 0.012 0.012 0.002 0.05 0.012 \
; 0.03 0.35 0.05 0.05 0.02 0.45 0.05 \
; 0.03 0.05 0.45 0.05 0.02 0.35 0.05 \
; 0.1 0.1 0.1 0.4 0.1 0.1 0.1 \
; 0.1 0.1 0.1 0.1 0.4 0.1 0.1 \
; 0.2 0.05 0.05 0.05 0.05 0.4 0.2 \
; 0.12 0.12 0.12 0.12 0.01 0.12 0.39')
emission_probability = np.matrix(np.ones((7, 20)) * 0.05)
test = hmm(states,possible_observation,start_probability,transition_probability,emission_probability)
observations = ['A', 'S','T','A']
obs4 = ['C', 'A','G']
observation_tuple = []
observation_tuple.extend( [observations,obs4] )
quantities_observations = [10, 20]
num_iter=1000
e,t,s = test.train_hmm(observation_tuple,num_iter,quantities_observations)
The error corresponds to the last line. 错误对应于最后一行。 If I transpose the
start_prbability
or emission_probability
matrix, I'll get an error in the test = hmm()
line itself. 如果我转了
start_prbability
或emission_probability
矩阵,我将在得到一个错误test = hmm()
线本身。
What am I doing wrong here? 我在这里做错了什么?
Change line 349 of hmm_class.py
to, 将
hmm_class.py
第349行更改为
emProbNew = emProbNew/ np.reshape(em_norm.transpose(),[-1,1])
Not the best solution I know, but I think the author overlooked the fact that Python
would not always be able to know what he meant here with division. 这不是我所知道的最佳解决方案,但是我认为作者忽略了
Python
不能总是知道除法在这里意味着什么的事实。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.