Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Exploring a dark landscape
Imagine exploring hilly countryside at night with only a torch. You want to spend time in places in proportion to how high they are. Rule: take a random step. If it’s uphill, go. If it’s downhill, go only sometimes, more rarely the steeper the drop. After a long walk, a record of where you’ve been is a map of the hills.
That’s Markov chain Monte Carlo (MCMC). The landscape is the posterior. You never need its full shape, only “how high is it here compared with there?”. The list of visited places is a set of samples you can average.
MCMC is how Bayesian models with many parameters are fitted in practice: calibration of physics models, hierarchical reliability models, Bayesian logistic regression, and uncertainty in SLAM back-ends. Knowing how to tune it and when to distrust it is essential.
- 1. MCMC produces…
- 2. A downhill step in Metropolis is…
- 3. To run Metropolis you need the posterior…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Metropolis–Hastings
From the current , propose , and accept with probability
Otherwise stay at . Repeat the current state when you reject: that matters for correctness. With a symmetric random-walk proposal , the terms cancel. Only ratios of appear, so the normalizing constant (the evidence) is never needed. Work with log-densities to avoid underflow.
Gibbs sampling
Update one block of variables at a time from its full conditional . Every move is accepted. It’s natural when conditionals are conjugate: for normal data, is normal and is inverse-gamma. Gibbs is a special case of MH with acceptance probability 1.
Using the output
Discard a burn-in period, then average: . Quantiles of the draws give credible intervals, and pushing draws through a model gives predictive samples.
- 1. p(new)/p(old) = 0.3 with a symmetric proposal: acceptance probability?
- 2. When an MH proposal is rejected, the chain…
- 3. Gibbs sampling updates variables from their…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.Tuning and the step-size trade-off
- Too small a step: nearly every proposal is accepted, but the chain crawls, so autocorrelation is huge and the ESS tiny.
- Too large: nearly every proposal is rejected, and the chain sits still.
For Gaussian-like targets in high dimensions, the optimal random-walk acceptance rate is about 0.234 (Roberts, Gelman and Gilks, 1997). Scale the proposal like the posterior covariance, which adaptive MH learns during warm-up (Haario et al., 2001).
Diagnostics
- Trace plots: several chains from dispersed starts should overlap.
- R̂ (Gelman–Rubin): compares between-chain and within-chain variance. Values near 1 indicate convergence, and the modern rule is with rank normalization (Vehtari et al., 2021).
- Effective sample size: . Report it, and the Monte Carlo SE .
Diagnostics can only detect failure. A chain stuck in one mode of a multimodal posterior can look perfectly converged.
When MCMC struggles
- Strong correlations: Gibbs takes tiny axis-aligned steps, with lag-1 autocorrelation about . Reparameterize or update blocks jointly.
- Curved ridges (bananas) and funnels (hierarchical models): a fixed-size random walk is either too big in the narrow parts or too small in the wide ones. Hamiltonian Monte Carlo uses gradients to follow the geometry (A5.2-8).
- Multimodality: use tempering, multiple dispersed chains, or reparameterize.
- 1. The asymptotically optimal acceptance rate for random-walk MH is about…
- 2. R̂ well above 1 means…
- 3. Gibbs on two variables with correlation 0.99 mixes…
Level 3: Advanced
★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.Why Metropolis–Hastings is correct
The MH transition kernel is for . Then
which is symmetric in . That’s detailed balance, so is stationary (A4.4-1). With irreducibility and aperiodicity (true for a random walk with positive density everywhere), the chain converges to from any start, and averages obey the ergodic theorem: almost surely. ∎
Why Gibbs is correct
One Gibbs update of is an MH step with proposal . The acceptance ratio . Each update preserves , so their composition does too.
The Monte Carlo CLT for Markov chains
For geometrically ergodic chains, . That’s why the ESS and batch-means SEs (A5.1-2) are the right uncertainty for MCMC estimates.
Exercise 3.1: Show that the MH acceptance with a symmetric proposal is min(1, p(x’)/p(x))
With the proposal terms cancel in the Hastings ratio, leaving . That’s the original Metropolis rule (Metropolis et al., 1953).
- 1. MH's correctness rests on…
- 2. Gibbs updates are MH steps with acceptance…
- 3. The MCMC standard error uses…
Level 4: Expert
★★★★★ Expert⏱ 45 minResearchers: original papers and open problems.Grasp success as Bayesian logistic regression
Model the probability that a grasp succeeds as , with 60 trials. The posterior over has no closed form, so random-walk MH with 4 chains gives . For a new situation (22 N on a 7.5 cm object) it reports a 90% band for the success probability, not a single number. A planner can use the band: it can require the lower bound to exceed a threshold before attempting a risky grasp, or choose informative trials where the band is widest (active learning). Probabilistic programming systems (Stan, PyMC, NumPyro) automate this with HMC.
MCMC in AI, robotics and aerospace
- Probabilistic programming. Stan, PyMC and NumPyro make MCMC (mostly NUTS) a routine tool for calibration and hierarchical models (Carpenter et al., 2017).
- Bayesian calibration of simulators. Kennedy–O’Hagan calibration of physics models (thermal, aerodynamic, battery) with discrepancy terms (Kennedy and O’Hagan, 2001).
- SLAM uncertainty and multi-hypothesis data association have used MCMC over associations (Ranganathan, Menegatti and Dellaert, 2006).
- Inverse problems in planetary science. Recovering interior structure or atmospheric profiles from remote measurements with MCMC over physical parameters.
- Bayesian neural networks via stochastic-gradient MCMC (SGLD, SGHMC) for uncertainty in perception and control (Welling and Teh, 2011; Chen, Fox and Guestrin, 2014).
References
- N. Metropolis, A. Rosenbluth, M. Rosenbluth, A. Teller, E. Teller (1953). “Equation of state calculations by fast computing machines.” Journal of Chemical Physics, 21(6).
- W. K. Hastings (1970). “Monte Carlo sampling methods using Markov chains and their applications.” Biometrika, 57(1).
- S. Geman, D. Geman (1984). “Stochastic relaxation, Gibbs distributions, and the Bayesian restoration of images.” IEEE TPAMI, 6(6).
- A. Gelfand, A. Smith (1990). “Sampling-based approaches to calculating marginal densities.” JASA, 85(410).
- G. Roberts, A. Gelman, W. Gilks (1997). “Weak convergence and optimal scaling of random walk Metropolis algorithms.” Annals of Applied Probability, 7(1).
- H. Haario, E. Saksman, J. Tamminen (2001). “An adaptive Metropolis algorithm.” Bernoulli, 7(2).
- A. Gelman, D. Rubin (1992). “Inference from iterative simulation using multiple sequences.” Statistical Science, 7(4).
- A. Vehtari, A. Gelman, D. Simpson, B. Carpenter, P.-C. Bürkner (2021). “Rank-normalization, folding, and localization: an improved R-hat.” Bayesian Analysis, 16(2).
- B. Carpenter et al. (2017). “Stan: a probabilistic programming language.” Journal of Statistical Software, 76(1).
- M. Kennedy, A. O’Hagan (2001). “Bayesian calibration of computer models.” JRSS B, 63(3).