pymc-devs / pymc2

THIS IS THE **OLD** PYMC PROJECT (VERSION 2). PLEASE USE PYMC INSTEAD:
http://pymc-devs.github.com/pymc/
Other
879 stars 229 forks source link

TypeError raised by Scipy when called stochastic_from_data in distributions.py #108

Closed raino01r closed 8 years ago

raino01r commented 8 years ago

Hello all, I'm using pymc since a bit of time now and recently I was working on a problem that required the creation of a custom stochastic variable from data. I'm not sure whether this problem is already known.

Problem: When calling stochastic_from_data, there is a TypeError thrown, the problem is that in the distributiuon.py the following two lines are given

# distributions.py
import scipy.stats as stats
gaussian_kde = stats.kde

Example:

>>> import pymc
>>> prior = pymc.rnormal(0, 1, 10000)
>>> prior_stoch = pymc = pymc.stochastic_from_data('prior', prior)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../python2.7/site-packages/pymc/distributions.py", line 427, in stochastic_from_data
    pdf = gaussian_kde(data)  # automatic bandwidth selection
TypeError: 'module' object is not callable

Solution

# distributions.py
import scipy.stats as stats
gaussian_kde = stats.gaussian_kde

because:

import pymc as pm
prior = pm.rnormal(0,1,10000)
import scipy.stats as stats
pdf = stats.gaussian_kde(prior)

does not raise anything.

My setup:

$ python --version
Python 2.7.10
$ python
>>> import scipy
>>> import pymc
>>> scipy.__version__
'0.17.0'
>>> pymc.__version__
'2.3.6'

Comments: the proposed solution should not affect anything rather than stochastic_from_dist in distributions.py.

pedrohasselmann commented 4 years ago

Hello,

I'm facing similar error. I have pymc 2.3.6 install through pip.

Traceback (most recent call last): y = pymc.stochastic_from_data('y', data=np.asarray(VG.radf), value=Lr, observed=True) File "/usr/local/lib/python2.7/dist-packages/pymc/distributions.py", line 427, in stochastic_from_data pdf = gaussian_kde(data) # automatic bandwidth selection TypeError: 'module' object is not callable

kde has been updated do gaussian_kde, but I can't understand why it rises "'module' object is not callable".

I truly appreciated any help here.

fonnesbeck commented 4 years ago

I would strongly recommend using PyMC3 instead of 2.3.6. The samplers are much, much better.

If you really have to stick with PyMC2, I would at least upgrade to the latest release (2.3.7).