Hexa Scholar

Markov chains: watching probability flow

A green frog leaps rightward from the left one of three lily pads on a dark pond; the other two pads are empty.
A frog hops between three lily pads, like the walker on this page moving between three states.

The question

A walker hops between three states by fixed odds. After 20 steps, which state is it most likely to be in?

Stage 1 asks for your pick before any step is taken.

  1. 1 SeePick the likeliest state at step 20.
  2. 2 TryTwo steps, the long run, then steer a chain.
  3. 3 ProveBuild the proof, line by line.
  4. 4 ApplyCommutes, credit ratings and a machine.
Before you start · 3 quick checks on a matrix product, the multiplication rule and a PMF, about 3 min

Two ideas before you start

2 ideas

The arrows out of a state carry its odds

Figure: a chain with the states A, B and C in a row; the arrows out of the chosen state are drawn bold, with their probabilities. It needs JavaScript.

From

Row A of P: 0.6 + 0.4 + 0 = 1

At each step the walker leaves its state along one arrow, with the probability on that arrow. The arrows out of a state add up to 1, and they form that state's row of the transition matrix P.

Exact definition

Markov chain. A Markov chain on the states \(1, \dots, N\) (on this page often A, B and C) is a sequence of random variables \(X_{0}, X_{1}, X_{2}, \dots\), where \(X_{n}\) is the state at step \(n\). Its transition matrix \(P\) has the entries \(p_{ij}\), the probability of a move from \(i\) to \(j\) in one step. Every \(p_{ij} \ge 0\), and every row adds up to 1: \(\sum_{j} p_{ij} = 1\) for each state \(i\). The same \(P\) is used at every step.

The distribution at step \(n\) is the row vector \(\pi_{n} = (P(X_{n} = 1), \dots, P(X_{n} = N))\); its entries add up to 1. We also write \(\pi_{n}(j) = P(X_{n} = j)\). The row \(\pi_{0}\) is the initial distribution.

Only the current state matters

Figure: the same chain; the arrow from the chosen state into B is dashed, and the arrows out of B are drawn bold. It needs JavaScript.

X₀ =

X₀ = A, X₁ = B. Next step: A 0.2 B 0.5 C 0.3

The walker is at B at step 1. Wherever it was at step 0, its next step uses the arrows out of B. This is the Markov property.

Exact definition

Markov property. For every \(n \ge 0\) and all states \(i_{0}, \dots, i_{n-1}, i, j\) with \(P(X_{0} = i_{0}, \dots, X_{n-1} = i_{n-1}, X_{n} = i) \gt 0\),

\[\begin{aligned} &P(X_{n+1} = j \mid X_{n} = i, \\ &\qquad X_{n-1} = i_{n-1}, \dots, X_{0} = i_{0}) \\ &= p_{ij}. \end{aligned}\]

Once \(X_{n}\) is known, the earlier states change nothing about the next one. In particular, \(P(X_{n+1} = j \mid X_{n} = i) = p_{ij}\) whenever \(P(X_{n} = i) \gt 0\). The lesson on conditional probability defines \(P(A \mid B)\).

Fine print: rows, columns and time

This page writes a distribution as a row and multiplies it on the left of \(P\), the usual convention for Markov chains. Some books write the distribution as a column and use the transpose of \(P\); the numbers are the same. Every chain here has finitely many states, and its \(P\) does not change from step to step.

1 See

Where will the walker most likely be at step 20?

Your pick for step 20:

2 Try

Two steps, and many steps

Two questions first: one applies the rule from stage 1, one asks for a prediction. The explorer below them opens once both are answered.

The explorer opens when you have answered the two questions above.

3 Prove

Why n steps multiply by P to the n

Theorem

Assumptions. Let \(X_{0}, X_{1}, X_{2}, \dots\) be a Markov chain on \(N \ge 2\) states with transition matrix \(P\): every \(p_{ij} \ge 0\), every row adds up to 1, and the Markov property of the setup holds with the same \(P\) at every step. For every \(n \ge 0\), \(\pi_{n}\) is the row \((P(X_{n} = 1), \dots, P(X_{n} = N))\). As usual, \(P^{0} = I\) and \(P^{n+1} = P^{n}P\).

Conclusion. For every \(n \ge 0\),

\[\pi_{n} = \pi_{0}P^{n},\]

and for all states \(i\) and \(j\) with \(P(X_{0} = i) \gt 0\),

\[P(X_{n} = j \mid X_{0} = i) = (P^{n})_{ij}.\]

Facts the proof uses.

  • the law of total probability, from the lesson on conditional probability;
  • matrix products may be regrouped, \((AB)C = A(BC)\), from the lesson on matrix multiplication;
  • given \(X_{0} = i\), with \(P(X_{0} = i) \gt 0\), the sequence \(X_{0}, X_{1}, \dots\) is again a Markov chain with the same \(P\), started at \(i\).

Each option is one sentence about the chain of the theorem. Pick the one that is true for every chain the theorem covers: any \(N \ge 2\), any \(P\) and any initial distribution \(\pi_{0}\).

What else follows
  • Paths. For \(n \ge 1\), writing out the product \(P^{n}\) entry by entry, \((P^{n})_{ij}\) is the sum of \(p_{ik_{1}}\,p_{k_{1}k_{2}} \cdots p_{k_{n-1}j}\) over all paths \(i \to k_{1} \to \dots \to k_{n-1} \to j\) of \(n\) steps. For \(n = 0\), \((P^{0})_{ij}\) is 1 when \(j = i\) and 0 otherwise.
  • Split a trip. For all \(m, n \ge 0\), \(P^{m+n} = P^{m}P^{n}\), so whenever \(P(X_{0} = i) \gt 0\), \[\begin{aligned} &P(X_{m+n} = j \mid X_{0} = i) \\ &= \sum_{k} (P^{m})_{ik}\,(P^{n})_{kj}: \end{aligned}\] add over the state \(k\) at step \(m\). These are the Chapman–Kolmogorov equations.
  • Rows of \(P^{n}\). Each row of \(P^{n}\) is a distribution: its entries are at least 0 and add up to 1.
  • Distributions that stay put. If \(\pi_{0}P = \pi_{0}\), then \(\pi_{n} = \pi_{0}\) for every \(n\). Such a distribution is called stationary. Which chains have one, and when \(\pi_{n}\) approaches it, is the subject of a later lesson.
4 Apply

Problems

Each problem states its model and has hints and a full solution. Exact answers can be typed as decimals or as fractions.

Key point For one path, multiply the probabilities along its arrows. For the probability of being at \(j\) after \(n\) steps from \(i\), add over all paths: it is \((P^{n})_{ij}\). When the start is spread out over the states, it is entry \(j\) of the row \(\pi_{0}P^{n}\). Each answer describes the model, and holds for the real process only as far as its next state depends on the current one alone, by fixed odds.
Level Intro Prerequisites matrix multiplication (the lesson on matrix multiplication), conditional probability (the lesson on conditional probability) Time ~35 min

Further reading