Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example 8.21 may have some typos #1

Closed
MooersLab opened this issue Nov 14, 2017 · 6 comments
Closed

Example 8.21 may have some typos #1

MooersLab opened this issue Nov 14, 2017 · 6 comments

Comments

@MooersLab
Copy link

PyMC3 example of NB regression in Code_8.21.py gives the following error message.

File "code_8.21.py", line 50, in
y = pm.NegativeBinomial('y', mu=pm.exp(eta), alpha=alpha, observed=y)
AttributeError: module 'pymc3' has no attribute 'exp'

I think that the pm.exp(eta) should be replaced with np.exp(eta).
I get the same result with Python2.7 and Python3.5.
I am using PyMC3 version 3.1.

After making the above change, the script runs for a much longer time and then throuws an error on line 54

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/statsmodels/compat/pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead.
from pandas.core import datetools
Optimization terminated successfully.
Current function value: 3854.710331
Iterations: 31
Function evaluations: 48
Gradient evaluations: 48
Traceback (most recent call last):
File "./code_8.21.py", line 54, in
step = pm.NUTS(state=start) # Initiate sampling
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymc3/step_methods/hmc/nuts.py", line 149, in init
super(NUTS, self).init(vars, use_single_leapfrog=True, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymc3/step_methods/hmc/base_hmc.py", line 64, in init
vars, shared, model.logpt, self.potential, use_single_leapfrog, integrator, **theano_kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymc3/step_methods/hmc/trajectory.py", line 124, in get_theano_hamiltonian_functions
energy_function, p = _theano_energy_function(H, q, **theano_kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymc3/step_methods/hmc/trajectory.py", line 54, in _theano_energy_function
energy_function = theano.function(inputs=[q, p], outputs=total_energy, **theano_kwargs)
TypeError: function() got an unexpected keyword argument 'state'

@emilleishida
Copy link
Collaborator

Thanks for pointing out the typo!
it has being corrected.

After correcting the typo you mentioned I ran the script here and got the expected result.
pymc3.version = 3.0

what version of pymc3 are you using?

@MooersLab
Copy link
Author

MooersLab commented Nov 14, 2017 via email

@emilleishida
Copy link
Collaborator

Oh sure! just now I realized that you had written this information in your initial post.
The issue comes because from version 3.1 on there was a change on the accepted NUTS options.

https://discourse.pymc.io/t/differenc-between-pymc-3-1-and-pymc-3-0-on-nuts/293/2

so, if we substitute line 54 with

step = pm.NUTS(scaling=start)

it should run without problems.
let me know if this works for you!

@MooersLab
Copy link
Author

MooersLab commented Nov 15, 2017 via email

@emilleishida
Copy link
Collaborator

good! my pleasure to help.

I am happy to know that the fix worked.
the fix in line 54 will work with version 3.0 as well, so it is probably a safer option.
I will change the other examples accordingly.

thanks again for pointing this out.

@MooersLab
Copy link
Author

MooersLab commented Nov 15, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants