Hamiltonian Monte Carlo Sampler

HMC uses Hamiltonian dynamics to propose distant moves in parameter space. Compare with random walk MH. Visualize leapfrog trajectories, energy conservation, and acceptance rates on a 2D target distribution.

HMC (Duane et al. 1987): augment target π(q) with momenta H(q,p)=-log π(q)+p²/2. Leapfrog integrates Hamilton's equations exactly (symplectic). Metropolis accept/reject corrects for numerical error. Acceptance rate → 1 as ε→0. HMC is the engine behind Stan/PyMC3. Nuts sampler (Hoffman-Gelman 2011) adapts L automatically. HMC scales to high dimensions where MH fails (autocorrelation ∝ d).