Search code examples
pythonpymc

Designing a simple Binomial distribution throws core dump in pymc


I am trying to design a simple binomial distribution in pymc. However it fails with the below error, the same code works fine if I use Poisson distribution instead of binomial

import pymc as pm
from pymc import Beta,Binomial,Exponential
import numpy as np
from pymc.Matplot import plot as mcplot

data = pm.rbinomial(5,0.01,size=100)
p = Beta("p",1,1)
observations = Binomial("obs",5,p,value=data,observed=True)
model = pm.Model([p,observations])
mcmc = pm.MCMC(model)
mcmc.sample(400,100,2)
mcplot(mcmc)

Error

venki@venki-HP-248-G1-Notebook-PC:~/Desktop$ python perf_testing.py 
*** glibc detected *** python: free(): corrupted unsorted chunks: 0x0000000003cb0d40 ***
*** glibc detected *** python: malloc(): memory corruption: 0x00000000038bf2e0 ***

I have also created a issue in github pymc. I am though not sure, If i am wrong or is it a bug ?

OS

Python 2.7.3
pymc 2.3.4
Ubuntu 12.04.5 LTS

Solution

  • I think that this is a bug (here is a link to the issue you opened, thanks!).

    Here is a work around you can use for now: instead of the creating observations as you have done above, use n and p arguments which have dimension matching data:

    observations = Binomial("obs", 5*np.ones_like(data),
                            p*np.ones_like(data), value=data,observed=True)