This page details the methods and classes provided by the emcee module. The main entry point is through the EnsembleSampler object.
Standard usage of emcee involves instantiating an EnsembleSampler.
A generalized Ensemble sampler that uses 2 ensembles for parallelization. The __init__ function will raise an AssertionError if k < 2 * dim (and you haven’t set the live_dangerously parameter) or if k is odd.
Warning: The chain member of this object has the shape: (nwalkers, nlinks, dim) where nlinks is the number of steps taken by the chain and k is the number of walkers. Use the flatchain property to get the chain flattened to (nlinks, dim). For users of pre-1.0 versions, this shape is different so be careful!
| Parameters: |
|
|---|
An array (length: k) of the fraction of steps accepted for each walker.
The autocorrelation time of each parameter in the chain (length: dim) as estimated by the acor module.
Get the list of “blobs” produced by sampling. The result is a list (of length iterations) of list s (of length nwalkers) of arbitrary objects. Note: this will actually be an empty list if your lnpostfn doesn’t return any metadata.
A pointer to the Markov chain itself. The shape of this array is (k, iterations, dim).
A shortcut for accessing chain flattened along the zeroth (walker) axis.
A shortcut to return the equivalent of lnprobability but aligned to flatchain rather than chain.
Return the log-probability at the given position.
A pointer to the matrix of the value of lnprobfn produced at each step for each walker. The shape is (k, iterations).
The state of the internal random number generator. In practice, it’s the result of calling get_state() on a numpy.random.mtrand.RandomState object. You can try to set this property but be warned that if you do this and it fails, it will do so silently.
Clear the chain and lnprobability array. Also reset the bookkeeping parameters.
Iterate sample() for N iterations and return the result.
| Parameters: |
|
|---|
Advance the chain iterations steps as a generator.
| Parameters: |
|
|---|
At each iteration, this generator yields:
The PTSampler class performs a parallel-tempered ensemble sampling using EnsembleSampler to sample within each temperature. This sort of sampling is useful if you expect your distribution to be multi-modal. Take a look at the documentation to see how you might use this class.
A parallel-tempered ensemble sampler, using EnsembleSampler for sampling within each parallel chain.
| Parameters: |
|
|---|
Matrix of shape (Ntemps, Nwalkers) detailing the acceptance fraction for each walker.
Returns a matrix of autocorrelation lengths for each parameter in each temperature of shape (Ntemps, Ndim).
Returns the sequence of inverse temperatures in the ladder.
Returns the stored chain of samples; shape (Ntemps, Nwalkers, Nsteps, Ndim).
Exponential ladder in \(1/T\), with \(T\) increasing by \(\sqrt{2}\) each step, with ntemps in total.
Alias of chain provided for compatibility.
Return the log-probability at the given position.
Matrix of ln-likelihood values; shape (Ntemps, Nwalkers, Nsteps).
Matrix of lnprobability values; shape (Ntemps, Nwalkers, Nsteps).
The state of the internal random number generator. In practice, it’s the result of calling get_state() on a numpy.random.mtrand.RandomState object. You can try to set this property but be warned that if you do this and it fails, it will do so silently.
Clear the chain, lnprobability, lnlikelihood, acceptance_fraction, tswap_acceptance_fraction stored properties.
Iterate sample() for N iterations and return the result.
| Parameters: |
|
|---|
Advance the chains iterations steps as a generator.
| Parameters: |
|
|---|
At each iteration, this generator yields
Thermodynamic integration estimate of the evidence.
| Parameters: |
|
|---|---|
| Return (lnZ, dlnZ)(lnZ, dlnZ): | |
Returns an estimate of the log-evidence and the error associated with the finite number of temperatures at which the posterior has been sampled. |
|
The evidence is the integral of the un-normalized posterior over all of parameter space:
Thermodymanic integration is a technique for estimating the evidence integral using information from the chains at various temperatures. Let
Then
so
By computing the average of the log-likelihood at the difference temperatures, the sampler can approximate the above integral.
Returns an array of accepted temperature swap fractions for each temperature; shape (ntemps, ).
The Metropolis-Hastings sampler included in this module is far from fine-tuned and optimized. It is, however, stable and it has a consistent API so it can be useful for testing and comparison.
The most basic possible Metropolis-Hastings style MCMC sampler
| Parameters: |
|
|---|
The fraction of proposed steps that were accepted.
The autocorrelation time of each parameter in the chain (length: dim) as estimated by the acor module.
A pointer to the Markov chain.
An alias for reset() kept for backwards compatibility.
Alias of chain provided for compatibility.
Return the log-probability at the given position.
A list of the log-probability values associated with each step in the chain.
The state of the internal random number generator. In practice, it’s the result of calling get_state() on a numpy.random.mtrand.RandomState object. You can try to set this property but be warned that if you do this and it fails, it will do so silently.
Iterate sample() for N iterations and return the result.
| Parameters: |
|
|---|
Advances the chain iterations steps as an iterator
| Parameters: |
|
|---|
At each iteration, this generator yields:
This section is mostly for developers who would be interested in implementing a new sampler for inclusion in emcee. A good starting point would be to subclass the sampler object and override the Sampler.sample() method.
An abstract sampler object that implements various helper functions
| Parameters: |
|
|---|
The fraction of proposed steps that were accepted.
The autocorrelation time of each parameter in the chain (length: dim) as estimated by the acor module.
A pointer to the Markov chain.
Alias of chain provided for compatibility.
Return the log-probability at the given position.
A list of the log-probability values associated with each step in the chain.
The state of the internal random number generator. In practice, it’s the result of calling get_state() on a numpy.random.mtrand.RandomState object. You can try to set this property but be warned that if you do this and it fails, it will do so silently.
Clear chain, lnprobability and the bookkeeping parameters.
Iterate sample() for N iterations and return the result.
| Parameters: |
|
|---|
Produce a ball of walkers around an initial parameter value.
| Parameters: |
|
|---|
A Metropolis-Hastings proposal, with axis-aligned Gaussian steps, for convenient use as the mh_proposal option to EnsembleSampler.sample() .
A pool that distributes tasks over a set of MPI processes. MPI is an API for distributed memory parallelism. This pool will let you run emcee without shared memory, letting you use much larger machines with emcee.
The pool only support the map() method at the moment because this is the only functionality that emcee needs. That being said, this pool is fairly general and it could be used for other purposes.
Contributed by Joe Zuntz.
| Parameters: |
|
|---|
Just send a message off to all the pool members which contains the special _close_pool_message sentinel.