0

I don't know if anyone is familiar with Dan Foreman-Mackley's "emcee" Python module, but I am using it to sample a distribution. I am using the Parallel Tempering sampler because my distribution is funky looking. Here is the relevant code:

from emcee import PTSampler

rendim = 6
renwalkers = 100
ntemps = 20


gauss2 = PTSampler(ntemps, renwalkers, rendim, lnlike, lnprior)

p0 = [[[np.random.rand()*0.24,np.random.rand()*3,np.random.rand()*1,np.random.rand()*1,np.random.rand()*3,np.random.rand()*1] for i in range(renwalkers)] for i in range(ntemps)]

for q, lnprob, lnlike in gauss2.sample(p0,iterations=1000):
    pass
gauss2.reset()

for q, lnprob, lnlike in gauss2.sample(p, lnprob0=lnprob,
                                       lnlike0=lnlike,
                                       iterations=10000, thin=10):
    pass

I keep getting the error that 'numpy.ndarray' object is not callable. Here is the full error:

TypeError                                 Traceback (most recent call last)
<ipython-input-25-d5f2a1f4b7b0> in <module>()
     11 p0 = [[[np.random.rand()*0.24,np.random.rand()*3,np.random.rand()*1,np.random.rand()*1,np.random.rand()*3,np.random.rand()*1] for i in range(renwalkers)] for i in range(ntemps)]
     12 
---> 13 for q, lnprob, lnlike in gauss2.sample(p0,iterations=1000):
     14     pass
     15 gauss2.reset()

/Library/Python/2.7/site-packages/emcee-2.1.0-py2.7.egg/emcee/ptsampler.py in sample(self, p0, lnprob0, lnlike0, iterations, thin, storechain)
    255                              self.logpargs, self.loglkwargs, self.logpkwargs)
    256             if self.pool is None:
--> 257                 results = list(map(fn, p.reshape((-1, self.dim))))
    258             else:
    259                 results = list(self.pool.map(fn, p.reshape((-1, self.dim))))

/Library/Python/2.7/site-packages/emcee-2.1.0-py2.7.egg/emcee/ptsampler.py in __call__(self, x)
     94             return lp, lp
     95 
---> 96         return self.logl(x, *self.loglargs, **self.loglkwargs), lp
     97 
     98 

TypeError: 'numpy.ndarray' object is not callable

Update: here are the lnlike and lnprior functions:

def lnprior(theta):
    eta, mu1, sig1, h, mu2, sig2 = theta
    if 0 < eta < 0.24 and 0 < mu1 < 1.5 and 0 < sig1 < 1 and 0 < h < 1 and 0 < mu2 < 1.5 and 0 < sig2 < 1:
        return 0
    return -np.inf

def lnlike(theta):
    eta, mu1, sig1, h, mu2, sig2 = theta
    return -k*np.log(Nsamp)+np.sum(np.log(np.sum(MCetadist(eta,events,mu1,sig1,h,mu2,sig2),axis=1)))
8
  • what is lnlike and lnprior? Commented Jul 23, 2014 at 20:55
  • @PadraicCunningham I updated the post with their definitions Commented Jul 23, 2014 at 21:00
  • lnlike returns an array yes? Commented Jul 23, 2014 at 21:18
  • @PadraicCunningham yep! I believe so. Commented Jul 23, 2014 at 21:28
  • 1
    @PadraicCunningham I'm not sure what I did but it is working now.......... hmmm.. Commented Jul 24, 2014 at 0:00

1 Answer 1

-2

The message "TypeError: 'numpy.ndarray' object is not callable" means that the "numpy.ndarray" that you are trying to call as a function is a module or variable and is thus not callable. When you call a non-function with '()', you will has this type error. You can just drop the '()' after that reference and everything will be ok.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.