Skip to content
mlmentorship

Markov chains

Stochastic processes where the future depends only on the present, not the past. Foundation of HMMs, MCMC, and many sequence models.

Published · 7 min read ·Core ·Foundation
Reading depth

Summary

A Markov state retains the information needed to specify the next-state law without consulting older history. For finite states with row-stochastic transition matrix , row-vector marginals evolve as .

Use : each row is nonnegative and sums to one. For the illustrated teaching chain,

Right multiplication gives , , and . Every update preserves total mass, but these finite-time distributions still depend on the initial state.

Stationary distribution

A stationary distribution satisfies , a fixed-point condition rather than a promise of convergence. Every finite row-stochastic matrix has at least one stationary distribution. Finite irreducibility makes it unique; adding aperiodicity ensures convergence from every initial distribution:

For the fixture, and give . Writing yields . Thus for this start, explicitly showing contraction. Nontrivial eigenvalue magnitudes govern asymptotic contraction for finite irreducible reversible chains. Bounds also depend on the starting distribution; a positive absolute spectral gap excludes periodic oscillation.

Detailed balance and reversibility

A chain is reversible if there is a such that

Summing the balance equality over gives . Detailed balance therefore implies stationarity, but stationarity does not imply detailed balance. The fixture’s two cross-flows both equal . Metropolis-Hastings can construct a target-invariant reversible chain; valid convergence still requires additional conditions.

Learning objective

Balanced probability flow preserves the distribution while transitions continue

Balanced flow preserves the distribution, not the stateFor transition matrix [[.8,.2],[.4,.6]], stationary probabilities are 2/3 and 1/3. The weighted flows in opposite directions both equal 2/15, even though their transition probabilities differ.Unequal reservoirs exchange equalmass flowsAmass 2/3Bmass 1/3A sends 0.2 of its mass; B sends 0.4Each direction transfers 2/15 perstep.The distribution stays; individualstates still move.
Derivation

Mass moves toward 2/3 in A and 1/3 in B; at stationarity the two cross-flows balance.

Two-state Markov chain probability mass converges to a stationary distributionFour stacked bars show the marginal distribution moving from all A to point eight A, then point seven two A, then the stationary two-thirds A and one-third B split. A state diagram beside it shows equal detailed-balance flows of two fifteenths in both directions.Repeated transitions move the marginalrow vector update: mu(t+1) = mu(t) Ptimestate A massstate B massmu01.000 Amu10.8000.200mu20.7200.280pi2/3 A1/3 Bpi P = pi: the split stops changingAt stationarity, flows balancetransition matrix P = [[0.8, 0.2], [0.4, 0.6]]ApiA = 2/3BpiB = 1/3A to B: (2/3)(0.2) = 2/15B to A: (1/3)(0.4) = 2/15self-loops keep remaining mass in place
Read it this way: the bars are the distribution before each transition, not rows of the transition matrix. Repeated multiplication moves mass toward the stationary split. At pi, equal cross-flows leave both state masses unchanged. Original schematic checked against Levin and Peres and the Berkeley Data 140 textbook.
Check: Why does the distribution stay at (2/3,1/3) even while individual transitions continue?
Read it this way: For transition matrix [[.8,.2],[.4,.6]], stationary probabilities are 2/3 and 1/3. The weighted flows in opposite directions both equal 2/15, even though their transition probabilities differ.
Can the stationary distribution stay fixed while individual states continue moving?

Change the Requirement

Remove Holding Probabilities

New task: Replace the fixture matrix with .

Picture and change: Mass alternates between states instead of contracting.

Check: is the unique stationary distribution, but starting at A gives alternating point masses forever.

Use when: Transition structure can create periodicity; uniqueness alone is insufficient for marginal convergence.

Higher-order chains

New task: Let the next-state probability depend on the previous state as well as the current state.

Picture and change: Use ordered pairs as states, preserving the history that changes transition probabilities.

Check: From (A,B), move to (B,A) with probability and (B,B) with . From (B,B), let those probabilities be and instead; a current-token-only B cannot represent both rows.

Use when: A specified older observation still changes the next-state law. A -order token chain becomes first-order over -tuples, potentially increasing the state space substantially.

Common cases in ML

Use caseChosen state or transition
HMMHidden state, not generally the observed symbol alone
MCMCSampler state with a declared invariant target
PageRankRandom walk with specified graph and teleportation conventions
DiffusionNoise-level-dependent transitions; include time when needed
MDP/RLEnvironment state and action-conditioned transition
Language modelFull retained prefix/context, not generally one token

Common pitfalls

  • Insufficient state. Test whether older observed information still changes the specified conditional law.
  • Premature sampler claims. Multiple chains, effective sample size, and convergence diagnostics identify concerns, not universal proof of convergence.
  • Mixed conventions. Row-stochastic and column-stochastic matrices act on different sides of their marginal vectors.
  • Stationarity versus limits. A fixed point need not attract every start; infinite-state chains need additional recurrence conditions.

Reconstruct

Must stationary flow balance separately on every edge?

No. Consider three states, each staying with probability one-half or moving clockwise with probability one-half. Uniform mass is stationary, yet clockwise pair flow is and reverse flow is zero. Net flow into each state balances without reversibility.