Dynamic Hamiltonian Monte Carlo
Dynamic Hamiltonian Monte Carlo (No-U-Turn Sampler) · Also known as: Dynamic HMC, NUTS, No-U-Turn Sampler, adaptive HMC
Dynamic Hamiltonian Monte Carlo — widely known as the No-U-Turn Sampler (NUTS) — is an adaptive extension of Hamiltonian Monte Carlo that automatically selects the number of leapfrog integration steps during each MCMC transition, removing the need to hand-tune the most sensitive tuning parameter of standard HMC. It is the default sampler in Stan and PyMC and is suitable for continuous, differentiable posterior distributions of moderate to high dimension.
Read the full method
Sign in with a free account to read this section.
Method map
The neighbourhood of related methods — select a node to explore.
When to use it
Use Dynamic HMC when the posterior is continuous and the log-posterior and its gradients are available (as in most Bayesian regression, hierarchical, and latent-variable models). It is especially powerful in moderate to high dimensions (tens to hundreds of parameters) where random-walk samplers like Metropolis-Hastings mix extremely slowly. Do not use it when parameters are discrete (use Gibbs sampling or marginalisation instead), when the log-posterior is not differentiable, or when gradient evaluation is prohibitively expensive — in those cases variational inference or SMC may be preferable.
Strengths & limitations
- Eliminates manual tuning of trajectory length, the most sensitive HMC parameter.
- Mixes rapidly in high-dimensional, correlated posteriors compared with random-walk methods.
- Provides strong theoretical guarantees: preserves detailed balance and targets the exact posterior.
- Produces high effective sample sizes per gradient evaluation in well-conditioned problems.
- Diagnostic failures (divergences, low E-BFMI, high R-hat) are informative and guide model improvement.
- Requires continuous, differentiable parameters — discrete parameters must be marginalised or handled separately.
- Gradient computation can be expensive for large datasets or highly complex models.
- Highly non-linear or funnel-shaped posteriors can cause divergent transitions even with optimal tuning.
- Warm-up phase requires many gradient evaluations; short chains may not adapt adequately.
Frequently asked
What is a divergent transition and why does it matter?
A divergent transition occurs when the leapfrog integrator becomes numerically unstable, usually because the posterior has a region of very high curvature (e.g., a funnel). Divergences indicate that samples from that region are unreliable. The correct response is to reparameterise the model (e.g., use a non-centred parameterisation for hierarchical models), not simply to increase the target acceptance rate.
How does NUTS differ from standard HMC?
Standard HMC requires the user to specify both a step size and a fixed number of leapfrog steps (trajectory length). NUTS retains the step size (adapted automatically) but replaces the fixed trajectory length with the U-turn criterion, which dynamically and automatically determines when to stop integrating. This makes NUTS dramatically easier to use and often more efficient.
What is the mass matrix and why does it matter?
The mass matrix M in the Hamiltonian controls how the algorithm moves through parameter space. A diagonal mass matrix set to the inverse marginal variances of the posterior rescales each dimension so they are on a similar scale, improving mixing. A dense mass matrix can also capture correlations. Poor mass-matrix estimation leads to slow mixing or step-size collapse.
Can I use Dynamic HMC with discrete parameters?
Not directly. Leapfrog integration requires continuous, differentiable parameters. Discrete parameters must be marginalised analytically, assigned to a Gibbs step, or handled with methods such as embedding discrete variables in a continuous relaxation. Stan requires all parameters to be continuous for this reason.
How many warm-up and sampling iterations do I need?
A common starting point is 1000 warm-up and 1000 sampling iterations per chain with 4 chains. For complex posteriors, 2000 warm-up iterations improve mass-matrix estimation. Adequacy is judged by R-hat (below 1.01) and bulk/tail effective sample sizes (above 100 per chain as a minimum), not by iteration count alone.
Sources
- Hoffman, M. D. & Gelman, A. (2014). The No-U-Turn Sampler: Adaptively setting path lengths in Hamiltonian Monte Carlo. Journal of Machine Learning Research, 15(1), 1593–1623. link ↗
- Neal, R. M. (2011). MCMC using Hamiltonian dynamics. In S. Brooks, A. Gelman, G. Jones & X.-L. Meng (Eds.), Handbook of Markov Chain Monte Carlo (pp. 113–162). CRC Press. ISBN: 978-1420079418
How to cite this page
ScholarGate. (2026, June 3). Dynamic Hamiltonian Monte Carlo (No-U-Turn Sampler). ScholarGate. https://scholargate.app/en/bayesian/dynamic-hamiltonian-monte-carlo
Which method?
Set this method beside its closest kin and read them side by side — the library lays the books on the table; the choice is yours.
- Bayesian RegressionBayesian↔ compare
- Gibbs SamplingBayesian↔ compare
- Hamiltonian Monte CarloBayesian↔ compare
- Sequential Monte CarloBayesian↔ compare
- Variational InferenceBayesian↔ compare