MALA

class telescopic.kernels.MALA(step_size=None, *, cov=None)

The Metropolis-adjusted Langevin algorithm.

The proposal is \(x' = x + \tfrac{\epsilon^2}{2}\Sigma\nabla\log\pi(x) + \epsilon Cz\), with \(CC^\top = \Sigma\) (cov) and \(z \sim \mathcal N(0, I)\), a draw from \(q(\cdot \mid x)\). It is accepted when \(\log u < \log\pi(x') - \log\pi(x) + \log q(x \mid x') - \log q(x' \mid x)\); a proposal with a log-density of -inf or a non-finite position is rejected. Coupled chains draw their proposals from the reflection-maximal coupling of their proposal distributions, which share the covariance \(\epsilon^2\Sigma\), and share the uniform (Jacob, O’Leary & Atchadé 2020, section 4.4): a MetropolisHastings with a LangevinProposal and Reflection.

Parameters:
step_sizefloat, optional

\(\epsilon\). None leaves it to tune(): dual averaging toward an acceptance rate of 0.574 from \(\epsilon_0 = 1.65\,d^{-1/6}\) (Roberts & Rosenthal 1998).

covarray_like, shape (d, d), optional

\(\Sigma\), usually an estimate of the target covariance. None leaves it to tune(), which takes the covariance of adaptive Metropolis pilot chains.

Notes

A step uses d normals and 1 uniform, and a coupled step d normals and 2 uniforms. Each evaluates the log-density once per chain, once per pair when the proposals coincide, and the gradient where the log-density is finite.

Both compute in whitened coordinates. With \(B = \epsilon C\) and the whitened drift \(h = B^\top\nabla\log\pi(x)\), the proposal is \(x' = x + B(h/2 + z)\) and the log ratio of the proposal densities is \((\lVert z\rVert^2 - \lVert z + (h + h')/2\rVert^2)/2\), so a step costs 3 products of a row with a \(d \times d\) factor and a coupled step 7.

Examples

MALA needs the gradient, as grad or log_prob_and_grad, which it evaluates with every finite log-density, so on a Gaussian the two counts agree:

>>> from telescopic import examples, kernels, sample
>>> example = examples.gaussian(2)
>>> result = sample(
...     example.log_prob, example.initial, grad=example.grad,
...     kernel=kernels.MALA(), n_replicates=50, vectorize=True, rng=0,
... )
>>> result.n_grad == result.n_log_prob
True
with_step_size(step_size)

A copy with another step size, without validating the covariance again.

Parameters:
step_sizefloat

Positive and finite.

Returns:
GradientKernel