determin.ant
06-eigenvalues / 6.6

Module 6: Eigenvalues

Markov Chains

Where you'll see this: PageRank is a Markov chain over the web graph. Text auto-complete uses a Markov model over words. Reinforcement learning formalizes the environment as a Markov Decision Process. Hidden Markov Models underlie speech recognition. Markov chains are everywhere probabilistic systems evolve over time.

Markov chains are one of the most beautiful applications of eigenvalues. The long-run behavior of any Markov chain is determined by a single eigenvector.

What is a Markov chain?

A Markov chain is a system that jumps between states over time. The key property: the next state depends only on the current state, not on the history.

The transitions are captured in a transition matrix T, where T[i,j] is the probability of going from state j to state i. Each column sums to 1.

Evolution over time

If the current distribution over states is a vector π, the distribution after one step is TπT\boldsymbol{\pi}. After k steps: TkπT^k \boldsymbol{\pi}.

The stationary distribution

As k → ∞, the distribution converges to a fixed point π\boldsymbol{\pi}^* where:

Tπ=πT\boldsymbol{\pi}^* = \boldsymbol{\pi}^*

This is exactly an eigenvector equation with eigenvalue 1. The stationary distribution is the eigenvector of T corresponding to λ = 1. Every column-stochastic matrix has exactly one such eigenvector (under mild conditions).

The stationary distribution is an eigenvector. The long-run behavior of any Markov chain is determined by the eigenvector of T with eigenvalue 1. All other eigenvalues have |λ| ≤ 1 — they decay away.

Speed of convergence

The second eigenvalue |λ₂| controls how fast the chain mixes. If |λ₂| is close to 1, convergence is slow (nearly reducible states). If |λ₂| is small, convergence is fast.

Try it

Set the transition probabilities and initial distribution. The bars show the distribution at each step converging toward the stationary distribution (dashed). "Slow mixing" has a large second eigenvalue — notice how many more steps it takes.

In NumPy:
import numpy as np

T = np.array([[0.9, 0.2], [0.1, 0.8]])  # transition matrix (columns sum to 1)

# Stationary distribution = eigenvector with eigenvalue 1
eigenvalues, eigenvectors = np.linalg.eig(T)
idx = np.argmin(np.abs(eigenvalues - 1))
stationary = eigenvectors[:, idx]
stationary /= stationary.sum()  # normalize
print(stationary)  # [0.667, 0.333]

# Or: iterate until convergence
pi = np.array([0.5, 0.5])
for _ in range(100):
    pi = T @ pi
print(pi)  # same result
Positive Definite MatricesDot Product
Transition matrix T
→A→Bfrom Afrom B
Initial distribution
Step 0Step 15
0
0.9
1
0.82
2
0.76
3
0.72
4
0.7
5
0.68
6
0.66
7
0.66
8
0.65
9
0.64
10
0.64
11
0.64
12
0.64
13
0.64
14
0.64
15
0.63
0.5

State A   State B   The dashed bar is the stationary distribution (the eigenvector with λ=1).