Hanqing Li Hanqing Li 李汉青


Hamiltonian Monte Carlo uses gradient information to propose distant moves with high acceptance probability. Its diagnostics reflect failures of numerical geometry.

Hamiltonian augmentation

HMC augments the parameter with momentum so that posterior simulation becomes approximate Hamiltonian flow.

Definition. Let \(U(q)=-\log\pi(q\mid X)\), choose mass matrix \(M\), and introduce momentum \(p\sim N(0,M)\). The Hamiltonian is \[ H(q,p)=U(q)+\frac12p^\top M^{-1}p. \]

Proposition. The joint density proportional to \(\exp\{-H(q,p)\}\) has marginal density \(\pi(q\mid X)\).

Proof. The joint density factors into \(\pi(q\mid X)\) times the Gaussian momentum density. Integrating out \(p\) leaves the posterior density of \(q\).

Leapfrog reversibility and volume preservation

The leapfrog integrator is used because it preserves the geometric properties needed for a Metropolis correction.

Proposition. Leapfrog updates are reversible and volume preserving. Therefore a Metropolis correction using the Hamiltonian error leaves the joint target invariant.

Proof. Each half-step momentum update and full-step position update is a shear map with determinant one. The symmetric composition is reversible after momentum negation. Volume preservation and reversibility are exactly the conditions used in the Metropolis acceptance proof.

Divergences

Divergences indicate that the numerical trajectory has encountered geometry too sharp for the chosen step size and parameterization.

Remark. Divergences often occur near funnels, boundaries, or strong posterior curvature. Increasing target acceptance may help, but reparameterization is often the mathematical fix.

Energy and effective sample size

HMC diagnostics are geometric diagnostics of exploration.

Definition. Energy Bayesian fraction of missing information and related energy diagnostics compare variation in the Hamiltonian across transitions with marginal energy variation. Low energy exploration suggests poor movement across posterior level sets.

Remark. Large effective sample size for some scalar summaries does not guarantee that all posterior geometry has been explored. HMC should be checked on the quantities that matter for the inferential question.

Hamiltonian flow

Definition. Write the target as \[ \pi(q)\propto e^{-U(q)} \] and introduce momentum \[ p\sim N(0,M). \] The Hamiltonian is \[ H(q,p)=U(q)+K(p), \qquad K(p)=\frac12p^\top M^{-1}p. \] Hamilton's equations are \[ \frac{\mathrm{d}q}{\mathrm{d}t}=M^{-1}p, \qquad \frac{\mathrm{d}p}{\mathrm{d}t}=-\nabla U(q). \]

Theorem. Exact Hamiltonian flow preserves \(H\), phase-space volume, and the joint density \[ \widetilde\pi(q,p)\propto e^{-H(q,p)}. \]

Proof. Along a trajectory, \[ \frac{\mathrm{d}H}{\mathrm{d}t} =\nabla U(q)^\top M^{-1}p +(M^{-1}p)^\top\{-\nabla U(q)\}=0. \] The vector field \((M^{-1}p,-\nabla U(q))\) has divergence zero, so Liouville's theorem gives volume preservation. Constant \(H\) and preserved volume imply invariance of \(e^{-H}\).

Leapfrog integrator

Definition. One leapfrog step of size \(\epsilon\) is \[ p_{1/2}=p_0-\frac{\epsilon}{2}\nabla U(q_0), \] \[ q_1=q_0+\epsilon M^{-1}p_{1/2}, \] \[ p_1=p_{1/2}-\frac{\epsilon}{2}\nabla U(q_1). \]

Proposition. Leapfrog is volume-preserving and reversible under momentum negation. Its global energy error over a fixed integration time is \(O(\epsilon^2)\) under smoothness.

Proof. Each momentum shear and position shear has Jacobian determinant one, so their composition preserves volume. Applying the same three updates with step \(-\epsilon\) reverses the map; equivalently, negate momentum before and after a forward step. Leapfrog is the symmetric Strang splitting of kinetic and potential flows, so local truncation error is \(O(\epsilon^3)\) and fixed-time global error is \(O(\epsilon^2)\).

Metropolis correction

Theorem. Let \(\Phi\) be an \(L\)-step leapfrog proposal followed by momentum negation. Accept \((q',p')=\Phi(q,p)\) with probability \[ \alpha=1\wedge \exp\{-H(q',p')+H(q,p)\}. \] The resulting kernel is reversible with respect to \(\widetilde\pi\).

Proof. The deterministic proposal is an involution after momentum negation and has unit Jacobian. The Metropolis ratio is therefore simply the target-density ratio \(e^{-H(q',p')}/e^{-H(q,p)}\). The standard Metropolis detailed-balance calculation applies.

Gaussian geometry and mass matrices

Example. For \[ q\sim N(0,\Sigma), \qquad U(q)=\frac12q^\top\Sigma^{-1}q, \] Hamilton's equation implies \[ \frac{\mathrm{d}^2q}{\mathrm{d}t^2} =-M^{-1}\Sigma^{-1}q. \] If \(M=\Sigma^{-1}\), every transformed direction has unit frequency. If \(M=I\), frequencies vary with posterior scales, and the step size must resolve the narrowest direction. Adapting a dense mass matrix approximately whitens global covariance, though it cannot remove nonlinear curvature.

No-U-turn trajectory selection

Long trajectories eventually retrace their path and waste computation. The no-U-turn criterion stops trajectory doubling when, schematically, \[ (q^+-q^-)^\top M^{-1}p^-<0 \quad\text{or}\quad (q^+-q^-)^\top M^{-1}p^+<0. \] Modern NUTS constructions sample from the built trajectory with a rule preserving detailed balance. The criterion is geometric, not a convergence diagnostic; poor geometry can still make every available trajectory inadequate.

Divergences and posterior funnels

Example (Neal funnel). Let \[ v\sim N(0,3^2),\qquad x_j\mid v\sim N(0,e^v). \] For negative \(v\), the \(x_j\)-coordinates lie in an extremely narrow neck; for positive \(v\), they are broad. The Hessian scale changes exponentially with \(v\), so a step size stable in the neck is inefficient in the body, while a larger step diverges in the neck. The noncentered form \[ x_j=e^{v/2}z_j,\qquad z_j\sim N(0,1), \] removes much of this coupling.

A divergence is a large numerical energy error, often indicating that leapfrog cannot resolve local curvature. Increasing target acceptance reduces step size and may help, but reparameterization is usually the substantive remedy. Discarding divergent draws biases the approximation.

Energy mixing

Definition. One empirical form of the Bayesian fraction of missing information is \[ \operatorname{E\text{-}BFMI} =\frac{\sum_{s=2}^N(E_s-E_{s-1})^2} {\sum_{s=1}^N(E_s-\bar E)^2}, \] up to conventional normalization, where \(E_s=H(q_s,p_s)\). Small values indicate that momentum refreshment changes energy by much less than the target's marginal energy range.

Energy histograms, divergences, tree depth, acceptance, rank-normalized \(\widehat R\), and function-specific ESS diagnose different failures. None validates the statistical model; simulation-based calibration and posterior predictive checks address separate questions.