Many real-world systems evolve step by step through distinct conditions or states: a server switches between healthy, degraded, and offline; a customer moves from browsing to cart abandonment or purchase; a weather regime shifts from dry to rainy; or a word follows another in a sequence. When the future behavior of a system depends primarily on where it stands right now rather than the full winding path it took to get there, a Markov chain offers a clean, mathematically grounded way to model those transitions.
Named after Russian mathematician Andrey Markov, who studied chains of linked events in the early twentieth century, a Markov chain is a stochastic process over a state space that satisfies the Markov property (often called memorylessness). Given the present state, future states are conditionally independent of earlier historical states.
The Markov Property and Transition Matrices
Consider a discrete-time Markov chain {Xt:t=0,1,2,…} taking values in a countable state space S={1,2,…,m}. The Markov property states that for every time step t and every sequence of states:
P(Xt+1=st+1∣Xt=st,Xt−1=st−1,…,X0=s0)=P(Xt+1=st+1∣Xt=st)
When these one-step transition probabilities do not change over time—meaning P(Xt+1=j∣Xt=i)=pij for all t—the chain is time-homogeneous. We can organize all probabilities pij into an m×m transition matrix P, where row i represents the starting state and column j represents the next state. Because probabilities out of any given state must sum to 1, every row of P is non-negative and sums to 1:
j=1∑mpij=1for every state i∈S
If π(t) is the row vector representing the probability distribution across states at step t, advancing by one step multiplies by P:
π(t+1)=π(t)P
Advancing by k steps simply applies Pk, the k-th matrix power of P, whose (i,j) entry gives the probability of moving from state i to state j in exactly k steps.
Key Structural Properties of Markov Chains
Analyzing long-run behavior requires looking at how states connect and whether the chain settles into a stable regime:
- Communicating and irreducibility: State j is accessible from state i if there is a positive probability of reaching j from i in some finite number of steps. A Markov chain is irreducible if every state can reach every other state—forming a single communicating class.
- Periodicity: The period of a state is the greatest common divisor of the return-time step counts (the number of steps required to return to that state). A chain is aperiodic if states are not trapped in strict deterministic cycles (such as alternating every two steps).
- Recurrence vs. transience: A state is recurrent if, starting there, the chain will eventually return with probability 1; it is transient if there is a positive chance it never returns after leaving.
- Stationary distribution: A probability distribution π is stationary (or invariant) if πP=π. When a finite Markov chain is both irreducible and aperiodic, it converges to a unique stationary distribution regardless of the initial state π(0)—a foundational result of the ergodic theorem for Markov chains.
Common Extensions and Real-World Applications
Basic discrete-time chains with a small state space expand into a rich family of models used across science and engineering:
| Model Variant | How It Extends a Basic Markov Chain | Typical Applications |
|---|---|---|
| Continuous-Time Markov Chain (CTMC) | Transitions occur at random continuous times with exponential holding times and transition rates | Queueing systems, reliability engineering, epidemiology, population dynamics |
| Hidden Markov Model (HMM) | Underlying states are hidden (unobserved), emitting observable signals at each step | Speech recognition, bioinformatics sequence analysis, regime detection |
| Markov Decision Process (MDP) | Adds actions and rewards at each state so a policy can steer transitions | Reinforcement learning, optimal control, dynamic resource allocation |
| Markov Chain Monte Carlo (MCMC) | Constructs a Markov chain whose stationary distribution matches a target probability density | Bayesian posterior sampling, complex numerical integration |
In web search and network analysis, classic algorithms like PageRank treat web navigation as a random walk over a link graph modeled as a Markov chain, using the stationary distribution to measure long-run visit importance. In genetics and linguistics, sequence models use transition probabilities to capture local ordering patterns.
Simulating a Markov Chain in Python
Simulating sample paths from a transition matrix is straightforward in Python and helps verify theoretical long-run proportions through empirical runs:
Python
import numpy as np
states = ["Idle", "Active", "Error"]
P = np.array([
[0.70, 0.25, 0.05], # From Idle
[0.20, 0.72, 0.08], # From Active
[0.40, 0.30, 0.30], # From Error
])
def simulate_chain(P, start_idx, steps, seed=42):
rng = np.random.default_rng(seed)
n_states = P.shape[0]
path = [start_idx]
curr = start_idx
for _ in range(steps):
curr = rng.choice(n_states, p=P[curr])
path.append(curr)
return path
path = simulate_chain(P, start_idx=0, steps=10_000)
empirical_share = {
states[i]: np.mean(np.array(path) == i) for i in range(len(states))
}
print("Empirical state shares:", {k: round(v, 4) for k, v in empirical_share.items()})
Strengths, Limitations, and Practical Considerations
Markov chains shine when sequential transitions are governed by local state dynamics and you need transparent transition probabilities, analytical structure, or fast simulation. They give clear interpretability—showing exact probabilities of moving from one state to another—and serve as the building block for HMMs, MDPs, and MCMC samplers.
Their main limitation is the Markov assumption itself: if future transitions depend heavily on long-range history, elapsed duration in the current state, or external context not encoded in the state definition, a simple first-order chain can miss important memory effects. Often, augmenting the state space (for example, tracking both current status and time-in-state) restores the Markov property while keeping the model tractable.