Hamiltonian Monte Carlo (HMC) is a Markov Chain Monte Carlo (MCMC) method that uses gradient information to make large, directed moves in the posterior, suppressing the random-walk behaviour that makes simple Metropolis-Hastings (MH) slow in high dimensions. It augments the target distribution over parameters with fictitious momentum variables , simulates Hamiltonian dynamics jointly over via the leapfrog integrator, then accepts or rejects the trajectory endpoint using the Metropolis criterion.
Augmented state: introduce independently of . Define the Hamiltonian where is the potential energy and is kinetic energy. The joint density , so the marginal over is the target.
One HMC step: (1) resample ; (2) simulate leapfrog steps from with stepsize to produce proposal ; (3) accept with probability . Negate before presenting the proposal to restore detailed balance.
Three key properties of Hamiltonian dynamics:
Hierarchical funnel & parameterization (Betancourt-Girolami 2015): hierarchical models induce a funnel-shaped posterior whose local curvature varies by orders of magnitude, so a fixed leapfrog step size produces divergences in the funnel neck. The remedy is a non-centered parameterization (when data are weak) and/or a Riemannian metric, with divergence monitoring as a bias diagnostic.
The Störmer-Verlet / leapfrog scheme interleaves half-steps for momentum with full steps for position, for i = 1, ..., L:
This is the unique first-order symplectic integrator for separable Hamiltonians; it exactly preserves a "shadow" Hamiltonian , ensuring acceptance rates remain high even with moderately large stepsizes.
Two hyperparameters: stepsize and number of leapfrog steps (trajectory length ). Optimal acceptance rate ≈ 65% (Roberts-Gelman-Gilks 1997, analogous to the 0.234 rule for random-walk Metropolis in dimensions). Trajectory length should be long enough for q* to be nearly independent of q, but not so long that the trajectory loops back. The No-U-Turn Sampler (NUTS, Hoffman-Gelman 2011) automates both: it grows the trajectory until the simulation turns around (U-turns), eliminating manual tuning. NUTS is the default in Stan.
acts as a preconditioning matrix. Setting (inverse posterior covariance) decorrelates parameters and equalises leapfrog stepsizes across dimensions. In practice is estimated from warmup iterations (diagonal approximation is standard).
Scaling: the total arithmetic cost per independent sample scales as for random-walk Metropolis versus for HMC — a improvement. (Equivalently: HMC needs gradient evaluations per sample and RWM needs density evaluations, each evaluation itself costing arithmetic.) In high-dimensional posteriors (modern hierarchical models, neural networks, latent Gaussian fields) this is a decisive advantage.
Probabilistic programming: HMC/NUTS is the sampler in Stan, PyMC, and Turing.jl. The ability to target arbitrary differentiable posteriors without hand-crafted proposal distributions enabled a generation of applied Bayesian models that would have been computationally infeasible with Gibbs or random-walk MH.
Limitations: