NUTS targets a posterior p(θ) by simulating a physical particle on the energy surface U(θ) = −log p(θ), with an auxiliary momentum r and total energy H(θ,r) = U(θ) + ½|r|². Each proposal resamples r ~ N(0,I), then integrates Hamilton's equations with the leapfrog scheme:
r(½) = r − (ε/2)∇U(θ)
θ' = θ + ε·r(½)
r' = r(½) − (ε/2)∇U(θ')
NUTS removes the fixed-trajectory-length tuning knob of plain HMC: it builds a balanced binary tree of leapfrog steps, doubling in a random direction (forward or backward) at each level, until the endpoints start turning back toward each other:
stop when (θ⁺ − θ⁻)·r⁻ < 0 or (θ⁺ − θ⁻)·r⁺ < 0
That is the "no U-turn" criterion. A sample is then drawn from the states visited along the tree, weighted so the draw is still a valid sample from p(θ) — no whole-trajectory Metropolis rejection needed.
- Main contour map — a top-down view of p(θ₁,θ₂) with the leapfrog tree path (cyan) and accumulated draws (violet). Thin strips along the bottom/right edges are live marginal histograms of θ₁ and θ₂ built from the accumulated samples.
- Phase-space panel — plots the auxiliary momentum (r₁,r₂) visited along the current tree; a well-behaved leapfrog trajectory traces a smooth, roughly closed loop.
- Energy panel — plots H(θ,r) at each leapfrog step of the current tree against the starting energy (dashed line); good step sizes keep the drift small, this is exactly the energy diagnostic used to detect divergences in Stan/PyMC.
- ε (step size) — smaller steps track curvature more faithfully but need more leapfrog evaluations; larger steps risk visible energy drift (numerical divergence).
- Max tree depth — a safety cap on doublings (2^depth leapfrog steps worst case) if no U-turn ever triggers.
This is the exact algorithm (Hoffman & Gelman, 2014) that powers Stan, PyMC and NumPyro. The bent "banana" ridge is a classic torture-test posterior whose curving valley defeats naive random-walk Metropolis but NUTS glides along with ease.