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 :attr:`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
:attr:`flatchain` property to get the chain flattened to
``(nlinks, dim)``. For users of pre-1.0 versions, this shape is
different so be careful!
:param nwalkers:
The number of Goodman & Weare "walkers".
:param dim:
Number of dimensions in the parameter space.
:param 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.
:param a: (optional)
The proposal scale parameter. (default: ``2.0``)
:param args: (optional)
A list of extra arguments for ``lnpostfn``. ``lnpostfn`` will be
called with the sequence ``lnpostfn(p, *args)``.
:param postargs: (optional)
Alias of ``args`` for backwards compatibility.
:param threads: (optional)
The number of threads to use for parallelization. If ``threads == 1``,
then the ``multiprocessing`` module is not used but if
``threads > 1``, then a ``Pool`` object is created and calls to
``lnpostfn`` are run in parallel.
:param pool: (optional)
An alternative method of using the parallelized algorithm. If
provided, the value of ``threads`` is ignored and the
object provided by ``pool`` is used for all parallelization. It
can be any object with a ``map`` method that follows the same
calling sequence as the built-in ``map`` function.
Definition at line 28 of file ensemble.py.
def emcee.ensemble.EnsembleSampler.sample |
( |
|
self, |
|
|
|
p0, |
|
|
|
lnprob0 = None , |
|
|
|
rstate0 = None , |
|
|
|
blobs0 = None , |
|
|
|
iterations = 1 , |
|
|
|
thin = 1 , |
|
|
|
storechain = True , |
|
|
|
mh_proposal = None |
|
) |
| |
Advance the chain ``iterations`` steps as a generator.
:param p0:
A list of the initial positions of the walkers in the
parameter space. It should have the shape ``(nwalkers, dim)``.
:param lnprob0: (optional)
The list of log posterior probabilities for the walkers at
positions given by ``p0``. If ``lnprob is None``, the initial
values are calculated. It should have the shape ``(k, dim)``.
:param rstate0: (optional)
The state of the random number generator.
See the :attr:`Sampler.random_state` property for details.
:param iterations: (optional)
The number of steps to run.
:param thin: (optional)
If you only want to store and yield every ``thin`` samples in the
chain, set thin to an integer greater than 1.
:param storechain: (optional)
By default, the sampler stores (in memory) the positions and
log-probabilities of the samples in the chain. If you are
using another method to store the samples to a file or if you
don't need to analyse the samples after the fact (for burn-in
for example) set ``storechain`` to ``False``.
:param mh_proposal: (optional)
A function that returns a list of positions for ``nwalkers``
walkers given a current list of positions of the same size. See
:class:`utils.MH_proposal_axisaligned` for an example.
At each iteration, this generator yields:
* ``pos`` — A list of the current positions of the walkers in the
parameter space. The shape of this object will be
``(nwalkers, dim)``.
* ``lnprob`` — The list of log posterior probabilities for the
walkers at positions given by ``pos`` . The shape of this object
is ``(nwalkers, dim)``.
* ``rstate`` — The current state of the random number generator.
* ``blobs`` — (optional) The metadata "blobs" associated with the
current position. The value is only returned if ``lnpostfn``
returns blobs too.
Definition at line 117 of file ensemble.py.