pythonemcee

emcee EnsembleSampler object has no attribute get_chain


I am having trouble accessing the values generated from emcee using the get_chain() method. My code is provided below:

import numpy as np
import emcee
def log_prob(x): return -np.sum(x**2)
p0 = np.array(np.random.randn(12, 1))
sampler = emcee.EnsembleSampler(12, 1, log_prob)
sampler.run_mcmc(p0, 1000)
samples = sampler.get_chain()

When I run this, I get the message AttributeError: 'EnsembleSampler' object has no attribute 'get_chain', and I am not sure why. I read somewhere online that the get_chain() method was only added in a newer release of emcee, and that it needed to be downloaded from GitHub. If this is the issue, how would I download it from GitHub and ensure it still works with Anaconda (I'm new to Python/GitHub, and I'm not too familiar with how this would be done)?

Any help would be greatly appreciated! Thanks!


Solution

  • As you suspect, this is probably due to having installed an old version of emcee. You can check the version installed with

    emcee.__version__
    

    emcee 3 was only a release candidate (instead of an official release) for quite a long time, hence the advise from the blog post you read. It has already been released however, the post is probably nearly a year old at least. You should be able to update to latest emcee and fix your issue with pip

    pip install -U emcee
    

    or with conda (which looks like what you are using).

    conda install -c conda-forge emcee
    

    see more details on emcee installation with conda on its conda forge page