Foundations to Frontier
Tests
A. Mathematical Foundations › A4 Probability Theory › Stochastic processes

Markov Chains: Transition Matrices, Stationary Distributions, Ergodicity

A Markov chain is a random process with a short memory: the next state depends only on the current one. Its transition matrix P turns distributions forward (p_{t+1} = p_t P), its stationary distribution solves πP = π, and if the chain is irreducible and aperiodic it forgets its start at the rate of the second eigenvalue. You will compute absorption times, use detailed balance, learn why MCMC and PageRank work, and estimate P from data, the foundation of MDPs, HMMs and reinforcement learning.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Weather with a short memory

Suppose tomorrow’s weather depends only on today’s: after a sunny day there’s a 90% chance of sun, after a rainy day a 50% chance. You don’t need to remember last week, only today. A process like this, hopping between states with probabilities that depend only on where it is now, is a Markov chain.

Run it for a long time and something remarkable happens: the fraction of sunny days settles to a fixed number, whatever the weather was on day one. The chain forgets where it started.

A robot's terrain as a Markov chain: forget the start, approach π
start in:
P = [0.90 0.10 0.00] [0.20 0.70 0.10] [0.10 0.30 0.60]
pₜ(state)t (dotted: log TV to π)
π = (0.643, 0.286, 0.071) · TV(p₄₀, π) = 5.6e-6 · convergence factor per step ≈ 0.741 (= |λ₂|) · 3000-step path spends (0.659, 0.262, 0.079) of its time in each state
Solid lines: the probability of each terrain t steps after starting in the chosen one. Dashed: the stationary distribution π, which solves πP = π. The start is forgotten geometrically fast, at the rate of the second-largest eigenvalue |λ₂|. Make the chain "sticky" (small off-diagonals) and |λ₂| → 1: slow mixing. Set every way out of a state to 0 and it becomes absorbing: π puts all its mass there.
Why engineers care

A rover’s terrain type, a machine’s health state (OK / degraded / failed), a user’s next click, a robot’s next grid cell. All are modelled as Markov chains. Reinforcement learning, speech recognition, Google’s PageRank and the MCMC samplers behind Bayesian inference are all Markov chains underneath.

📝 Quick check (Level 0)
0/3 answered
  1. 1. In a Markov chain, the next state depends on…
  2. 2. After a long time, the fraction of time in each state…
  3. 3. Does the long-run fraction depend on the starting state (for a well-connected chain)?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Transition matrices

A chain on states {1,…,n}\{1, \dots, n\} is defined by Pij=P(Xt+1=j∣Xt=i)P_{ij} = P(X_{t+1} = j\mid X_t = i). Each row is a probability distribution, so Pij≥0P_{ij}\ge0 and ∑jPij=1\sum_jP_{ij} = 1. This is a stochastic matrix.

  • Distributions move by right-multiplication: if ptp_t is the row vector of P(Xt=i)P(X_t = i), then pt+1=ptPp_{t+1} = p_tP and pt=p0Ptp_t = p_0P^t.
  • Chapman–Kolmogorov: Pm+n=PmPnP^{m+n} = P^mP^n, so (Pt)ij(P^t)_{ij} is the tt-step transition probability.

Stationary distributions

π\pi is stationary if πP=π\pi P = \pi: start there and you stay there in distribution. It’s a left eigenvector with eigenvalue 1. For two states with P=(1−aab1−b)P = \begin{pmatrix}1-a & a\\ b & 1-b\end{pmatrix}, π=(b,a)a+b\pi = \frac{(b, a)}{a + b}.

📝 Quick check (Level 1)
0/3 answered
  1. 1. Each row of a transition matrix sums to…
  2. 2. The distribution after t steps is…
  3. 3. For a = 0.3, b = 0.1, π equals…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

When does the chain forget its start?

  • Irreducible: every state can reach every other.
  • Aperiodic: returns to a state aren’t forced onto a fixed rhythm. For example, a chain that alternates 1, 2, 1, 2 has period 2. A self-loop (Pii>0P_{ii} > 0) is enough to break periodicity.

Convergence theorem. A finite, irreducible, aperiodic chain has a unique π\pi with all πi>0\pi_i > 0, and p0Pt→πp_0P^t\to\pi for every p0p_0. The error shrinks geometrically, roughly like ∣λ2∣t\lvert\lambda_2\rvert^t, where λ2\lambda_2 is the second-largest eigenvalue in modulus. The spectral gap 1−∣λ2∣1 - \lvert\lambda_2\rvert sets the mixing speed.

Ergodic theorem. For an irreducible chain, the fraction of time spent in state ii converges a.s. to πi\pi_i, and 1T∑f(Xt)→∑iπif(i)\frac1T\sum f(X_t)\to\sum_i\pi_if(i). This is the law of large numbers for dependent samples (A4.3-4).

Absorbing chains

If some states are absorbing (Pii=1P_{ii} = 1), order the states transient first: P=(QR0I)P = \begin{pmatrix}Q & R\\ 0 & I\end{pmatrix}. The fundamental matrix N=(I−Q)−1N = (I - Q)^{-1} gives the expected visits. The expected time to absorption is N1N\mathbf 1, and the absorption probabilities are NRNR. That answers “how long until the rover reaches the dock, and how likely is it to fall off the cliff first?”

🐍 Exercise 1: stationary distribution, convergence and the ergodic theorem
Solve πP = π for a 3-state chain, show that TV(p₀Pᵗ, π) → 0 at a rate set by |λ₂|, check that a simulated path's occupation frequencies match π, and see that a periodic chain never converges.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Mixing speed is governed by…
  2. 2. A chain alternating 1 → 2 → 1 → 2 is…
  3. 3. The expected time to absorption is…

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Why the convergence theorem holds (coupling sketch)

Run two copies of the chain: XtX_t started at p0p_0 and YtY_t started at π\pi, independently until they first meet, then together.

  1. Coupling inequality. Since Yt∼πY_t\sim\pi for all tt, ∥pt−π∥TV≤P(Xt≠Yt)=P(τ>t)\lVert p_t - \pi\rVert_{TV}\le P(X_t\ne Y_t) = P(\tau > t), where τ\tau is the meeting time.
  2. The meeting time is finite. Irreducibility and aperiodicity give some mm with (Pm)ij≥δ>0(P^m)_{ij}\ge\delta > 0 for all i,ji, j. So in every block of mm steps the copies meet with probability at least δ\delta.
  3. Geometric decay. Hence P(τ>km)≤(1−δ)k→0P(\tau > km)\le(1 - \delta)^k\to0. ∎

Detailed balance and reversibility

If πiPij=πjPji\pi_iP_{ij} = \pi_jP_{ji} for all i,ji, j (detailed balance), then summing over ii gives πP=π\pi P = \pi. Such chains are reversible: run backwards they look the same. Birth–death chains always are, which gives πi+1/πi=pup/pdown\pi_{i+1}/\pi_i = p_{\text{up}}/p_{\text{down}}.

Metropolis–Hastings builds a reversible chain for any target π\pi: propose jj from q(i,⋅)q(i, \cdot), then accept with probability min⁡(1,πjq(j,i)πiq(i,j))\min\big(1, \frac{\pi_jq(j,i)}{\pi_iq(i,j)}\big). Only ratios of π\pi are needed, so normalizing constants cancel. That’s why MCMC can sample posteriors (Metropolis et al., 1953; Hastings, 1970).

Exercise 3.1: Show that detailed balance implies stationarity

(πP)j=∑iπiPij=∑iπjPji=πj∑iPji=πj(\pi P)_j = \sum_i\pi_iP_{ij} = \sum_i\pi_jP_{ji} = \pi_j\sum_iP_{ji} = \pi_j.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The coupling inequality bounds TV distance by…
  2. 2. Metropolis–Hastings needs π only up to…
  3. 3. Detailed balance means…

Level 4: Expert

★★★★★ Expert⏱ 45 minResearchers: original papers and open problems.

Sampling a multimodal belief with MCMC

A robot’s belief over 40 corridor cells has two bumps: it’s probably near cell 10 or cell 28. A lazy random-walk Metropolis chain samples it exactly in the long run, by detailed balance. But the low-probability valley between the bumps acts as a bottleneck. The chain takes about 7× longer to mix than on a flat target. That’s the central practical problem of MCMC (and of exploration in RL), and the motivation for tempering, Hamiltonian Monte Carlo and teleporting moves. Google’s PageRank is the stationary distribution of a “random surfer” chain made irreducible and fast-mixing by teleporting with probability 0.15 (Brin and Page, 1998).

🐍 Exercise 2 (research): MCMC mixing on a two-mode belief, and teleportation
Build a lazy Metropolis chain for a two-mode belief over 40 cells. Verify detailed balance and stationarity, and compute the mixing time (max TV ≤ 1/4) compared with a flat target. Then show that a PageRank-style teleporting chain on a random graph mixes in a handful of steps.

Markov chains in AI, robotics and aerospace

  • MDPs and RL. A policy turns an MDP into a Markov chain. Its stationary distribution weights the average-reward objective and on-policy learning (Puterman, 1994; Sutton and Barto, 2018).
  • Hidden Markov models. The state is a Markov chain observed through noise. The forward algorithm and Viterbi decoding power speech recognition, gesture recognition and terrain classification (Rabiner, 1989).
  • Reliability and health management. Degradation is modelled as chains OK → degraded → failed, with absorbing failure states. The fundamental matrix gives the mean time to failure for spacecraft subsystems.
  • MCMC for Bayesian inference (Gelman et al., 2013). Convergence diagnostics such as R-hat and effective sample size exist because mixing can be slow.
  • Multi-model filters (IMM) model the switching between motion regimes as a Markov chain (Blom and Bar-Shalom, 1988; A4.2-6).

References

  1. D. Levin, Y. Peres (2017). Markov Chains and Mixing Times, 2nd ed. AMS.
  2. J. Norris (1997). Markov Chains. Cambridge University Press.
  3. A. A. Markov (1906). “Extension of the law of large numbers to dependent quantities.” Izv. Fiz.-Matem. Obsch. Kazan Univ., 15.
  4. N. Metropolis, A. Rosenbluth, M. Rosenbluth, A. Teller, E. Teller (1953). “Equation of state calculations by fast computing machines.” Journal of Chemical Physics, 21(6).
  5. W. K. Hastings (1970). “Monte Carlo sampling methods using Markov chains and their applications.” Biometrika, 57(1).
  6. S. Brin, L. Page (1998). “The anatomy of a large-scale hypertextual web search engine.” Computer Networks, 30.
  7. L. Rabiner (1989). “A tutorial on hidden Markov models and selected applications in speech recognition.” Proceedings of the IEEE, 77(2).
  8. M. Puterman (1994). Markov Decision Processes. Wiley.
  9. A. Gelman et al. (2013). Bayesian Data Analysis, 3rd ed. CRC Press.
  10. J. Kemeny, J. L. Snell (1976). Finite Markov Chains. Springer.