pomegranate icon indicating copy to clipboard operation
pomegranate copied to clipboard

Trying to create a HMM from_matrix produces lIndexError: list index out of range

Open shr264 opened this issue 5 years ago • 1 comments

Hi,

I'm just getting started with this package but am running into an error. Here is the code to produce the error:

from pomegranate import DiscreteDistribution, HiddenMarkovModel import numpy as np

state_names = ['0', '1', '2', '3', '4'] n = len(state_names)

transmat = np.array([[0.2, 0.2, 0.2, 0.2, 0.2], [0.2, 0.2, 0.2, 0.2, 0.2], [0.2, 0.2, 0.2, 0.2, 0.2], [0.2, 0.2, 0.2, 0.2, 0.2], [0.2, 0.2, 0.2, 0.2, 0.2]])

state_dist = {word:1/n for word in state_names}
states = [ DiscreteDistribution(state_dist)]

start_probs = np.array([[0.2], [0.2], [0.2], [0.2], [0.2]])

model = HiddenMarkovModel.from_matrix(transition_probabilities=transmat, distributions=states, starts=start_probs, state_names=state_names)

shr264 avatar Nov 09 '19 19:11 shr264

Sorry for taking a while to get to this. You've defined your distributions to be a list with a single element in it. You need to define it to be a list with five distributions in it---one for each state in your model.

jmschrei avatar Dec 04 '19 07:12 jmschrei

Thank you for opening an issue. pomegranate has recently been rewritten from the ground up to use PyTorch instead of Cython (v1.0.0), and so all issues are being closed as they are likely out of date. Please re-open or start a new issue if a related issue is still present in the new codebase.

jmschrei avatar Apr 16 '23 06:04 jmschrei