The No-U-Turn Sampler (NUTS) is an adaptive variant of Hamiltonian Monte Carlo that chooses the length of each simulated trajectory automatically, stopping when the path starts to double back on itself. It is the default inference engine for continuous parameters in modern probabilistic models and probabilistic programming systems such as Stan, PyMC and NumPyro.
Introduced by Matthew Hoffman and Andrew Gelman in 2011, NUTS removed the most difficult manual setting of Hamiltonian Monte Carlo, the number of leapfrog steps. Combined with automatic step size adaptation, it lets practitioners in statistics and artificial intelligence draw high-quality posterior samples for models with hundreds or thousands of parameters without hand-tuning the sampler.
How NUTS builds a trajectory
NUTS simulates the motion of a particle on the negative log posterior surface, treating parameters as position and an auxiliary Gaussian variable as momentum. The leapfrog integrator advances the particle in small steps, and gradients of the log density, usually obtained by automatic differentiation, steer it toward regions of high probability.
Instead of running a fixed number of steps, NUTS grows the trajectory by repeated doubling. At each iteration it picks a random direction, forward or backward in time, and adds as many new leapfrog steps as the trajectory already contains: 1, 2, 4, 8 and so on. This produces a balanced binary tree of states.
Doubling stops when the U-turn criterion fires: the momentum at either end of the trajectory points back toward the other end, so further simulation would only retrace ground already covered. Doubling also stops on a divergence, when the simulated energy error grows beyond a large threshold. The next state is then sampled from the tree in a way that preserves detailed balance, so the chain still targets the exact posterior.
Key parameters and diagnostics
Although NUTS is called tuning-free, it still exposes a handful of settings, and reading its diagnostics is essential for trustworthy inference. The table lists the settings practitioners most often encounter.
| Setting | Typical default | Effect |
|---|---|---|
| Target acceptance rate | 0.8 (0.65 in the original paper) | Higher values force smaller steps and fewer divergences |
| Maximum tree depth | 10, about 1,023 leapfrog steps | Caps computation per iteration |
| Warm-up iterations | 500 to 1,000 | Adapt step size and mass matrix |
| Mass matrix | Diagonal, estimated in warm-up | Rescales parameters with different scales |
| Number of chains | 4 | Enables convergence checks across chains |
Step size is tuned during warm-up with dual averaging, which drives the average acceptance statistic toward the target. After warm-up the step size and mass matrix are frozen, because continuing to adapt would break the Markov property of the chain.
The following diagnostics indicate whether a run can be trusted.
| Diagnostic | Warning sign | Usual cause |
|---|---|---|
| Divergent transitions | Any after warm-up | Regions of high curvature, such as funnels |
| Tree depth saturation | Many iterations hit the maximum | Poorly scaled or strongly correlated posterior |
| R-hat | Above about 1.01 | Chains have not mixed |
| Effective sample size | Low relative to draws | High autocorrelation |
| E-BFMI | Below about 0.3 | Momentum resampling explores energy poorly |
NUTS compared with other MCMC methods
NUTS belongs to the family of Markov chain Monte Carlo methods and trades a higher cost per iteration for far less correlated samples. In high-dimensional continuous models, that trade usually wins decisively over random-walk samplers.
| Method | Proposal mechanism | Main limitation |
|---|---|---|
| Metropolis-Hastings algorithm | Random-walk proposals | Mixes very slowly in high dimensions |
| Gibbs sampling | Draws from full conditional distributions | Struggles with strongly correlated parameters |
| Static Hamiltonian Monte Carlo | Fixed number of leapfrog steps | Requires manual path-length tuning |
| No-U-Turn Sampler | Adaptive trajectory length | Needs gradients and continuous parameters |
| Variational inference | Optimizes an approximate distribution | Biased; often underestimates uncertainty |
The cost of a NUTS iteration scales with the number of gradient evaluations, typically between a few and about a thousand. Theory and practice indicate that well-tuned Hamiltonian methods scale roughly as dimension to the power of one quarter per effective sample, compared with linear scaling for random-walk Metropolis.
When to use NUTS and how to help it
NUTS is the first choice for differentiable posteriors with continuous parameters, such as hierarchical regression, time-series and pharmacokinetic models. It cannot sample discrete parameters directly; these are usually marginalized out analytically or handled by a separate Gibbs step.
| Situation | Recommended action | Reason |
|---|---|---|
| Divergences in a hierarchical model | Use a non-centered parameterization | Removes the funnel geometry |
| Parameters on very different scales | Standardize data or use a dense mass matrix | Improves step-size efficiency |
| Constrained parameters | Rely on built-in transforms | Sampler works on an unconstrained space |
| Multimodal posterior | Run several chains and compare | NUTS rarely jumps between distant modes |
| Very large datasets | Consider variational or subsampling methods | Full gradients become expensive |
A frequent mistake is to raise the target acceptance rate to silence divergences without investigating their cause. Smaller steps can hide a problematic geometry rather than fix it, so reparameterization is generally preferred.
Variants and modern implementations
Current software no longer uses the exact 2011 algorithm. Stan and most libraries implement multinomial NUTS, which samples the next state from the whole trajectory with weights proportional to probability density, and use a generalized U-turn criterion that is more robust under a non-identity mass matrix. These refinements improve efficiency while keeping the same core idea of adaptive path length.
Related research continues to extend the approach. Riemannian NUTS adapts the metric to local curvature at a higher computational cost, while GPU-oriented samplers such as ChEES-HMC run many short chains in parallel and adapt a shared trajectory length instead of building a tree per chain. For most applied work on a single machine, however, standard multinomial NUTS remains the reference method against which new samplers are benchmarked.
The simple explanation
Imagine rolling a marble around a bowl-shaped landscape to learn its shape. The marble spends more time in the deep parts. Those deep parts are the most likely parameter values.
The hard question is how long to let each roll last. Too short, and the marble barely moves. Too long, and it wastes time coming back. NUTS solves this simply. It stops the roll when the marble starts turning back. That makes the method fast and almost automatic.
How it is used in practice
An epidemiology team builds a hierarchical model of infection rates across 120 districts, with about 400 parameters including district effects and a shared variance. They fit it in a probabilistic programming language that uses NUTS with four chains of 1,000 warm-up and 1,000 sampling iterations.
The first run reports dozens of divergent transitions caused by a funnel between district effects and their variance. After switching to a non-centered parameterization, the divergences disappear, R-hat values fall below 1.01 and effective sample sizes exceed 1,000 for every key parameter. The team then reports credible intervals for each district with confidence that the sampler explored the posterior properly.