MALA#

class cuqi.sampler.MALA(target, scale, x0=None, dim=None, rng=None, **kwargs)#

Metropolis-adjusted Langevin algorithm (MALA) (Roberts and Tweedie, 1996)

Samples a distribution given its logd and gradient (up to a constant) based on Langevin diffusion dL_t = dW_t + 1/2*Nabla target.logd(L_t)dt, where L_t is the Langevin diffusion and W_t is the dim-dimensional standard Brownian motion. The sample is then accepted or rejected according to Metropolis–Hastings algorithm.

For more details see: Roberts, G. O., & Tweedie, R. L. (1996). Exponential convergence of Langevin distributions and their discrete approximations. Bernoulli, 341-363.

Parameters:
  • target (cuqi.distribution.Distribution) – The target distribution to sample. Must have logpdf and gradient method. Custom logpdfs and gradients are supported by using a cuqi.distribution.UserDefinedDistribution.

  • x0 (ndarray) – Initial parameters. Optional

  • scale (int) – The Langevin diffusion discretization time step.

  • dim (int) – Dimension of parameter space. Required if target logpdf and gradient are callable functions. Optional.

  • callback (callable, Optional) – If set this function will be called after every sample. The signature of the callback function is callback(sample, sample_index), where sample is the current sample and sample_index is the index of the sample. An example is shown in demos/demo31_callback.py.

Example

# Parameters
dim = 5 # Dimension of distribution
mu = np.arange(dim) # Mean of Gaussian
std = 1 # standard deviation of Gaussian

# Logpdf function
logpdf_func = lambda x: -1/(std**2)*np.sum((x-mu)**2)
gradient_func = lambda x: -2/(std**2)*(x-mu)

# Define distribution from logpdf as UserDefinedDistribution (sample and gradients also supported)
target = cuqi.distribution.UserDefinedDistribution(dim=dim, logpdf_func=logpdf_func,
    gradient_func=gradient_func)

# Set up sampler
sampler = cuqi.sampler.MALA(target, scale=1/5**2)

# Sample
samples = sampler.sample(2000)

A Deblur example can be found in demos/demo28_MALA.py

__init__(target, scale, x0=None, dim=None, rng=None, **kwargs)#

Methods

__init__(target, scale[, x0, dim, rng])

log_proposal(theta_star, theta_k, g_logpi_k)

sample(N[, Nb])

sample_adapt(N[, Nb])

single_update(x_t, target_eval_t, ...)

step(x)

Perform a single MCMC step

step_tune(x, *args, **kwargs)

Perform a single MCMC step and tune the sampler.

tune()

Tune the sampler parameters.

Attributes