- Home
- Library
- Computational Quantum Field Theory
- Sampling Measures and Estimating Free Energies
- Markov Chains and Hamiltonian Proposals
Markov Chains and Hamiltonian Proposals
A field configuration can have thousands of coupled components. Moving each component independently may change the action so much that nearly every proposal is rejected; making every move tiny can leave the chain exploring very slowly. Hamiltonian Monte Carlo uses the action's gradient to propose a coordinated move, then corrects its numerical error with an acceptance step.
We will construct both a random-walk sampler and a Hamiltonian sampler for the same correlated Gaussian, prove their invariant measure, and compare the work required to estimate one specified observable. Correct equilibrium probabilities and rapid exploration are separate questions.
Preparation: Probability densities, Gaussian covariance matrices, and importance sampling. All actions below are dimensionless finite Euclidean actions, with weight .
Preserve a probability distribution
Let and
A transition kernel includes accepted moves and rejections. Its invariance condition is
for every measurable set . If the current configuration has distribution , the next one does too. Detailed balance,
is a sufficient way to obtain this condition: integrate over . It is not necessary, and invariance alone does not guarantee convergence from the starting state. A kernel that never moves preserves every distribution and samples none of them from a fixed initial point.
Suppose a proposal has density . On pairs with nonzero forward and reverse probability, choose
The accepted probability flux is the smaller of the two proposed fluxes, so it is symmetric. Add the probability of rejection as a point mass at . This proves detailed balance without knowing .
For a symmetric Gaussian proposal , , the ratio reduces to . In code, comparing with avoids exponentiating a large number. Rejected states must remain in the sequence: deleting them changes the sampling measure.
Follow a Hamiltonian trajectory
Introduce an auxiliary momentum with a constant positive matrix and define
The extended density is proportional to ; integrating out gives . Hamilton's equations in an auxiliary simulation time are
This time is an algorithmic parameter. It is not the Lorentzian time evolution of the field theory.
Exact Hamiltonian flow conserves and phase-space volume. A practical trajectory uses leapfrog steps:
Each kick or drift is a shear with unit Jacobian. Reversing the momenta reverses the trajectory. If denotes steps and , the map is an involution with unit absolute Jacobian. Accepting it with
therefore balances the flux between paired points. Refreshing , applying this accepted map, and discarding gives a kernel with the desired marginal. This argument requires the stated reversible, volume-preserving numerical map; approximate energy conservation alone would not suffice. The construction and its assumptions are developed in Neal, §§2.3 and 3.2.
A position-dependent mass matrix needs a different extended density and integrator. Simply substituting into these equations does not preserve the target.
A narrow Gaussian valley
Take
The variances along and are and . An isotropic random walk must accommodate the narrow direction while traveling along the broad one. With , Hamiltonian motion has frequencies and ; its leapfrog stability condition is in each mode.
Our random walk uses . HMC uses and , comfortably within that linear stability bound. Neither choice is asserted to be globally optimal. A fixed trajectory length near a mode's full period can mix poorly even with very high acceptance; varying lengths or choosing a suitable constant mass matrix can help.
For each method, the accompanying calculation runs 512 independent chains, each with 8,192 stored states. Every chain starts from an independently drawn exact Gaussian sample. Thus this experiment isolates stationary sampling error; it does not test equilibration from a displaced start. The primary observable is , whose exact mean is zero. Second moments and the cross moment are checked against .
| Quantity | Random walk | HMC |
|---|---|---|
| Acceptance fraction | 0.4788 | 0.9889 |
| Standard deviation of the estimated mean across runs | 0.09570 | 0.01266 |
| Action/gradient work units per stored state | 1 | 12 |
| Work times variance of the mean | 75.03 | 15.75 |
One work unit here means one full evaluation of or . The old action is cached. A trajectory uses 11 gradient evaluations and one new action; momentum generation and linear algebra overhead are not priced separately.
If an asymptotic variance scales as , reaching standard error costs approximately , where is work per state. The measured coefficients imply about random-walk units versus HMC units for : a factor of about 4.8 for this observable and cost model. Prefixes of 2,048 states give coefficients 76.70 and 14.82, supporting the approximate inverse-length scaling here. These are estimates from repeated runs, not guaranteed error bounds.
The linear trajectory's reversal error is below and its determinant agrees with one to floating-point accuracy. These tests diagnose integrator mistakes; the separate moment checks test the target distribution. Neither demonstrates correct sampling of an unrelated interacting theory.
Measure what the chain can tell you
Acceptance is an implementation diagnostic, not an effective sample count. Correlations depend on the observable. A sampler may estimate efficiently yet miss a slower nonlinear or topological observable. For a non-Gaussian application, compare dispersed starting states, inspect slow quantities, and estimate their autocorrelation and uncertainty.
Finite-precision reversibility, force errors, numerical overflow, or incorrect rejection bookkeeping can invalidate a nominally correct implementation. The Metropolis correction repairs the discretization error of the specified reversible proposal; it is not a repair for arbitrary code errors.
For a group-valued gauge link the momentum is in the Lie algebra, and the lattice gauge-force calculation differentiates the oriented plaquette under a group rotation. It also checks reversibility at fixed integration and solve settings. For a discrete spin, a conditional bond construction instead gives a collective proposal that obeys detailed balance.
Summary
Construct a kernel by proving invariance for its complete transition, including rejection. Hamiltonian proposals exploit gradients while an acceptance step corrects their finite-step energy error. Compare samplers at matched error for a stated observable and an explicit cost model; high acceptance alone does not establish efficient exploration.
Exercises
A stationary chain without detailed balance
On three states labeled modulo three, stay put with probability and move forward by one with probability . Find the invariant measure and determine whether the chain is reversible or periodic.
Solution
Each column of the transition matrix sums to one, so the uniform measure is invariant. There is a forward transition from 0 to 1 but no reverse transition from 1 to 0, violating detailed balance. The directed cycle makes every state reachable, and the self-loop makes the period one. Thus this finite irreducible, aperiodic chain converges to the uniform measure despite being nonreversible.
One leapfrog step
For , start at and use . Compute the proposed point before the final momentum reversal, the energy error, and the acceptance probability.
Solution
The first kick leaves . The drift gives , and the second kick gives . Hence
The final momentum reversal preserves this energy. The acceptance is , not exactly one despite the oscillator being solvable analytically.
References
- R. M. Neal, “MCMC using Hamiltonian dynamics,” in Handbook of Markov Chain Monte Carlo (2011), arXiv:1206.1901, §§2.3, 3.2–3.3 and 4.
Reproducible calculations: examples/computational-qft/monte-carlo-methods/README.md.
Scrollable formula. Use Left and Right arrow keys to reveal hidden content.
Scrollable table. Use Left and Right arrow keys to reveal hidden columns.
Scrollable figure. Use Left and Right arrow keys to reveal hidden content.