AmpersandTV / pymc3-hmm

Hidden Markov models in PyMC3
Other
94 stars 13 forks source link

Poisson-zero Hidden Markov Model example does not run #74

Closed rlouf closed 3 years ago

rlouf commented 3 years ago

Poisson-zero Hidden Markov Model example does not run

Execute the notebook until cell 6 to notice the error. The following exception is raised:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-46-437d1704a6eb> in <module>
      6 
      7 with test_model:
----> 8     transmat_step = TransMatConjugateStep(test_model.P_rv)
      9     states_step = FFBSStep([test_model.S_t])
     10     mu_step = pm.NUTS([test_model.mu])

AttributeError: 'Model' object has no attribute 'P_rv'

Replacing the offending line with

transmat_step = TransMatConjugateStep(test_model.P_tt)

solves the problem (and should be correct if I understand the library correctly). Then there is an error with the initial value when trying to sample from the model's posterior. This is due to S_t being initialized as an array of 0s and is solved by setting the test value of S_t as such in the model definition:

S_rv.tag.test_value = np.array(observed > 0, dtype=np.int32)
brandonwillard commented 3 years ago

The updates for that example are currently in #66.

rlouf commented 3 years ago

Looks like the issues were addressed in the PR already.