markdregan/Bayesian-Modelling-in-Python

Section 2 pymc3 error

Closed this issue · 5 comments

Section 2 - Model Check II - Bayes Factor

Model fails

14 
  15     y_like = pm.DensityDist('y_like',
---> 16              lambda value: pm.switch(tau, 
  17                  pm.Poisson.dist(mu_p).logp(value),
  18                  pm.NegativeBinomial.dist(mu_nb, alpha).logp(value)

AttributeError: module 'pymc3' has no attribute 'switch'

Found a fix suggested by Cameron Davidson-Pilson which looks like it was intended to be merged into your code (but seems it wasn't?). The suggested revision to lambda works fine.

  y_like = pm.DensityDist('y_like',
               lambda value: pm.math.switch(tau, 
                   pm.Poisson.dist(mu_p).logp(value),
                   pm.NegativeBinomial.dist(mu_nb, alpha).logp(value)
               ),
               observed=messages['time_delay_seconds'].values)

Yep, we changed that namespace, easy fix.

@krispy1946 Maybe do a PR.

Thanks for flagging Chris. I'm re-running all notebooks now and fixing issues. Been a while and PYMC3 has come on even further since I last used it. Will push later this weekend.

Pushed updated notebooks.
pm.math.switch issue fixed.