ULA#
- class cuqi.sampler.ULA(target, scale, x0=None, dim=None, rng=None, **kwargs)#
Unadjusted Langevin algorithm (ULA) (Roberts and Tweedie, 1996)
Samples a distribution given its logpdf 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.
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 logd 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 (In practice, a scale of 1/dim**2 is recommended but not guaranteed to be the optimal choice).
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 and gradient as UserDefinedDistribution target = cuqi.distribution.UserDefinedDistribution(dim=dim, logpdf_func=logpdf_func, gradient_func=gradient_func) # Set up sampler sampler = cuqi.sampler.ULA(target, scale=1/dim**2) # Sample samples = sampler.sample(2000)
A Deblur example can be found in demos/demo27_ULA.py
- __init__(target, scale, x0=None, dim=None, rng=None, **kwargs)#
Methods
__init__
(target, scale[, x0, dim, rng])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