Markov chains §
A Markov chain is a stochastic process with the Markov property: given the present state, the future is independent of the past. It is the workhorse model for any system whose next state is a probabilistic function of the current one only — queues, web search ranking, genetic sequences, weather, MCMC sampling, and reinforcement learning.
When it is relevant. Use a Markov chain whenever you can (or want to assume) that the history of a process is summarized by its current state. If the next step depends on how long the system has been in its current state, a plain Markov chain is not enough and you must enlarge the state space (or use a semi-Markov / continuous-time model).
Terminology, precisely. “Markov chain” is usually reserved for discrete time . The continuous-time version is a continuous-time Markov chain (see Poisson processes, whose exponential clocks drive the jumps). The state space may be discrete or continuous:
- Discrete state space — the chain is described by a transition matrix (this page).
- Continuous state space — there is no matrix; the chain is described by a transition kernel , a function of the current point and a set .
Everything below is for the discrete-time, discrete-state case, where the matrix is the central object.
Builds on Random variables and expectation and Conditional probability; hitting-time estimates are a martingale application.
Brief history §
- Markov (1906) — On the theory of probabilities introduced chains and proved convergence to a stationary distribution.
- Ehrenfest (1911) — the urn model applied chains to gas diffusion, the first physical use.
- Chapman & Kolmogorov (1931) — the Chapman–Kolmogorov equations for multi-step transitions.
- Perron–Frobenius / modern ergodic theory — spectral tools that give existence, uniqueness, and the rate of convergence to stationarity.
1. The Markov property and definition §
Definition. A stochastic process on a state space is a Markov chain if, for all states ,
The whole future is pinned down by the present state . By the chain rule of conditional probability, the joint law of a whole trajectory factorizes:
This is the single most useful identity: a long, complicated path probability collapses into one initial probability times a product of one-step probabilities.
Details
Why the property is powerful. Without the Markov property, the probability of a path of length would require conditioning on the entire history — an object that grows with . The Markov property says that conditioning on the history is redundant: the last state already carries all the information the future needs. That is what makes chains computable and simulable.
Concrete example: a weather chain. Let . Suppose
- if today is Sunny, tomorrow is Sunny with probability and Rainy with ;
- if today is Rainy, tomorrow is Sunny with probability and Rainy with .
The Markov assumption is that “tomorrow’s weather depends on today’s weather, not on the whole week so far.” The probability of the specific 3-day path Sunny → Sunny → Rainy is
one initial probability times two one-step factors — no need to remember the day before.
The simulation above runs a 4-state chain. Each Step applies one transition; the bar chart tracks how often each state has been visited, and you can watch those empirical frequencies settle onto the theoretical stationary distribution (Section 3).
Authoritative sources.
Authoritative sources
Example problem.
Problem
A chain has states with , . Starting from , compute .
Solution
Apply the factorization:
The initial state is fixed at (probability ), so only the two one-step factors matter.
2. Transition matrix and Chapman–Kolmogorov equations §
Definition. For a discrete state space , the transition matrix has entries
so each row sums to ( is row-stochastic). The -step transition probabilities are the matrix power :
The Chapman–Kolmogorov equations say that an -step move equals an -step move followed by an -step move, summed over the intermediate state:
Details
Reading the matrix. is the probability of leaving and arriving at in one step. Because from state you must go somewhere, . A diagonal entry is the probability of staying put.
Why works. The entry of is : go from to some intermediate , then from to . This is exactly the Chapman–Kolmogorov equation with , and it is just the chain rule of conditional probability plus the law of total probability. Matrix multiplication is doing the “sum over the forgotten intermediate state” for you.
Concrete example. Take the weather chain of Section 1, with and
The probability of being Rainy two days from now, given it is Sunny today, is :
The intermediate day is Sunny with probability (contributing ) or Rainy with probability (contributing ).
Authoritative sources.
Authoritative sources
Example problem.
Problem
With the weather matrix above, compute the full matrix .
Solution
Each row still sums to — is also a transition matrix, as it must be.
3. Stationary distributions and ergodicity §
Definition. A probability vector (so , ) is a stationary distribution if
If the chain is irreducible and aperiodic (Section 4), then exists, is unique, and the chain converges to it from any starting state:
i.e. every row of tends to . This is the ergodic theorem for finite Markov chains.
Details
What “stationary” means. If the chain starts in — that is, — then it stays in forever: . The distribution is a fixed point of the update rule.
Existence and uniqueness. For a finite chain, irreducibility (every state reachable from every other) guarantees that a stationary distribution exists and is unique. Aperiodicity (no deterministic “clock” forcing returns to a fixed rhythm) guarantees that the chain actually converges to it rather than oscillating. The rate of convergence is governed by the second-largest eigenvalue of in magnitude — the Perron–Frobenius theory.
Concrete example. For the weather chain, solve with :
From the first equation, , so . With this gives and . So in the long run it is Sunny about of the time. You can verify in the simulation that the empirical bars settle near the theoretical .
Authoritative sources.
Authoritative sources
Example problem.
Problem
A 3-state chain has transition matrix
Find the stationary distribution .
Solution
Solve with :
All three are equal, so .
4. Classification of states §
Definition. For a state , let be the probability that the chain, starting from , ever returns to .
- Recurrent if (you come back with probability ); transient if (there is a real chance you never return).
- The chain is irreducible if every state can be reached from every other state.
- The period of is ; the state is aperiodic if .
Details
Recurrent vs transient, intuitively. A recurrent state is one you are doomed to revisit; a transient state is one you may visit a few times and then abandon forever. In a finite chain, irreducibility forces every state to be recurrent (you cannot “escape to infinity” when there are only finitely many states). Transience only appears in infinite chains, e.g. the simple random walk on is transient.
The return-probability criterion. The cleanest test is : compute the probability of ever returning to after leaving it. If it is , the state is recurrent; otherwise transient. Equivalently, a state is recurrent iff the expected number of visits to it (starting from itself) is infinite.
Periodicity, intuitively. A state with period can only be revisited at times that are multiples of — the chain is trapped on a -cycle. Example: a chain that alternates deterministically between two states has period . Aperiodicity ( ) is what lets the chain “forget its phase” and converge to a single stationary distribution; a periodic chain instead oscillates. A single self-loop ( ) is the easiest way to guarantee aperiodicity.
Concrete example. Consider a 3-state chain where and happen with probability , and state is reachable from but never returns. Then is transient (once you leave you never come back, and you can even fail to reach it), while form a closed, period- class.
Authoritative sources.
Authoritative sources
Example problem.
Problem
A chain has states with , , , . Classify each state and give the period of state .
Solution
From you can jump to (and then wander in ) or stay at ; but from you can never reach . So is transient (you may leave it and never return), while and are recurrent (closed class). State is revisited only at even times ( ), so its period is .
5. Hitting times and expected hitting times §
Definition. For a set of states , the hitting time is . The expected hitting time from state is . It satisfies the linear system
Details
Why the linear system. If you have already arrived, so . If , you spend one step (the leading ) and then, having moved to with probability , still need more steps on average. Taking expectation over the next state gives . This is a system of linear equations in the unknowns for , and it has a unique solution whenever is reachable from every state.
Gambler’s ruin — the canonical example. A gambler with dollars bets dollar at a time, winning with probability and losing with probability , until reaching (broke) or (goal). The states are with , . The expected duration solves with . For the fair game the solution is the parabola .
Connection to martingales. The fair gambler’s fortune is a martingale; the optional stopping theorem gives the probability of reaching before in one line, while the hitting-time duration above comes from the squared fortune, which is a submartingale.
Authoritative sources.
Authoritative sources
Example problem.
Problem
A fair gambler starts with dollars and plays until reaching or . What is the expected number of bets?
Solution
Here , , and the fair-game formula gives bets on average.
6. Applications §
Definition. Markov chains are the engine behind a wide range of models and algorithms; the unifying idea is always “the next state is a probabilistic function of the current one.”
Details
- PageRank. The web is a directed graph; a “random surfer” who follows links at random is a Markov chain on pages. PageRank is its stationary distribution (with a damping factor to keep the chain irreducible and aperiodic). The most important pages are the ones the surfer occupies most often in the long run.
- MCMC (Metropolis–Hastings). To sample from a hard-to-normalize target distribution, one builds a Markov chain whose stationary distribution is exactly the target, runs it, and reads off samples. Ergodicity (Section 3) guarantees the samples converge to the target.
- Ehrenfest urn. Two urns exchange one of particles at random each step — the 1911 model of gas diffusion. It is a birth–death chain whose stationary distribution is binomial, and it is the discrete precursor of Brownian motion.
- Queues. The number of customers in a queue evolves as a Markov chain (a birth–death process); its stationary distribution gives the long-run occupancy and waiting times.
Authoritative sources.
Authoritative sources
Quizz §
Try it yourself
A 3-state chain has transition matrix
(a) Find the stationary distribution . (b) Starting from state , find the expected hitting time of state .
Solution
(a) Solve with :
So , , .
(b) Let . Then and
From the first: . From the second: . Substituting: steps.