No-U-Turn Sampler

Also known as: NUTS

On this page 7

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.

SettingTypical defaultEffect
Target acceptance rate0.8 (0.65 in the original paper)Higher values force smaller steps and fewer divergences
Maximum tree depth10, about 1,023 leapfrog stepsCaps computation per iteration
Warm-up iterations500 to 1,000Adapt step size and mass matrix
Mass matrixDiagonal, estimated in warm-upRescales parameters with different scales
Number of chains4Enables convergence checks across chains
Main NUTS settings in common implementations

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.

DiagnosticWarning signUsual cause
Divergent transitionsAny after warm-upRegions of high curvature, such as funnels
Tree depth saturationMany iterations hit the maximumPoorly scaled or strongly correlated posterior
R-hatAbove about 1.01Chains have not mixed
Effective sample sizeLow relative to drawsHigh autocorrelation
E-BFMIBelow about 0.3Momentum resampling explores energy poorly
NUTS warning signs and their usual meaning

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.

MethodProposal mechanismMain limitation
Metropolis-Hastings algorithmRandom-walk proposalsMixes very slowly in high dimensions
Gibbs samplingDraws from full conditional distributionsStruggles with strongly correlated parameters
Static Hamiltonian Monte CarloFixed number of leapfrog stepsRequires manual path-length tuning
No-U-Turn SamplerAdaptive trajectory lengthNeeds gradients and continuous parameters
Variational inferenceOptimizes an approximate distributionBiased; often underestimates uncertainty
How NUTS relates to neighboring samplers

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.

SituationRecommended actionReason
Divergences in a hierarchical modelUse a non-centered parameterizationRemoves the funnel geometry
Parameters on very different scalesStandardize data or use a dense mass matrixImproves step-size efficiency
Constrained parametersRely on built-in transformsSampler works on an unconstrained space
Multimodal posteriorRun several chains and compareNUTS rarely jumps between distant modes
Very large datasetsConsider variational or subsampling methodsFull gradients become expensive
Practical decisions when applying NUTS

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.