# TransportMaps.Samplers¶

Classes

Class Description
Sampler Generic sampler of distribution d
ImportanceSampler Importance sampler of distribution d, with biasing distribution d_bias
RejectionSampler Rejection sampler of distribution d, with biasing distribution d_bias
MetropolisHastingsIndependentProposalsSampler Metropolis-Hastings with independent proposal sampler of distribution d, with proposal distribution d_prop
MetropolisHastingsSampler Metropolis-Hastings sampler of distribution d, with proposal d_prop
MetropolisHastingsWithinGibbsSampler Metropolis-Hastings within Gibbs sampler of distribution d, with proposal d_prop and Gibbs block sampling blocks
HamiltonianMonteCarloSampler Hamiltonian Monte Carlo sampler of distribution d, with proposal distribution d_prop

Functions

Function Description
ess Compute the Effective Sample Size (ESS) of a sample

Documentation

class TransportMaps.Samplers.Sampler(d)[source]

Generic sampler of distribution d

This main class just mirrors all the sampling methods provided by the distribution d.

Parameters: d (Distributions.Distribution) – distribution to sample from.
rvs(m, *args, **kwargs)[source]

Generate $$m$$ samples and weights from the distribution

Parameters: m (int) – number of samples to generate (tuple (ndarray [$$m,d$$], ndarray [$$m$$])) – list of points and weights
class TransportMaps.Samplers.ImportanceSampler(d, d_bias)[source]

Importance sampler of distribution d, with biasing distribution d_bias

Parameters: d (Distributions.Distribution) – distribution to sample from d_bias (Distributions.Distribution) – biasing distribution
rvs(m, mpi_pool_tuple=(None, None))[source]

Generate $$m$$ samples and importance weights from the distribution

Parameters: m (int) – number of samples to generate (tuple (ndarray [$$m,d$$], ndarray [$$m$$])) – list of points and weights
class TransportMaps.Samplers.RejectionSampler(d, d_bias)[source]

Rejection sampler of distribution d, with biasing distribution d_bias

Parameters: d (Distributions.Distribution) – distribution to sample from d_bias (Distributions.Distribution) – biasing distribution
rvs(m, *args, **kwargs)[source]

Generate $$m$$ samples and importance weights from the distribution

Parameters: m (int) – number of samples to generate (tuple (ndarray [$$m,d$$], ndarray [$$m$$])) – list of points and weights
class TransportMaps.Samplers.MetropolisHastingsIndependentProposalsSampler(d, d_prop)[source]

Metropolis-Hastings with independent proposal sampler of distribution d, with proposal distribution d_prop

Parameters: d (Distributions.Distribution) – distribution to sample from d_prop (Distributions.Distribution) – proposal distribution
rvs(m, x0=None, mpi_pool_tuple=(None, None))[source]

Generate a Markov Chain of $$m$$ equally weighted samples from the distribution d

Parameters: m (int) – number of samples to generate x0 (ndarray [$$1,d$$]) – initial chain value mpi_pool_tuple (tuple [2] of mpi_map.MPI_Pool) – pool of processes to be used for the evaluation of d and prop_d (tuple (ndarray [$$m,d$$], ndarray [$$m$$])) – list of points and weights
class TransportMaps.Samplers.MetropolisHastingsSampler(d, d_prop)[source]

Metropolis-Hastings sampler of distribution d, with proposal d_prop

Parameters: d (Distributions.Distribution) – distribution $$\pi({\bf x})$$ to sample from d_prop (Distributions.ConditionalDistribution) – conditional distribution $$\pi({\bf y}\vert{\bf x})$$ to use as a proposal
rvs(m, x0=None, mpi_pool_tuple=(None, None))[source]

Generate a Markov Chain of $$m$$ equally weighted samples from the distribution d

Parameters: m (int) – number of samples to generate x0 (ndarray [$$1,d$$]) – initial chain value mpi_pool_tuple (tuple [2] of mpi_map.MPI_Pool) – pool of processes to be used for the evaluation of d and prop_d (tuple (ndarray [$$m,d$$], ndarray [$$m$$])) – list of points and weights
class TransportMaps.Samplers.MetropolisHastingsWithinGibbsSampler(d, d_prop_list, block_list=None)[source]

Metropolis-Hastings within Gibbs sampler of distribution d, with proposal d_prop and Gibbs block sampling blocks

Parameters: d (Distributions.Distribution) – distribution $$\pi({\bf x})$$ to sample from d_prop (list of Distributions.ConditionalDistribution) – conditional distribution $$\pi({\bf y}\vert{\bf x})$$ to use as a proposal block_list (list of list) – list of blocks of variables
rvs(m, x0=None, mpi_pool_tuple=(None, None))[source]

Generate a Markov Chain of $$m$$ equally weighted samples from the distribution d

Parameters: m (int) – number of samples to generate x0 (ndarray [$$1,d$$]) – initial chain value mpi_pool_tuple (tuple [2] of mpi_map.MPI_Pool) – pool of processes to be used for the evaluation of d and prop_d (tuple (ndarray [$$m,d$$], ndarray [$$m$$])) – list of points and weights
class TransportMaps.Samplers.HamiltonianMonteCarloSampler(d)[source]

Hamiltonian Monte Carlo sampler of distribution d, with proposal distribution d_prop

This sampler requires the package pyhmc.

Parameters: d (Distributions.Distribution) – distribution to sample from
rvs(m, x0=None, display=False, n_steps=1, persistence=False, decay=0.9, epsilon=0.2, window=1, return_logp=False, return_diagnostics=False, random_state=None)[source]

Generate a Markov Chain of $$m$$ equally weighted samples from the distribution d

pyhmc for arguments

TransportMaps.Samplers.ess(samps, quantile=0.99, do_xcorr=False, plotting=False, plot_lag=50, fig=None)[source]

Compute the Effective Sample Size (ESS) of a sample

The minimum ESS over all the dimension is returned. Cross-correlation can be optionally used as well in the determination of the ESS. Plotting of the correlation decay can be shown.

The ESS is computed as $$\lfloor m/\kappa \rfloor$$, where

$\kappa = 1 + \sum_{c_i>b_i} c_i \;,$

$$c_i$$ is the auto-correlation at lag $$i$$ and $$b_i$$ is the quantile-confidence interval for the $$i$$-th value of auto-correlation (i.e. only significant auto-correlation values are summed up).

Parameters: samps (ndarray [$$m,d$$]) – $$d$$-dimensional sample on which to compute the ESS quantile (float) – condifence interval quantile do_xcorr (bool) – whether to compute and use the auto-correlation function plotting (bool) – whether to plot auto/cross-correlation decays plot_lag (int) – how many lags to plot fig (figure) – handle to a figure (int) – minimum ESS across the $$d$$ dimensions