1. Memoryless Stochastic Sequences
A Markov Chain is a mathematical model for systems that transition between states according to probabilistic rules, where the future state depends exclusively on the current state and not on the history of previous states.
1.1 The Markov Property
A discrete-time sequence of random variables $X_0, X_1, X_2, \dots$ taking values in a discrete state space $\mathcal{S}$ satisfies the Markov Property if for all time steps $t \ge 0$ and states $i_0, i_1, \dots, i, j \in \mathcal{S}$:
$$P(X_{t+1} = j \mid X_t = i, X_{t-1} = i_{t-1}, \dots, X_0 = i_0) = P(X_{t+1} = j \mid X_t = i)$$
text
2. Transition Matrices & Chapman-Kolmogorov
2.1 The Transition Probability Matrix
When transition probabilities do not depend on time $t$ (time-homogeneous), we represent transitions with an $N \times N$ Transition Matrix $\mathbf{P}$:
$$P_{ij} = P(X_{t+1} = j \mid X_t = i)$$
Axioms of Row-Stochastic Matrices:
- Non-negativity: $P_{ij} \ge 0$ for all $i, j \in \mathcal{S}$.
- Total row probability equals 1: $$\sum_{j \in \mathcal{S}} P_{ij} = 1 \quad (\mathbf{P}\mathbf{1} = \mathbf{1})$$
2.2 The Chapman-Kolmogorov Equations
How do we calculate the probability of transitioning from state $i$ to state $j$ in exactly $n$ steps ($P_{ij}^{(n)}$)?
$$P_{ij}^{(m+n)} = \sum_{k \in \mathcal{S}} P_{ik}^{(m)} P_{kj}^{(n)}$$
In matrix notation, the $n$-step transition matrix is simply the matrix power:
$$\mathbf{P}^{(n)} = \mathbf{P}^n$$
Given an initial state probability distribution vector $\mathbf{\pi}_0$, the probability distribution at step $n$ is:
$$\mathbf{\pi}_n = \mathbf{\pi}_0 \mathbf{P}^n$$
3. Classification of States & Long-Term Behavior
To understand whether a Markov chain stabilizes in the long run, we classify its states:
text
4. Stationary Distributions & The Ergodic Theorem
A probability distribution $\mathbf{\pi} = (\pi_1, \pi_2, \dots, \pi_N)$ is a Stationary Distribution (invariant measure) if:
$$\mathbf{\pi} \mathbf{P} = \mathbf{\pi} \quad \text{and} \quad \sum_{i} \pi_i = 1$$
In linear algebra terms, $\mathbf{\pi}$ is a left eigenvector of $\mathbf{P}$ corresponding to the eigenvalue $\lambda = 1$.
The Fundamental Convergence Theorem (Perron-Frobenius)
If a Markov chain is finite, irreducible, and aperiodic (ergodic):
- There exists a unique stationary distribution $\mathbf{\pi}$.
- For any initial distribution $\mathbf{\pi}0$: $$\lim{n \to \infty} \mathbf{P}^n = \mathbf{1} \mathbf{\pi} \implies \lim_{n \to \infty} \mathbf{\pi}_0 \mathbf{P}^n = \mathbf{\pi}$$
- The expected return time to state $i$ is inversely proportional to its stationary probability: $$E[T_i \mid X_0 = i] = \frac{1}{\pi_i}$$
5. Google's PageRank: The World's Most Famous Markov Chain
How does a search engine rank billions of hyperlinked webpages? Larry Page and Sergey Brin modeled the web as a graph random walk:
text
The Random Surfer Model
A virtual user starts at a random page. At each step:
- With probability $d \approx 0.85$ (the damping factor), the surfer clicks a random outbound link.
- With probability $1 - d = 0.15$, the surfer gets bored and teleports uniformly to an arbitrary webpage across the entire web.
The Google Matrix $\mathbf{G}$
Let $\mathbf{P}$ be the raw link transition matrix where $P_{ij} = 1 / \text{deg}_{\text{out}}(i)$ if a link exists. To eliminate dead ends (dangling nodes) and periodic loops, the Google Matrix $\mathbf{G}$ is defined as:
$$\mathbf{G} = d \mathbf{P} + \frac{1 - d}{N} \mathbf{E}$$
where $\mathbf{E} = \mathbf{1}\mathbf{1}^T$ is an $N \times N$ matrix of all ones.
Because every entry of $\mathbf{G}$ is strictly positive ($G_{ij} > 0$), by the Perron-Frobenius theorem $\mathbf{G}$ is guaranteed to be irreducible and aperiodic! The dominant eigenvector $\mathbf{\pi} \mathbf{G} = \mathbf{\pi}$ yields the global PageRank score for every webpage.
6. Gambler's Ruin Random Walk
A gambler starts with $$i$. In each round:
- Wins $$1$ with probability $p$.
- Loses $$1$ with probability $q = 1 - p$. The game ends when the gambler reaches $$N$ (bank broke) or $$0$ (gambler broke). Both $0$ and $N$ are absorbing states.
text
Let $P_i$ be the probability of reaching $$N$ starting from $$i$.
By the Law of Total Probability:
$$P_i = p P_{i+1} + q P_{i-1}$$
Subject to boundary conditions $P_0 = 0$ and $P_N = 1$.
Solving this second-order linear recurrence relation:
$$P_i = \begin{cases} \frac{i}{N} & \text{if } p = 0.5 \text{ (Fair game)} \ \frac{1 - (q/p)^i}{1 - (q/p)^N} & \text{if } p \neq 0.5 \end{cases}$$
House Edge Reality: If $p = 0.49$ (European roulette), starting with $$100$ and playing until $$200$ against a casino with $N = 200$: $$P_{100} = \frac{1 - (0.51/0.49)^{100}}{1 - (0.51/0.49)^{200}} \approx 0.0179 \quad (1.79% \text{ chance of winning!})$$
7. Python Implementation: PageRank via Power Iteration
python
8. Key Takeaways
- Markov Property: The future depends solely on the current state.
- Matrix Powering: $n$-step transitions are computed by $\mathbf{P}^n$.
- Ergodic Convergence: Any irreducible, aperiodic chain converges to a unique stationary distribution $\mathbf{\pi} \mathbf{P} = \mathbf{\pi}$.
- Google PageRank: Adding a small random teleportation probability ($1 - d$) guarantees ergodicity over the entire web graph.