Paper commentary
The No-U-Turn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo
NUTS removes the need to hand-tune path length in Hamiltonian Monte Carlo
- Problem HMC works well, but its step count L must be set by hand. A poor choice either wastes computation or lets the chain random-walk.
- Method NUTS doubles a trajectory in a random direction and stops at a U-turn.
- Results On two of four targets, NUTS with δ = 0.6 reached about three times HMC's best ESS, with no tuning runs.
Why HMC needs hand-tuning
HMC scales better than random-walk Metropolis, at roughly O(D5/4) cost per independent sample against O(D2) for random walks. That advantage comes with a price, because two user-set parameters, the step size ϵ and the number of steps L, control its performance. If L is too small, successive samples sit close together and the chain random-walks, while if L is too large, trajectories loop back and waste work.
Choosing L is the harder of the two, because there is no simple measure of when a trajectory is too short or too long.
Practitioners usually fix L after one or more preliminary runs, which is costly and needs expertise. That hurdle keeps HMC out of general-purpose engines such as BUGS, which is the gap the authors target.
The key idea: stop when the path turns back
NUTS replaces the fixed L with a stopping rule: it keeps extending the trajectory until one end starts to fold back toward the other. The test is the dot product between the current momentum and the displacement from the starting point, which tracks whether the path is still moving away. Stopping at the first sign of a turn would not guarantee time reversibility, so the authors adopt a recursive scheme instead.
The scheme grows the trajectory by 2^j leapfrog steps at height j, in a direction chosen at random. Doubling halts when the end states of a balanced subtree point back against each other, which is the U-turn test.
How one NUTS iteration runs
Each iteration resamples the momentum from a standard normal and draws a slice variable below the current joint density. The slice variable confines the candidate states to those at least as probable as the slice height, and it simplifies the derivation.
Each leapfrog step updates the momentum by a half step, moves the position by a full step, and then applies another half step to the momentum. The update is volume-preserving, which keeps the Metropolis acceptance step valid.
States enter the candidate set C only when they lie inside the slice, and the tree-building keeps the candidates consistent with detailed balance. A separate rule halts doubling when the energy error becomes very large, with Δmax recommended at 1000.
The next state is drawn uniformly from C, the union of the valid candidate sets. The efficient variant drops the stored tree and breaks out of the recursion as soon as the stop indicator is zero, which saves memory and computation.
Adapting the step size
During burn-in the step size is adjusted by dual averaging, so no separate tuning run is needed. The method averages a statistic H_t and shrinks the iterates toward a target μ, so early extreme values of ϵ are damped. The defaults are γ = 0.05, t0 = 10 and κ = 0.75 in every experiment.
For HMC the statistic is the Metropolis acceptance probability, which is driven toward a target δ. The starting ϵ comes from a heuristic that doubles or halves the value until the acceptance probability crosses 0.5.
Does NUTS match a tuned HMC?
The authors ran HMC at ten logarithmically spaced simulation lengths and NUTS on four targets for 2000 iterations. The first 1000 iterations were used to adapt ϵ, and efficiency is measured as ESS divided by gradient evaluations.
On the two logistic regression targets NUTS produces effectively independent samples about as efficiently as HMC. On the multivariate normal and stochastic volatility targets NUTS with δ = 0.6 reached about three times HMC's best ESS. That gap matters because HMC's best simulation length varied by about a factor of 100 across the targets, with 17.62 the longest and 0.17 the shortest.
So a well-tuned HMC needs a length chosen separately for each target, which NUTS does not. NUTS performed similarly for δ between 0.45 and 0.65, so the authors treat 0.6 as a default. The authors add that NUTS matches HMC even when the cost of tuning HMC is not counted.
Comparison with random-walk Metropolis and Gibbs
NUTS ran with δ = 0.5 for 2,000 iterations, with the first 1,000 used as burn-in and adaptation, costing about 1,000,000 gradient and likelihood evaluations. Random-walk Metropolis ran for 1,000,000 iterations with its proposal tuned to an acceptance rate of 0.234.
Random-walk Metropolis barely explored the space, and Gibbs sampling covered more of it but left parts unexplored. NUTS produced many effectively independent samples from the same target. The authors note that rotating the space would help the other two, but finding a rotation gets expensive as the dimension grows.
Trajectory lengths and adaptation behaviour
Most NUTS trajectory lengths are integer powers of two, so the U-turn test is usually met after a full doubling. This means the sampler seldom has to discard half a trajectory to keep the chain balanced.
The averaged step size converged within a few hundred iterations, except for the stochastic volatility model. The authors attribute its weaker adaptation to its longer burn-in period.
Limitations
The authors compared NUTS only with basic HMC, not with its extensions. NUTS works only on unconstrained continuous variables, so discrete variables must be summed out or handled by Gibbs sampling.
The default settings were chosen by hand on the stochastic volatility model, and the authors say they may not transfer to other sampling algorithms. The mass-matrix extension is discussed as a possible improvement but was not tested here.
Paper info
- Authors
- Matthew D. Hoffman, Andrew Gelman
- Venue
- arXiv · Preprint
- First published
- 2011-11-18
- Added
- 2026-11-12
- Updated
- 2011-11-18
- Version
- v1
- arXiv
- 1111.4246
- Category
- stat.CO · cs.LG
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Matthew D. Hoffman, Andrew Gelman (2011). The No-U-Turn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo. arXiv:1111.4246v1. https://arxiv.org/abs/1111.4246v1
BibTeX
@misc{hoffman2011turn,
title = {{The No-U-Turn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo}},
author = {Matthew D. Hoffman and Andrew Gelman},
year = {2011},
eprint = {1111.4246},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1111.4246v1}
}