Rigorous derivation of MCMC methods for Bayesian inference: the Metropolis-Hastings algorithm, detailed balance, ergodicity, Gibbs sampling as a special case, Hamiltonian Monte Carlo, diagnostics, and convergence theory.
π(θ) — target distribution (posterior), known up to normalizing constant
q(θ′∣θ) — proposal distribution
α(θ′∣θ) — acceptance probability
T(θ′∣θ) — transition kernel of the chain
θ(t) — state of chain at iteration t
Core Intuition
Bayesian inference requires computing expectations under the posterior p(θ∣D), which involves intractable integrals. MCMC constructs a Markov chain whose stationary distribution is the posterior. Running the chain generates correlated samples; the empirical average of these samples converges to the posterior expectation by the ergodic theorem.
MCMC Random Walk
Acceptance = 70.0%
Step size0.80
Samples60
AcceptedRejected
Explore: Small steps → high acceptance but slow mixing. Large steps → low acceptance, chain gets stuck. Aim for ~20–40% acceptance.
The Sampling Problem
We want to compute:
Eπ[h(θ)]=∫h(θ)π(θ)dθ,(1)
where π(θ)=p(θ∣D)=p(D)p(D∣θ)p(θ).
The normalizing constant p(D)=∫p(D∣θ)p(θ)dθ is typically intractable. We can evaluate π~(θ)=p(D∣θ)p(θ) pointwise, but cannot normalize it.
MCMC solves this: it only requires π~ up to a constant.
Markov Chains: Foundations
Definition. A sequence {θ(t)} is a Markov chain if p(θ(t+1)∣θ(t),…,θ(0))=T(θ(t+1)∣θ(t)).
Stationary distribution.π is stationary for T if:
π(θ′)=∫T(θ′∣θ)π(θ)dθ.(2)
Ergodic Theorem. If the chain is irreducible and aperiodic with stationary distribution π, then:
Proposition. Gibbs sampling is a special case of Metropolis-Hastings where the proposal q(θ′∣θ) proposes from the full conditional distribution, and the acceptance probability is always 1.
HMC augments the parameter space with "momentum" variables p and simulates Hamiltonian dynamics to propose distant states with high acceptance probability.
Joint distribution:p(θ,p)∝exp(−H(θ,p)) where:
H(θ,p)=U(θ)+K(p)=−logπ~(θ)+21pTM−1p.(7)
Leapfrog integrator (discrete approximation to Hamilton's equations):
After L leapfrog steps, accept/reject with MH correction (accounts for discretization error).
Advantage: HMC proposes states far from the current position while maintaining high acceptance rates, greatly reducing autocorrelation compared to random-walk MH.
Convergence Diagnostics
Trace plots: Visual inspection for stationarity (chain should look like white noise after burn-in).
Effective Sample Size (ESS): ESS=N/(1+2∑kρk) where ρk is autocorrelation at lag k. Low ESS means high autocorrelation.
Burn-in: Discard initial samples before the chain reaches stationarity.
Common Pitfalls
Pitfall 1. Using too narrow a proposal in MH: high acceptance rate but slow exploration (random walk behavior). Optimal acceptance rate ≈ 23% for high-dimensional targets.
Pitfall 2. Not accounting for multimodality. Standard MCMC can get trapped in a single mode. Use tempering or multiple initialization strategies.
Pitfall 3. Declaring convergence too early. Short chains may appear stationary but haven't explored the full posterior. Always run multiple chains with dispersed initializations.
Research Perspective
MCMC was introduced by Metropolis et al. (1953) and generalized by Hastings (1970). Modern advances include the No-U-Turn Sampler (NUTS, Hoffman & Gelman, 2014) which automatically tunes HMC trajectory length, stochastic gradient MCMC for large datasets, and transport-based methods that combine variational inference with MCMC.
Summary
MCMC generates samples from distributions known only up to a constant.
Metropolis-Hastings uses propose-accept/reject; correctness follows from detailed balance.
Gibbs sampling cycles through full conditionals; always accepts.
HMC uses gradient information for efficient exploration of high-dimensional posteriors.
Convergence is assessed via R^, ESS, and trace plots.
Exercises
Exercise 1. Prove that detailed balance implies stationarity: if πT=π follows from equation (5).
Exercise 2. For a 1D Gaussian target π(θ)=N(0,1) with Gaussian proposal q(θ′∣θ)=N(θ,σ2), compute the acceptance probability and discuss the effect of σ.
Exercise 3. Show that the leapfrog integrator is time-reversible and volume-preserving (symplectic).
Exercise 4. Derive the Gibbs sampler for the bivariate Gaussian (θ1,θ2) with correlation ρ, and compute the autocorrelation of the chain.
Exercise 5. Show that ideal HMC (exact Hamiltonian dynamics, no discretization error) has acceptance probability 1.