0

I'm getting the following error when I run the 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.

What am I doing wrong here?

1 Answer 1

2

Change line 349 of hmm_class.py to,

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Try to format your code either using 4 spaces or the code button which looks like {} in order to make your answers more readable.
Doesn't that mean there's a mistake in the library? Why should I meddle with the code from given library?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.