Ergodicity
The property that lets a chain forget its start. An ergodic chain has one long-run behavior, so time averages from a single run equal ensemble averages.
Why Does This Exist?
Stationary distributions promise a fixed vector, but they do not promise you will reach it. A chain that flips deterministically between two states has a stationary distribution yet never settles from any start. A chain with two disconnected halves settles, but onto a limit that depends on where you began. Ergodicity is the condition that rules out both failures, and it is the license under which Markov chain Monte Carlo operates: one long run, started anywhere, eventually represents the target.
Concretely, a finite chain is ergodic when it is irreducible and aperiodic. Irreducible means every state can reach every other state, so there are no traps or islands. Aperiodic means the chain does not pulse on a fixed cycle, so visits smear out instead of alternating. Together they give a unique stationary with as grows, and time averages converge to expectations under .
The one idea you need first
A state has period if returns to it are only possible at multiples of steps. A two-state flip-flop has period 2. A chain with a self-loop of positive probability anywhere reachable is aperiodic, because that loop breaks every cycle length. The chain background is in Markov chains.
Think of It Like This
Three thermometers in one house
Put three thermometers in a house: one starts reading freezing, one room temperature, one sauna-hot. If the house has good airflow (irreducible, every room reaches every other) and no door that only opens on alternate minutes (aperiodic, no forced cycle), all three readings drift to the same room temperature and stay together. The start is forgotten.
Now break each condition in turn. Seal a room off and its thermometer keeps its own climate forever: reducible. Or force the heating to alternate rooms on a strict timer and the readings oscillate forever instead of settling: periodic. MCMC practitioners live this analogy every time they argue about burn-in length and thinning.
Where the analogy stops: thermometers converge because physics averages; chains converge because the transition matrix contracts differences, at a rate set by its second eigenvalue.
How It Actually Works
For a finite chain, check two things. First, irreducibility: for every pair there is some with . Second, aperiodicity: the greatest common divisor of return-step lengths is 1 for every state (in an irreducible chain, one state suffices). Pass both and the ergodic theorem holds:
for any function . The left side is what you compute from one run; the right side is the expectation under the stationary vector. This single equation justifies estimating posteriors, prices, and queue statistics from one long simulation.
Worked example
Take the two-state chain with from the stationary page. It is irreducible (each state reaches the other in one step) and aperiodic (both self-loops are positive), hence ergodic, with .
Track the running fraction of visits to A over 6 steps of one realized path : cumulative fractions are . Already circling 0.6. Start the same chain from B instead, path : fractions . Different opens, same neighborhood after a handful of steps. Extend either run to 1,000 steps and both averages sit within about of 0.6, because the per-step contraction factor is the second eigenvalue .
Contrast with the flip-flop . It is irreducible but periodic with period 2, so it is not ergodic. Started at A, the visit fraction to A oscillates without settling, and alternates between and forever.
Code
This compares running averages from two different starts on the ergodic chain. Same limit from both starts is the ergodic signature.
import numpy as np
P = np.array([[0.8, 0.2], [0.3, 0.7]])rng = np.random.default_rng(7)
def running_frac(start: int, n: int = 2000) -> float: s = start # 0 for A, 1 for B hits = 0 for t in range(1, n + 1): s = int(rng.random() < P[s, 1]) # next state, 1 means B hits += s == 0 # count visits to A return hits / n
print(round(running_frac(0), 3)) # -> 0.6print(round(running_frac(1), 3)) # -> 0.6Both prints land near 0.6 (typically within 0.02 at with seed 7) despite opposite starts. Replace with the flip-flop and the two runs keep disagreeing in a predictable alternating pattern instead.
Watch Out For
A stationary solver succeeding on a non-ergodic chain
Solving always returns something, even for reducible or periodic chains. People take that vector, simulate, and wonder why the run disagrees with it. The solver found an invariant vector; ergodicity is what makes the chain visit accordingly. Check reachability and period before quoting as the behavior.
Near-reducibility that looks converged but is not
A chain with a 0.999 self-loop on each of two weakly connected halves passes the formal checks yet mixes on a timescale of roughly steps. Short runs look settled inside whichever half they started in, and the halves disagree. Diagnose with multiple starts: if between-chain spread dwarfs within-chain wobble, run orders of magnitude longer.
The Quick Version
- Ergodic means irreducible plus aperiodic: every state reachable, no forced cycle.
- An ergodic finite chain has one stationary vector and forgets its start.
- Time averages from a single run converge to expectations under that vector.
- The worked chain converges with contraction factor 0.5; the flip-flop never settles.
- MCMC is valid only for ergodic chains, which is why diagnostics use multiple starts.
- Near-disconnected chains are formally ergodic but mix slowly, so test with widely spaced starts.