jmschrei / pomegranate

Fast, flexible and easy to use probabilistic modelling in Python.
http://pomegranate.readthedocs.org/en/latest/
MIT License
3.29k stars 591 forks source link

Error when using baum-welch for model fitting #977

Closed malonzm1 closed 2 years ago

malonzm1 commented 2 years ago

When I use model.fit(sequence, algorithm='baum_welch') it throws the following error: Traceback (most recent call last): File "", line 1, in File "pomegranate/hmm.pyx", line 2659, in pomegranate.hmm.HiddenMarkovModel.fit File "pomegranate/hmm.pyx", line 2686, in pomegranate.hmm.HiddenMarkovModel.fit TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

Pls. advise.

jmschrei commented 2 years ago

Please provide more details when opening issues. It's impossible for me to know what's going on here (e.g., did you make an error when defining your model, in the structure of your data, etc), so I can't really provide any useful guidance.

malonzm1 commented 2 years ago

Thanks. This is the code I used.

s0 = State(NormalDistribution(0, 0.08), name = 's0') s1 = State(NormalDistribution(0.3, 0.06), name = 's1') s2 = State(NormalDistribution(-0.3, 0.06), name = 's2') model = HiddenMarkovModel() model.add_states(s0, s1, s2) model.add_transition(model.start, s0, 0.333) model.add_transition(model.start, s1, 0.333) model.add_transition(model.start, s2, 0.333) model.add_transition(s0, s0, 0.5) model.add_transition(s0, s1, 0.25) model.add_transition(s0, s2, 0.25) model.add_transition(s1, s0, 0.25) model.add_transition(s1, s1, 0.5) model.add_transition(s1, s2, 0.25) model.add_transition(s2, s0, 0.25) model.add_transition(s2, s1, 0.25) model.add_transition(s2, s2, 0.5) model.add_transition(s0, model.end, 0.333) model.add_transition(s1, model.end, 0.333) model.add_transition(s2, model.end, 0.333) model.bake() model.fit(diffs, algorithm='baum_welch')

It works fine when I use model.fit(sequence,algorithm='viterbi') or when I don't specify the algorithm.

jmschrei commented 2 years ago

The default is baum-welch, which is what you need to pass in, not baum_welch.

malonzm1 commented 2 years ago

Thanks!