gstlal-inspiral  0.4.2
 All Classes Namespaces Files Functions Variables Pages
List of all members | Public Member Functions | Public Attributes
emcee.ptsampler.PTSampler Class Reference
Inheritance diagram for emcee.ptsampler.PTSampler:
[legend]
Collaboration diagram for emcee.ptsampler.PTSampler:
[legend]

Public Member Functions

def __init__
def exponential_beta_ladder
def reset
def sample
def thermodynamic_integration_log_evidence
def betas
def chain
def lnprobability
def lnlikelihood
def tswap_acceptance_fraction
def acceptance_fraction
def acor

Public Attributes

 logl
 logp
 ntemps
 nwalkers
 dim
 nswap
 nswap_accepted
 pool
 samplers

Detailed Description

A parallel-tempered ensemble sampler, using :class:`EnsembleSampler`
for sampling within each parallel chain.

:param ntemps:
    The number of temperatures.

:param nwalkers:
    The number of ensemble walkers at each temperature.

:param dim:
    The dimension of parameter space.

:param logl:
    The log-likelihood function.

:param logp:
    The log-prior function.

:param threads: (optional)
    The number of parallel threads to use in sampling.

:param pool: (optional)
    Alternative to ``threads``.  Any object that implements a
    ``map`` method compatible with the built-in ``map`` will do
    here.  For example, :class:`multi.Pool` will do.

:param betas: (optional)
    Array giving the inverse temperatures, :math:`\\beta=1/T`, used in the
    ladder.  The default is for an exponential ladder, with beta
    decreasing by a factor of :math:`1/\\sqrt{2}` each rung.

Definition at line 69 of file ptsampler.py.

Member Function Documentation

def emcee.ptsampler.PTSampler.acceptance_fraction (   self)
Matrix of shape ``(Ntemps, Nwalkers)`` detailing the
acceptance fraction for each walker.

Definition at line 421 of file ptsampler.py.

def emcee.ptsampler.PTSampler.acor (   self)
Returns a matrix of autocorrelation lengths for each
parameter in each temperature of shape ``(Ntemps, Ndim)``.

Definition at line 430 of file ptsampler.py.

def emcee.ptsampler.PTSampler.betas (   self)
Returns the sequence of inverse temperatures in the ladder.

Definition at line 379 of file ptsampler.py.

def emcee.ptsampler.PTSampler.chain (   self)
Returns the stored chain of samples; shape ``(Ntemps,
Nwalkers, Nsteps, Ndim)``.

Definition at line 387 of file ptsampler.py.

def emcee.ptsampler.PTSampler.exponential_beta_ladder (   self,
  ntemps 
)
Exponential ladder in :math:`1/T`, with :math:`T` increasing by
:math:`\\sqrt{2}` each step, with ``ntemps`` in total.

Definition at line 133 of file ptsampler.py.

def emcee.ptsampler.PTSampler.lnlikelihood (   self)
Matrix of ln-likelihood values; shape ``(Ntemps, Nwalkers, Nsteps)``.

Definition at line 404 of file ptsampler.py.

def emcee.ptsampler.PTSampler.lnprobability (   self)
Matrix of lnprobability values; shape ``(Ntemps, Nwalkers, Nsteps)``.

Definition at line 396 of file ptsampler.py.

def emcee.ptsampler.PTSampler.reset (   self)
Clear the ``chain``, ``lnprobability``, ``lnlikelihood``,
``acceptance_fraction``, ``tswap_acceptance_fraction`` stored
properties.

Definition at line 141 of file ptsampler.py.

def emcee.ptsampler.PTSampler.sample (   self,
  p0,
  lnprob0 = None,
  lnlike0 = None,
  iterations = 1,
  thin = 1,
  storechain = True 
)
Advance the chains ``iterations`` steps as a generator.

:param p0:
    The initial positions of the walkers.  Shape should be
    ``(ntemps, nwalkers, dim)``.

:param lnprob0: (optional)
    The initial posterior values for the ensembles.  Shape
    ``(ntemps, nwalkers)``.

:param lnlike0: (optional)
    The initial likelihood values for the ensembles.  Shape
    ``(ntemps, nwalkers)``.

:param iterations: (optional)
    The number of iterations to preform.

:param thin: (optional)
    The number of iterations to perform between saving the
    state to the internal chain.

:param storechain: (optional)
    If ``True`` store the iterations in the ``chain``
    property.

At each iteration, this generator yields

* ``p``, the current position of the walkers.

* ``lnprob`` the current posterior values for the walkers.

* ``lnlike`` the current likelihood values for the walkers.

Definition at line 159 of file ptsampler.py.

def emcee.ptsampler.PTSampler.thermodynamic_integration_log_evidence (   self,
  logls = None,
  fburnin = 0.1 
)
Thermodynamic integration estimate of the evidence.

:param logls: (optional) The log-likelihoods to use for
    computing the thermodynamic evidence.  If ``None`` (the
    default), use the stored log-likelihoods in the sampler.
    Should be of shape ``(Ntemps, Nwalkers, Nsamples)``.

:param fburnin: (optional)
    The fraction of the chain to discard as burnin samples; only the
    final ``1-fburnin`` fraction of the samples will be used to
    compute the evidence; the default is ``fburnin = 0.1``.

:return ``(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:

.. math::

    Z \\equiv \\int d\\theta \\, l(\\theta) p(\\theta)

Thermodymanic integration is a technique for estimating the
evidence integral using information from the chains at various
temperatures.  Let

.. math::

    Z(\\beta) = \\int d\\theta \\, l^\\beta(\\theta) p(\\theta)

Then

.. math::

    \\frac{d \\ln Z}{d \\beta}
    = \\frac{1}{Z(\\beta)} \\int d\\theta l^\\beta p \\ln l
    = \\left \\langle \\ln l \\right \\rangle_\\beta

so

.. math::

    \\ln Z(\\beta = 1)
    = \\int_0^1 d\\beta \\left \\langle \\ln l \\right\\rangle_\\beta

By computing the average of the log-likelihood at the
difference temperatures, the sampler can approximate the above
integral.

Definition at line 307 of file ptsampler.py.

def emcee.ptsampler.PTSampler.tswap_acceptance_fraction (   self)
Returns an array of accepted temperature swap fractions for
each temperature; shape ``(ntemps, )``.

Definition at line 412 of file ptsampler.py.


The documentation for this class was generated from the following file: