Markov Chain Simulator: Transition Probabilities & Steady-State Convergence

simulator intermediate ~10 min
Loading simulation...
π = [0.45, 0.27, 0.27] — equilibrium in ~8 steps

With default transition probabilities, the 3-state chain converges to steady state π ≈ [0.45, 0.27, 0.27] within about 8 steps.

Formula

πP = π (stationary distribution equation)
Σπᵢ = 1 (probability normalization)
P(Xₙ₊₁ = j | Xₙ = i) = pᵢⱼ (Markov property)

Memory-Free Randomness

A Markov chain is a random walk through states where each step depends only on where you are now, not how you got there. This 'memoryless' property — formalized by Andrey Markov in 1906 while studying vowel-consonant patterns in Pushkin's poetry — makes the math tractable and the applications vast. From PageRank to protein folding, Markov chains model systems where history compresses into the current state.

Transition Probabilities and the Matrix

The chain's behavior is fully encoded in its transition matrix P, where pᵢⱼ gives the probability of moving from state i to state j. Each row sums to 1. This simulation shows a 3-state chain with adjustable transitions — you control the arrows between states and watch how changing a single probability reshapes the entire long-run behavior. The matrix power Pⁿ converges to a rank-1 matrix whose rows are all the stationary distribution π.

Convergence to Steady State

Start the chain in any state and run it forward: after enough steps, the probability distribution over states stabilizes at π, the stationary distribution satisfying πP = π. The convergence plot shows this process — initial transients decay exponentially, with the rate controlled by the second-largest eigenvalue of P. Faster mixing (smaller second eigenvalue) means faster convergence, which is critical for MCMC sampling algorithms.

From Chains to Algorithms

Markov Chain Monte Carlo (MCMC) reverses the usual question: instead of analyzing a given chain, you design a chain whose stationary distribution equals your target distribution. The Metropolis-Hastings algorithm constructs such chains for arbitrary distributions, enabling Bayesian inference in complex models. This simulation builds intuition for how transition structure determines equilibrium — the same intuition that guides MCMC algorithm design.

FAQ

What is a Markov chain?

A Markov chain is a stochastic process where the future state depends only on the present state, not the history — the 'memoryless' property. Named after Andrey Markov (1906), it models random transitions between discrete states and is foundational to queuing theory, genetics, speech recognition, and Google's PageRank algorithm.

What is a stationary distribution?

The stationary (steady-state) distribution π satisfies πP = π, where P is the transition matrix. For an irreducible, aperiodic chain, π is unique and represents the long-run fraction of time spent in each state, regardless of the starting state.

What is mixing time?

Mixing time is the number of steps until the chain's distribution is close to steady state. Fast mixing is essential for MCMC algorithms — if the chain mixes slowly, samples are highly correlated and the algorithm needs exponentially more iterations to explore the state space.

How are Markov chains used in practice?

Markov chains model customer behavior in marketing, protein folding in bioinformatics, weather transitions in meteorology, text generation in NLP, and queueing systems in service operations. MCMC methods (Metropolis-Hastings, Gibbs sampling) use Markov chains as the backbone of Bayesian inference.

Sources

Embed

<iframe src="https://homo-deus.com/lab/operations-research/markov-chain/embed" width="100%" height="400" frameborder="0"></iframe>
View source on GitHub