Metropolis-Hastings

Metropolis-Hastings (MH) is an MCMC algorithm that produces a sequence whose long-run distribution is a target density known only up to a normalizing constant. It works by converting an arbitrary proposal transition into a Markov chain that satisfies detailed balance with respect to , using a single accept/reject step.

Given the current state , one iteration proceeds as follows:

  1. Propose .
  2. Compute the acceptance probability
  3. Draw . If , accept: set . Otherwise reject: set .

The resulting chain satisfies detailed balance with respect to :

where is the transition kernel of the MH chain. Under irreducibility, is therefore the unique stationary distribution, and by the ergodic theorem

for any integrable . Only the ratio appears in , so any unknown normalizing constant of cancels. This is the reason MH is the workhorse of Bayesian computation: the unnormalized posterior is sufficient to run the algorithm, and the intractable marginal likelihood is never needed.

When the proposal is symmetric — , as when for symmetric about — the Hastings correction equals one and the acceptance probability collapses to

This special case is the Metropolis algorithm (proposed first historically; Hastings’ extension handles asymmetric ). The further specialization in which for a random-walk increment is the random walk Metropolis chain, typically with or .

Intuition

Standard rejection sampling requires a proposal density that uniformly dominates the target by a known constant — infeasible when is known only up to a normalizing constant, as happens for essentially every nontrivial Bayesian posterior. MH sidesteps the dominance requirement by constructing a Markov chain whose stationary distribution is , rather than drawing independent samples outright. The chain’s samples are correlated, but long-run averages still converge to integrals against by the ergodic theorem.

The algorithm’s central trick is that an arbitrary proposal will almost certainly produce a chain that fails detailed balance with respect to . Adding a single accept/reject step with probability repairs the imbalance exactly. The ratio measures how much overproposes the move relative to what would like; the accept step discards the excess. The central tension is between proposals large enough to explore the state space — but so large they are rejected in the tails — and proposals small enough to be accepted but so small the chain crawls.

Properties

(Detailed Balance) The MH transition kernel satisfies by construction.

For , the MH transition density factors as . Multiplying by and substituting the acceptance formula,

and the right-hand side is symmetric under the swap . Detailed balance implies is stationary for ; irreducibility (plus aperiodicity in discrete state spaces) upgrades stationarity to convergence via the ergodic theorem. The full derivation is given in the Derivation section below.

(Only Ratios Needed) The acceptance probability depends on only through , so unknown normalizing constants cancel.

If for any constant , then . This makes MH the standard tool for Bayesian inference: the unnormalized posterior is enough to run the algorithm, and the marginal likelihood

— the quantity that makes direct posterior sampling intractable — never has to be computed.

(Symmetric Proposals) If , the Hastings correction drops out and .

The simplest instance is the random walk Metropolis chain with for symmetric about (e.g., or ). Under a symmetric , the accept step becomes: always accept moves to higher density; accept moves to lower density with probability equal to the density ratio. This preserves frequent exploration of high-density regions while still allowing downhill moves into the tails.

(Independence Sampler) If does not depend on , MH becomes an independence sampler with .

The proposal draws candidates from a fixed distribution independent of the current state. The Hastings correction is essential here — omitting it would target , not . Independence samplers mix well when is a close approximation to (a common choice is a Laplace approximation of the posterior, i.e., a Gaussian centered at the MAP with covariance ). They mix badly when has lighter tails than , because the chain gets trapped in tail regions where is large and any move away is rejected.

(Proposal Scale Trade-off) The proposal variance controls an exploration-versus-acceptance trade-off; either extreme mixes slowly.

For random walk Metropolis with : if is too small, nearly every proposal is accepted but each move is tiny, producing strong autocorrelation and slow exploration of . If is too large, most proposals land in low-density regions and are rejected, producing a chain that rarely moves. The acceptance rate (fraction of proposals accepted) is the standard diagnostic: theory for high-dimensional Gaussian targets suggests tuning toward roughly , and – is a practical working range. When coordinates of live on very different scales, an isotropic proposal is the wrong shape — a diagonal or full covariance matched to the posterior (often obtained from a Laplace approximation of the posterior at the MAP) improves mixing dramatically.

(Burn-in and Initialization) Early iterates depend on ; they are discarded, and initializing near a posterior mode shortens the required burn-in.

The ergodic theorem guarantees as , but for finite the approximation depends on how quickly the chain forgets its starting point. Standard practice is to discard the first iterates — the burn-in — and use only for averages. Initializing at the MLE or MAP (rather than at an arbitrary point) cuts burn-in sharply, because the chain starts in a high-density region of . Trace plots of each coordinate against iteration number are the standard visual diagnostic: a well-mixed chain looks like stationary noise around the posterior mean; a poorly-mixed chain drifts for many iterations or stays stuck at constant values.

(Any Proposal Works) Correctness of MH depends only on , , and the acceptance formula; the choice of determines efficiency, not whether the chain targets .

Irreducibility requires only that can reach every region of positive -mass, however slowly. Different choices of give qualitatively different algorithms — random walk Metropolis, independence samplers, Langevin dynamics, Hamiltonian Monte Carlo — but the underlying detailed-balance construction is identical. Choosing is an engineering problem about mixing speed, not correctness. The acceptance formula is the unique maximally-accepting rule that preserves detailed balance: any smaller that satisfies the balance equation could be enlarged toward without breaking stationarity.

(Relation to Gibbs) Gibbs sampling is the special case of MH in which proposals are drawn from full conditionals and always accepted.

If proposes by redrawing a single coordinate from its full conditional and leaving the rest fixed, algebraic cancellation gives , so every proposal is accepted. Gibbs thus avoids the acceptance overhead of MH but requires the full conditionals to be available in closed form. MH trades acceptance for the ability to handle arbitrary targets — the two algorithms sit at opposite ends of the same MCMC family, and hybrid “Metropolis-within-Gibbs” schemes handle cases where some conditionals are tractable and others are not.

Examples

Derivation

Goal. Show that the MH transition kernel satisfies detailed balance with respect to , i.e., for all . Together with irreducibility of the chain, this establishes as the unique stationary distribution and, via the ergodic theorem, justifies the Monte Carlo approximation .

Write the MH transition kernel as

where is the total rejection probability at and is a point mass. The rejection term trivially satisfies detailed balance because (both vanish unless ), so it suffices to check balance for the accept term in the case :

Substituting and distributing the through the product,

The right-hand side is symmetric under the swap , so it equals , which by the same algebra equals . This proves detailed balance.

The acceptance probability was not pulled from thin air: it is the maximal function that makes the balance equation hold. Any smaller than this minimum-to-one form would also balance the flow, but would reject more often and mix more slowly — the MH choice is the uniquely efficient one.

See Also