Mathematics for AI and Machine Learning

Foundations for modern AI and machine learning

Metropolis-Adjusted Langevin Algorithm

Chapter 18 Dynamics & diffusion

Chapter 18: Langevin Dynamics and Sampling — Metropolis-Adjusted Langevin Algorithm (MALA)

Animated preview (GIF)
Metropolis-Adjusted Langevin Algorithm — animated GIF preview
High-resolution PNG
Metropolis-Adjusted Langevin Algorithm — high-resolution mind-map icon

From the book

Chapter 18: Langevin Dynamics and Sampling. In the chapter mind map this icon labels Metropolis-Adjusted Langevin Algo (MALA). The discussion below is excerpted and lightly edited from § Metropolis-Adjusted Langevin Algorithm (MALA) in Mathematics for AI and Machine Learning.

To illustrate how MCMC works, consider using the Metropolis-Hastings algorithm to sample from a 1D bimodal distribution.

Use a Gaussian proposal distribution centered at the current sample:

$q(x' \mid x) = \mathcal{N}(x'; x, \sigma^2)$$ with $\sigma = 0.5$.

1. Initialize: Start with an initial sample $x_0 = 0$ 2. Iterate: For each step $t$: a. Generate proposal: Sample $x' \sim q(x' \mid x_t)$ b. Compute acceptance ratio: c. Accept or reject: Sample $u \sim \text{Uniform}(0, 1)$ - If $u \leq r$, accept the proposal: $x_{t+1} = x'$ - Otherwise, reject the proposal: $x_{t+1} = x_t$

  • Burn-in period: Discard the first 1,000 samples to allow the chain to reach stationarity
  • Sample distribution: The remaining 9,000 samples form a distribution that closely matches the target bimodal distribution
  • Exploration: The chain successfully explores both modes of the distribution

While Metropolis-Hastings works well for this example, Langevin dynamics would typically converge faster by using gradient information to move toward high-probability regions more efficiently.

What this drawing shows

What you see. Langevin proposal ellipse fixed; chain proposes green accept then red reject, illustrating Metropolis–Hastings correction.

In the mind map. Chapter 18 — Metropolis-Adjusted Langevin Algo (MALA). See From the book above for definitions, figures, and worked examples.

Where to read next

Open Chapter 18 companion →

Read the full definitions, figures, and worked examples in Chapter 18: Langevin Dynamics and Sampling — see the mind-map node Metropolis-Adjusted Langevin Algo (MALA).