emcee.sampler module

The base sampler class implementing various helpful functions.

class emcee.sampler.Sampler(dim, lnprobfn, args=[])[source]

Bases: object

An abstract sampler object that implements various helper functions

Parameters:
  • dim – The number of dimensions in the parameter space.

  • lnpostfn – A function that takes a vector in the parameter space as input and returns the natural logarithm of the posterior probability for that position.

  • args – (optional) A list of extra arguments for lnpostfn. lnpostfn will be called with the sequence lnpostfn(p, *args).

property acceptance_fraction

The fraction of proposed steps that were accepted.

property acor

The autocorrelation time of each parameter in the chain (length: dim) as estimated by the acor module.

property chain

A pointer to the Markov chain.

clear_chain()[source]

An alias for reset() kept for backwards compatibility.

property flatchain

Alias of chain provided for compatibility.

get_lnprob(p)[source]

Return the log-probability at the given position.

property lnprobability

A list of the log-probability values associated with each step in the chain.

property random_state

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.

reset()[source]

Clear chain, lnprobability and the bookkeeping parameters.

run_mcmc(pos0, N, rstate0=None, lnprob0=None, **kwargs)[source]

Iterate sample() for N iterations and return the result.

Parameters:
  • p0 – The initial position vector.

  • N – The number of steps to run.

  • lnprob0 – (optional) The log posterior probability at position p0. If lnprob is not provided, the initial value is calculated.

  • rstate0 – (optional) The state of the random number generator. See the random_state() property for details.

  • kwargs – (optional) Other parameters that are directly passed to sample().

sample(*args, **kwargs)[source]