Tutorials › Stochastic Processes › Proving Invariance of Metropolis-Hastings and Gibbs Kernels

Markov Chain Monte Carlo · Tutorial 925 of 994

Proving Invariance of Metropolis-Hastings and Gibbs Kernels

Learn to verify target invariance for Metropolis–Hastings and Gibbs updates, and to distinguish invariance of a composed sampler from reversibility.

Advanced 12 min read

What You'll Learn

  • Define invariance and detailed balance for a Markov kernel.
  • Prove detailed balance for a Metropolis–Hastings kernel, including rejected proposals.
  • Show how a Gibbs update preserves its joint target using conditional expectation.
  • Verify invariance by exact calculation in finite-state examples.
  • Prove that compositions of invariant kernels remain invariant.
  • Identify why a systematic composition can be invariant but not reversible.

Invariance Is Not the Same as Reversibility

In Markov chain Monte Carlo, a transition rule should preserve the distribution it is designed to sample. The precise claim is invariance: if the current state has the target distribution, then the next state has that distribution too. Detailed balance is a stronger, pairwise condition that implies invariance. Metropolis–Hastings is built to satisfy detailed balance, while a Gibbs update can be shown to preserve the target by integrating over a conditional distribution. These arguments also clarify what happens when updates are composed: invariance is preserved by composition, but detailed balance need not be.

Let \((\Omega,\mathcal{F},\mathbb{P})\) be a probability space, and let \((X_n)_{n\ge0}\) be a discrete-time Markov chain on a finite or countable state space \(S\), with transition kernel \(K=(K(i,j))\). Each row of \(K\) sums to \(1\). A probability distribution \(\pi=(\pi_i)\), written as a row vector, is invariant for \(K\) if \(\pi K=\pi\). It satisfies detailed balance if \(\pi_iK(i,j)=\pi_jK(j,i)\) for all \(i,j\in S\). Invariance is a property of one-step marginal distributions; it does not assert that the chain has reached the target from every starting state.

Theorem (Metropolis–Hastings detailed balance): Suppose \(\pi_i>0\) for every \(i\) in a finite or countable state space \(S\), and \(q(i,j)\) is a proposal transition matrix whose rows sum to \(1\). For \(i\ne j\), set \(\alpha(i,j)=\min\{1,\pi_jq(j,i)/(\pi_iq(i,j))\}\) when \(q(i,j)>0\), and set \(\alpha(i,j)=0\) when \(q(i,j)=0\). Define \(K(i,j)=q(i,j)\alpha(i,j)\) for \(i\ne j\), and \(K(i,i)=1-\sum_{j\ne i}K(i,j)\). Then \(K\) is a transition kernel and satisfies detailed balance with respect to \(\pi\); consequently \(\pi\) is invariant.

The acceptance rule compares the proposed probability flow \(\pi_iq(i,j)\) with the reverse flow \(\pi_jq(j,i)\). Rejection is included in \(K(i,i)\), so the rule defines a probability of staying at the current state as well as probabilities of moving.

Proof. For \(i\ne j\), \(0\le\alpha(i,j)\le1\), so \(K(i,j)\ge0\). Moreover, \(\sum_{j\ne i}q(i,j)\alpha(i,j)\le\sum_{j\ne i}q(i,j)\le1\), making \(K(i,i)\ge0\). By its definition, the row sum of \(K\) is \(1\). To prove detailed balance, first suppose \(q(i,j)>0\) and \(q(j,i)>0\). Then \[ \pi_iK(i,j)=\min\{\pi_iq(i,j),\pi_jq(j,i)\}=\pi_jK(j,i). \] If \(q(i,j)=0\), then \(K(i,j)=0\). If \(q(j,i)>0\), the ratio defining \(\alpha(j,i)\) has zero numerator, so \(K(j,i)=0\) as well. If both proposal probabilities are zero, both off-diagonal kernel entries are zero. Thus detailed balance holds for every distinct pair; for \(i=j\) it is an identity. Finally, for each \(j\), summing detailed balance over \(i\) gives \[ \sum_i\pi_iK(i,j)=\pi_j\sum_iK(j,i)=\pi_j, \] because row \(j\) of \(K\) sums to \(1\). Hence \(\pi K=\pi\). \(\square\)

Worked Example: An Asymmetric Two-State Proposal

Take \(S=\{1,2\}\), target \(\pi=(\tfrac13,\tfrac23)\), and proposal matrix \(q=\begin{bmatrix}\tfrac14&\tfrac34\\ \tfrac14&\tfrac34\end{bmatrix}\). Each proposal row sums to \(\tfrac14+\tfrac34=1\). Find the Metropolis–Hastings kernel and check target invariance.

From state \(1\), the proposal to state \(2\) is accepted with probability \[ \alpha(1,2)=\min\left\{1,\frac{(\tfrac23)(\tfrac14)}{(\tfrac13)(\tfrac34)}\right\} =\min\{1,\tfrac23\}=\tfrac23. \] Thus \(K(1,2)=\tfrac34\cdot\tfrac23=\tfrac12\), and \(K(1,1)=1-\tfrac12=\tfrac12\). From state \(2\), \[ \alpha(2,1)=\min\left\{1,\frac{(\tfrac13)(\tfrac34)}{(\tfrac23)(\tfrac14)}\right\} =\min\{1,\tfrac32\}=1. \] Thus \(K(2,1)=\tfrac14\), and \(K(2,2)=1-\tfrac14=\tfrac34\). The resulting rows each sum to \(1\): \(\tfrac12+\tfrac12=1\) and \(\tfrac14+\tfrac34=1\).

$$ K= \begin{bmatrix} \tfrac12&\tfrac12\\ \tfrac14&\tfrac34 \end{bmatrix}, \qquad \pi K= \left( \tfrac13\cdot\tfrac12+\tfrac23\cdot\tfrac14,\ \tfrac13\cdot\tfrac12+\tfrac23\cdot\tfrac34 \right) = \left(\tfrac13,\tfrac23\right). $$

Check: the two opposing flows are \(\pi_1K(1,2)=\tfrac13\cdot\tfrac12=\tfrac16\) and \(\pi_2K(2,1)=\tfrac23\cdot\tfrac14=\tfrac16\). Their equality verifies detailed balance directly, and the displayed multiplication verifies invariance.

Gibbs Updates Preserve the Joint Target

A Gibbs update replaces one component of the current state by a draw from its conditional distribution under the target, leaving the other components fixed. The argument below uses a two-component state \(S=\mathcal{X}\times\mathcal{Y}\) with target probability distribution \(\Pi\). Assume conditional distributions \(\Pi(dx\mid y)\) and \(\Pi(dy\mid x)\) are defined for target-almost-every \(y\) and \(x\), respectively. For finite or countable spaces, these are the usual conditional probabilities whenever the conditioning event has positive target probability. Values on conditioning events of target probability zero may be assigned arbitrarily, since they do not affect the invariance calculation.

Theorem (Invariance of a Gibbs update): Let \(K_X\) update \(x\) from \(\Pi(dx\mid y)\) while keeping \(y\) fixed. Then \(\Pi\) is invariant for \(K_X\). The corresponding update \(K_Y\), which draws \(y\) from \(\Pi(dy\mid x)\) while keeping \(x\) fixed, also preserves \(\Pi\).

Proof. Let \(f\) be any bounded measurable function on \(\mathcal{X}\times\mathcal{Y}\). Starting from \((x,y)\), the update \(K_X\) draws \(x'\) from \(\Pi(dx'\mid y)\). Integrating the expected value of \(f\) after the update against the target gives \[ \int \Pi(dx,dy)\int \Pi(dx'\mid y)f(x',y) =\int \Pi_{\mathcal{Y}}(dy)\int \Pi(dx\mid y)\int\Pi(dx'\mid y)f(x',y) =\int \Pi_{\mathcal{Y}}(dy)\int\Pi(dx'\mid y)f(x',y) =\int f(x,y)\Pi(dx,dy). \] The second equality holds because \(\int\Pi(dx\mid y)=1\) for target-almost-every \(y\); the last is the conditional-distribution decomposition of \(\Pi\). Thus the distribution after the update integrates every bounded measurable \(f\) exactly as \(\Pi\) does, so it equals \(\Pi\). For \(K_Y\), the same calculation integrates first over the conditional law of \(y\) given \(x\): the unchanged \(x\) has marginal \(\Pi_{\mathcal{X}}\), and the newly drawn \(y'\) has law \(\Pi(dy'\mid x)\). The resulting joint distribution is again \(\Pi\). \(\square\)

Worked Example: Checking One Coordinate Update

On \(\{0,1\}^2\), let the target probabilities of \(00,01,10,11\), in that order, be \((\tfrac1{10},\tfrac2{10},\tfrac3{10},\tfrac4{10})\). They sum to \(\tfrac{1+2+3+4}{10}=1\). Update the first coordinate \(x\) from its conditional distribution given \(y\), leaving \(y\) fixed.

When \(y=0\), the conditional probabilities for \(x=0,1\) are \(\tfrac{1}{1+3}=\tfrac14\) and \(\tfrac34\). When \(y=1\), they are \(\tfrac{2}{2+4}=\tfrac13\) and \(\tfrac23\). With states ordered \(00,01,10,11\), the update kernel is \[ K_X= \begin{bmatrix} \tfrac14&0&\tfrac34&0\\ 0&\tfrac13&0&\tfrac23\\ \tfrac14&0&\tfrac34&0\\ 0&\tfrac13&0&\tfrac23 \end{bmatrix}. \] Each row sums to \(1\): the two distinct row sums are \(\tfrac14+\tfrac34=1\) and \(\tfrac13+\tfrac23=1\). Multiplying the target row vector by this kernel gives \[ \pi K_X= \left( \tfrac4{10}\cdot\tfrac14,\ \tfrac6{10}\cdot\tfrac13,\ \tfrac4{10}\cdot\tfrac34,\ \tfrac6{10}\cdot\tfrac23 \right) = \left(\tfrac1{10},\tfrac2{10},\tfrac3{10},\tfrac4{10}\right). \] The factors \(\tfrac4{10}\) and \(\tfrac6{10}\) are the target marginal probabilities of \(y=0\) and \(y=1\). This exact check agrees with the conditional-expectation proof.

Composing Invariant Updates

Suppose \(K_1\) and \(K_2\) are transition kernels on the same state space and both preserve \(\pi\). Applying \(K_1\) and then \(K_2\) gives the composed kernel \(K_1K_2\), with \((K_1K_2)(i,j)=\sum_kK_1(i,k)K_2(k,j)\) in the countable case. It too preserves \(\pi\): starting with \(\pi\), the first update leaves the distribution at \(\pi\), and the second does the same.

Proposition (Invariance under composition): If \(\pi K_1=\pi\) and \(\pi K_2=\pi\), then \(\pi(K_1K_2)=\pi\). The same conclusion holds for any finite ordered composition of kernels that each preserve \(\pi\).

Proof. By associativity of multiplication of probability vectors and kernels, \[ \pi(K_1K_2)=(\pi K_1)K_2=\pi K_2=\pi. \] Applying this identity repeatedly proves the claim for any finite number of updates. No detailed-balance assumption is used. \(\square\)

Worked Example: A Systematic Gibbs Sweep Can Be Nonreversible

Use the binary target from the preceding example. First update \(x\) given \(y\), then update \(y\) given the newly updated \(x\). For the second update, the conditional probabilities are \(\mathbb{P}(y=0\mid x=0)=\tfrac13\), \(\mathbb{P}(y=1\mid x=0)=\tfrac23\), \(\mathbb{P}(y=0\mid x=1)=\tfrac37\), and \(\mathbb{P}(y=1\mid x=1)=\tfrac47\). Its rows, in state order \(00,01,10,11\), are \((\tfrac13,\tfrac23,0,0)\), \((\tfrac13,\tfrac23,0,0)\), \((0,0,\tfrac37,\tfrac47)\), and \((0,0,\tfrac37,\tfrac47)\). Each row sums to \(1\), since \(\tfrac13+\tfrac23=1\) and \(\tfrac37+\tfrac47=1\).

Multiplying \(K_X\) by this \(K_Y\) gives the one-sweep kernel \(P=K_XK_Y\). For instance, from \(00\), the first update gives \(00\) with probability \(\tfrac14\) and \(10\) with probability \(\tfrac34\). The second update then gives row \[ \tfrac14(\tfrac13,\tfrac23,0,0)+\tfrac34(0,0,\tfrac37,\tfrac47) =(\tfrac1{12},\tfrac16,\tfrac9{28},\tfrac37). \] From \(01\), the first update gives \(01\) with probability \(\tfrac13\) and \(11\) with probability \(\tfrac23\), yielding row \[ \tfrac13(\tfrac13,\tfrac23,0,0)+\tfrac23(0,0,\tfrac37,\tfrac47) =(\tfrac19,\tfrac29,\tfrac27,\tfrac8{21}). \] The first update depends on the old \(y\), not on the old \(x\), so rows for \(10\) and \(11\) repeat those for \(00\) and \(01\), respectively. Thus \[ P= \begin{bmatrix} \tfrac1{12}&\tfrac16&\tfrac9{28}&\tfrac37\\ \tfrac19&\tfrac29&\tfrac27&\tfrac8{21}\\ \tfrac1{12}&\tfrac16&\tfrac9{28}&\tfrac37\\ \tfrac19&\tfrac29&\tfrac27&\tfrac8{21} \end{bmatrix}. \] The row sums are \((7+14+27+36)/84=1\) for the first and third rows, and \((7+14+18+24)/63=1\) for the second and fourth rows. Since each coordinate update preserves the target, the composition does too; explicitly, \[ \pi P= \left( \tfrac4{10}\cdot\tfrac1{12}+\tfrac6{10}\cdot\tfrac19,\ \tfrac4{10}\cdot\tfrac16+\tfrac6{10}\cdot\tfrac29,\ \tfrac4{10}\cdot\tfrac9{28}+\tfrac6{10}\cdot\tfrac27,\ \tfrac4{10}\cdot\tfrac37+\tfrac6{10}\cdot\tfrac8{21} \right) = (\tfrac1{10},\tfrac2{10},\tfrac3{10},\tfrac4{10}). \] For example, the third entry is \(\tfrac9{70}+\tfrac{12}{70}=\tfrac3{10}\), and the fourth is \(\tfrac{18}{105}+\tfrac{24}{105}=\tfrac25\).

Check that this sweep is not reversible. Detailed balance between \(00\) and \(01\) would require \(\pi_{00}P(00,01)=\pi_{01}P(01,00)\). The left side is \(\tfrac1{10}\cdot\tfrac16=\tfrac1{60}\), whereas the right side is \(\tfrac2{10}\cdot\tfrac19=\tfrac1{45}\). These are unequal. Thus the systematic sweep is invariant, as the composition argument requires, but it is not reversible.

Which Argument Applies?

For a Metropolis–Hastings kernel, the direct proof is pairwise: compare the target-weighted flow from \(i\) to \(j\) with the reverse flow, then account for rejection on the diagonal. For a Gibbs coordinate update, the direct proof is conditional: under the target, the unchanged coordinates have their target marginal, and the replaced coordinate is drawn from its target conditional distribution. For a composition, invariance follows by applying the invariance identities in update order; do not infer detailed balance merely because the individual kernels are reversible.

Common mistake. A tempting but incorrect argument is: “Each coordinate update is reversible, so their systematic composition is reversible.” The binary example disproves this: its coordinate updates preserve the target, but the one-sweep flows between \(00\) and \(01\) are \(\tfrac1{60}\) and \(\tfrac1{45}\), not equal. The valid conclusion is only that the composition preserves the target. Detailed balance for the composition must be checked separately, and it can fail.

Check Your Understanding

For each question, distinguish the invariance claim from any detailed-balance claim.

  1. In the two-state Metropolis–Hastings example, calculate both target-weighted flows between states \(1\) and \(2\), and explain what their equality establishes.
  2. Why does the rejection probability belong on the diagonal of a Metropolis–Hastings kernel?
  3. For a Gibbs update of \(x\) given \(y\), which target marginal remains unchanged during the update?
  4. If two kernels each preserve \(\pi\), write the one-line identity proving that their ordered composition preserves \(\pi\).
  5. In the systematic binary Gibbs sweep, calculate \(\pi_{00}P(00,01)\) and \(\pi_{01}P(01,00)\). What do the values show?