The target is q ~ N(μ, σ²). Adding Gaussian momentum turns Hamiltonian
dynamics into a harmonic oscillator, so the trajectory has a closed form — a pure rotation
in phase space that conserves energy exactly. Leapfrog approximates that same orbit but rides a
nearby shadow energy level, and the resulting wobble in H is exactly what the
Metropolis step corrects. Trace a single proposal, then let the chain run.
integrator
stable · εω = 0.30
Phase space (q, p)1.0×
exact orbitleapfrog stepsstartproposalchain step · p resampled
exact orbit — harmonic oscillatorx = q − μ, ω = 1/(σ√m)
x(t) = x₀cos ωt + (p₀/mω) sin ωt
p(t) = −mω x₀ sin ωt + p₀ cos ωt
leapfrog step (size ε)
p ← p − (ε/2)·U′(q)
q ← q + ε·p/m
p ← p − (ε/2)·U′(q)
one HMC iteration
Draw p₀ ~ N(0, m), simulate to a proposal (q*, p*), then accept with
probability min(1, e^(H₀ − H*)). Under exact dynamics H* = H₀, so every
proposal is accepted; leapfrog's energy error makes the Metropolis step do real work — yet both leave
the target N(μ, σ²) invariant. Push ε past 2σ√m and leapfrog turns
unstable: the orbit spirals outward and acceptance collapses.