TL;DR
Neal's review shows how to borrow Hamiltonian dynamics from physics to propose distant new states for a Metropolis sampler. The proposal follows a simulated trajectory through an artificial landscape, so it can move far while still being accepted most of the time. The result is that a Markov chain explores a high-dimensional distribution with far fewer wasted steps than a random walk, which made it a standard tool for Bayesian sampling.
Builds on: Markov Chain Monte Carlo, Hamiltonian Mechanics, Metropolis Algorithm, Verlet Integration · Leads to: Hamiltonian Monte Carlo as a practical sampler
Why it mattered
Bayesian statistics needs samples from posterior distributions over many parameters, and a random-walk sampler becomes very slow once there are more than a few dimensions. Neal's review showed that a sampler which moves along a physical-looking trajectory can keep acceptance high while making large moves, and it gave the theory and the practical rules for doing so. The method is now the default inside widely used probabilistic programming systems. Stan, for example, uses a variant of Hamiltonian Monte Carlo as its default sampler.
The paper also changed how people think about the proposal step. A proposal does not have to be a random guess; it can be the result of a deterministic, reversible, volume-preserving map, and the acceptance rule then needs no Jacobian correction. That idea is useful well beyond this sampler.
The problem
A Metropolis sampler proposes a small random change to the current state and accepts or rejects it. In one dimension this works well. In many dimensions the proposal must be small, or most proposals are rejected, and so the chain takes a random walk through the distribution. Neal's analysis gives the cost: for a target made of independent replicas, the potential energy takes of order random-walk updates to explore, and the computation grows roughly as .
The fix is to propose a state that is far away but still has a similar probability. A physical system does this naturally, since a particle moving under a force follows a trajectory that keeps its total energy nearly constant. The question is how to turn that physics into a valid sampler.
How it works
Each iteration takes the current state of the variables of interest and adds a momentum that the sampler invents. Then it runs five steps.
- Resample the momentum. Draw a new from a Gaussian, independently of . Check: is unchanged, so this step only refreshes the momentum.
- Simulate a trajectory. Run Hamiltonian dynamics for small steps of size using the leapfrog scheme. Check: the total energy changes only slightly along the way.
- Negate the momentum. Flip the sign of at the end. Check: this makes the proposal symmetric, which the acceptance rule needs.
- Accept or reject. Accept the new state with probability . If it is rejected, keep the old state.
- Repeat. Each iteration gives one state of the Markov chain, and the chain's samples approximate the target distribution.
A tiny one-dimensional case shows the mechanics. The target is a Gaussian with variance 1, so , and the momentum has kinetic energy . Start at with . Each leapfrog step first moves the momentum a half step, then the position a full step, then the momentum another half step, using the gradient . This example is traced in detail in the worked examples below.
flowchart LR
A["State q, resample p"] --> B["Leapfrog trajectory, L steps"]
B --> C["Negate p"]
C --> D{"Accept with min(1, exp of minus change in H)?"}
D -->|yes| E["Move to new q"]
D -->|no| F["Keep old q"]
E --> A
F --> A
The math
Hamiltonian dynamics operates on positions and momenta . The Hamiltonian is the total energy, and Hamilton's equations are
For sampling, the Hamiltonian is split as . The potential energy is defined as , minus the log of the target density up to a constant. The kinetic energy is , a Gaussian for the momentum with variances .
Step 1 in symbols: resampling
The joint distribution of is proportional to . This factorises, so can be drawn from its Gaussian on its own. Refreshing leaves the joint distribution invariant, and it is the step that lets the chain move to different energy levels.
Step 2 in symbols: the leapfrog scheme
Hamilton's equations are discretised with steps of size :
The scheme preserves volume exactly, and it is reversible, which is what the acceptance rule needs. The paper notes that its local error is of order , one order better than the Euler method.
Step 4 in symbols: the acceptance rule
Because the dynamics conserves exactly in theory, the acceptance probability is one in theory. Discretisation changes slightly, so the rule is
where is the proposed state. The energy error from discretisation is small when is small enough, and it does not grow much with , which the paper notes.
Step 5 in symbols: the one-dimensional example
For and , Hamilton's equations give and . The trajectory is a rotation in the plane, and stays fixed along it.
Worked examples
Start at , , so . Run the exact dynamics for time .
- .
- .
- New energy: .
- Check: the energy is unchanged, so the exact proposal is accepted with probability 1.
Interpretation: the exact trajectory moves the sampler from the centre of the Gaussian to in one proposal, and the acceptance rule never rejects it. A random-walk proposal of similar size would often be rejected.
Use the same start, and , with and . The gradient is .
- Half-step momentum: .
- Full-step position: .
- Half-step momentum: . Energy now .
- Half-step momentum: .
- Full-step position: .
- Half-step momentum: .
- Energy: .
- Energy change: . Acceptance: .
Interpretation: the sampler moves to , a large move, and it is accepted with probability about 0.98. Check the step where the energy rose: it went from 0.5 to 0.508 after one step, so the error stays small as long as is small.
The paper's test distribution is a 100-dimensional Gaussian with independent variables and standard deviations . The leapfrog stepsize has to be small for the narrowest direction, so the paper uses near and .
- Trajectory length: , which is long enough to cross the widest direction, whose standard deviation is 1.
- Rejection rate for HMC: 0.13, so acceptance is .
- Rejection rate for random-walk Metropolis, with its best proposal size: 0.75, so acceptance is 0.25.
- Check: both rates are reported for near-optimal tuning, so the comparison is fair.
Interpretation: HMC accepts most of its long proposals, while the random walk rejects three quarters of its short ones. Per unit of computation the difference is large in 100 dimensions.
Try it. How many times higher is the HMC acceptance rate than the random-walk acceptance rate in this example? Answer: , about 3.5 times higher.
Results
The review reports three kinds of result, each with its numbers from the paper.
| Result | What the paper reports |
|---|---|
| Optimal acceptance, random-walk Metropolis | About 23 percent, at the optimal mean energy change |
| Optimal acceptance, HMC | About 65 percent, at |
| 100-dimensional Gaussian | HMC rejection 0.13, random-walk rejection 0.75, with |
| Exploring the potential energy | Random walk needs of order updates; the paper argues HMC may need only a few iterations to reach a nearly independent point |
The 23 percent figure for random walks matches a more formal analysis by Roberts and colleagues, and the 65 percent figure for HMC is consistent with earlier empirical results on high-dimensional problems. The paper's arguments about exploration rest on the fact that the momentum resampling changes the kinetic energy by an amount that grows with , which lets a single proposal move the potential energy a comparable amount.
The paper also states its limits. The stepsize must be small compared with the narrowest scale in the target, otherwise the energy error grows and acceptance falls. Trajectories can be periodic, which stops the chain from exploring, so the paper suggests choosing or at random within a small range. Distributions with isolated modes need extra methods, such as tempering during a trajectory, which the review describes. HMC also needs the gradient of the log density, which is not always available.
Reading guide
- Introduction (Section 1). Read for the motivation: random-walk proposals diffuse, and Hamiltonian dynamics can make distant proposals. Needs Markov Chain Monte Carlo and Metropolis Algorithm.
- Hamiltonian dynamics (Section 2). Read Hamilton's equations, the properties of volume preservation and reversibility, and the leapfrog scheme. Needs Hamiltonian Mechanics and Verlet Integration. The one-dimensional rotation example is a good place to check the reasoning.
- MCMC from Hamiltonian dynamics (Section 3). Read the canonical distribution and the HMC algorithm. Needs Probability Density Function for the target and Detailed Balance for the proof of invariance. The 2D and 100-dimensional illustrations follow.
- HMC in practice and theory (Section 4). Read the tuning rules, the effect of the mass matrix, and the scaling with dimension. Needs Kinetic Energy, Potential Energy and the Gaussian (Normal) Distribution that the momentum follows.
- Variations (Section 5). Skim unless you need them; these cover windows of states, tempering and short-cut methods.
Check yourself
QuestionRecall: why must the momentum be resampled at the start of each iteration, rather than kept from the previous trajectory?Show answer
Without resampling, a trajectory keeps the total energy almost fixed, so the chain would stay on one energy level and could not move to states of different probability. Resampling the momentum changes , and therefore , letting the chain move between energy levels. It also keeps the joint distribution invariant.
QuestionComputation: with and , what is the trajectory length ?Show answer
The trajectory length is .
QuestionWhy: why does the negation of the momentum at the end of the trajectory matter, if the momentum is resampled anyway in the next iteration?Show answer
The acceptance rule assumes the proposal is symmetric: the probability of moving from one state to another must equal the probability of the reverse move. Negating the momentum makes the reverse of the trajectory land back on the start, so the proposal is symmetric. In practice the negation can be skipped, because and the momentum is resampled before it is used again, but it is part of the algorithm's correctness argument.
QuestionApplied: a model has 10,000 parameters and the gradient is cheap to compute. A colleague proposes random-walk Metropolis with a tuned step size. Should you use HMC instead?Show answer
Probably yes. The paper's analysis shows that random-walk Metropolis needs work that grows with the dimension, while HMC's proposals move far with high acceptance. Before committing, check that the target is smooth enough for the leapfrog scheme, tune and to get an acceptance rate near the 65 percent the paper reports, and compare effective samples per second with the random walk on a short run.