Markov Chains

A system that forgets everything except where it is now. Start it anywhere and it settles in the same place.

Markov Chains

This module needs JavaScript: the numbers are computed in the page rather than recorded.

Worth knowing

The Markov property: the next state depends only on the current one, not on how you arrived.
A transition matrix holds the probabilities. Each row sums to 1, because you must go somewhere.
Iterating it converges to a stationary distribution — the eigenvector of P' with eigenvalue 1.
Change the starting state and the curves start in different places and arrive at the same one. That is the point.

Overview

Transition probabilities

A chain has a state space and transition probabilities. With a row-vector convention, a transition matrix P has entries Pᵢⱼ = P(next state = j | current state = i); each row sums to 1. If πₜ is the row vector of state probabilities at time t, then πₜ₊₁ = πₜP.

For two states, sunny and rainy, a matrix such as [[0.8, 0.2], [0.4, 0.6]] says that a sunny day is followed by a sunny day with probability 0.8, while a rainy day is followed by a sunny day with probability 0.4. Starting from π₀ = [1, 0], after one step π₁ = [0.8, 0.2].

In this guide
  1. The Markov assumption and long-run behavior
  2. Multiply the transition matrix step by step
  3. Try this above
  4. Sources and next steps

Markov Chains

A Markov chain models step-by-step movement between states when the next state depends on the current one.

The Markov assumption and long-run behavior

The Markov property says the next state is conditionally independent of earlier history once the current state is known. It is a modelling assumption; if relevant history is omitted, the model may be inadequate.

A stationary distribution satisfies π = πP. Some chains converge to one from many starting states, but convergence is not automatic: reducible or periodic chains can behave differently. See conditional probability for transition probabilities and matrix multiplication for repeated transitions.

Multiply the transition matrix step by step

From the sunny starting state π₀=[1,0] and P=[[0.8,0.2],[0.4,0.6]], one step gives π₁=[0.8,0.2]. A second step is π₂=π₁P=[0.72,0.28]. Each row of P is a probability distribution for the next state given the current state, so rows sum to one. This uses a row-vector convention; with column vectors, the matrix and multiplication order are transposed. State the convention before calculating.

The Markov property says that once the present state is known, earlier states add no information about the next step. It does not say transitions are independent across time. A stationary distribution solves π=πP and describes a distribution unchanged by one transition. For this example, π=[2/3,1/3] is stationary. A finite chain may have a unique stationary distribution yet fail to converge from every start if it is periodic. If an omitted variable such as season affects transitions, include it in the state or accept that the simple chain may predict poorly. Markov models are useful for repeated state transitions, not for every time series.

Try this above

Change one transition probability and keep each row normalised. Track how the state distribution evolves over several steps and whether it settles.

The long-run distribution can be found by solving π=πP along with the condition that probabilities sum to one. For the sunny/rainy matrix, solving gives π=[2/3,1/3]. Starting at that distribution leaves it unchanged at every step. A stationary distribution is not automatically the fraction of time observed in a short sequence; convergence requires additional conditions such as irreducibility and aperiodicity. Weather is only an illustration: real forecasting may need season, location, or trends represented in the state.

Sources and next steps

Check yourself

0 of 3

Answer without scrolling back up.

  1. What does the Markov property say?

  2. What is the stationary distribution?

  3. What does MCMC do with this idea?

Cheat sheet

Markov Chains

Step through a Markov chain and watch the state distribution converge to steady state. See why MCMC sampling and PageRank are both examples.

MATHS · vizlearn.in/maths/markov_chains.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.

Teaching a course with this? Individual teachers can use it freely; for a whole department or programme, see institutional licences.