Skip to content
VidiMaster it, module by module
Module 3/Applications

Markov Chains, PageRank & Path Counting

A Markov chain moves between states by fixed probabilities, encoded in a column-stochastic transition matrix AA that updates the state via x(k+1)=Ax(k)x(k+1)=Ax(k). When AA is regular, the chain always settles to a unique equilibrium distribution x∗x^{*} (the normalized eigenvector for λ=1\lambda=1) -- the same idea behind Google's PageRank. The matrix-power trick also counts paths in a directed graph.

Before you start — give these a try

Attempting first primes your brain for the lesson — even if you miss. Nothing is graded or saved; it's just a warm-up.

Find the equilibrium distribution x∗x^{*} of the regular transition matrix A=[0.80.30.20.7]A=\begin{bmatrix}0.8&0.3\\0.2&0.7\end{bmatrix}. Enter x∗=[x1,x2]x^{*}=[x_{1},x_{2}].

Which of the following is a regular transition matrix?

What you’ll be able to do

  • Identify Markov chains and probability distribution vectors, and normalize any nonnegative vector into one (Def.\ 7.8, 7.9; Rmk.\ 7.7).
  • Build a column-stochastic transition matrix and evolve a chain with x(k)=Akx(0)x(k)=A^{k}x(0), knowing each state stays a probability vector (Prop.\ 7.3).
  • Decide when a transition matrix is regular and compute the equilibrium distribution x∗x^{*} as the normalized λ=1\lambda=1 eigenvector (Def.\ 7.10; Thm.\ 7.13; Rmk.\ 7.8).
  • Interpret PageRank as the equilibrium distribution of a web's transition matrix, ranking pages by x∗x^{*} (Ex.\ 7.17).
  • Count rr-paths in a digraph using powers of its adjacency matrix (Def.\ 7.11, 7.12; Thm.\ 7.14).

In your course

· MATH2015 · Linear Algebra & Probability
§7.4 Applications
  • Definition 7.8Markov chain
    An iterative system whose next state depends only on the current state, not on the system's past history.
  • Definition 7.9Probability distribution vector
    A vector with 0≤xi≤10\le x_{i}\le 1 and x1+⋯+xn=1x_{1}+\cdots+x_{n}=1; entry xix_{i} is the probability of state ii.
  • Remark 7.7Normalizing to a probability vector
    Any nonzero vector with nonnegative entries becomes a probability vector by dividing by its entry-sum.
  • Proposition 7.3Transition matrices preserve probability vectors
    If AA is a transition matrix and xx a probability vector, then AxAx is a probability vector.
  • Definition 7.10Positive / regular transition matrix
    AA is positive if all entries are >0>0, and regular if AmA^{m} is positive for some integer m≥1m\ge 1.
  • Theorem 7.13Perron--Frobenius: equilibrium of a regular chain
    A regular transition matrix has a unique equilibrium probability vector x∗x^{*} with Ax∗=x∗Ax^{*}=x^{*} (the λ=1\lambda=1 eigenvector, normalized), and Amx→x∗A^{m}x\to x^{*} for every start xx.
  • Remark 7.8Globally stable equilibrium
    The equilibrium x∗x^{*} is approached from every initial distribution, so it is globally stable.
  • Definition 7.11Adjacency matrix of a digraph
    aij=1a_{ij}=1 if there is an edge vj→viv_{j}\to v_{i}, and 00 otherwise (column == source, row == destination).
  • Definition 7.12rr-path
    A sequence of rr directed edges leading from vjv_{j} to viv_{i}.
  • Theorem 7.14Path counting
    The (i,j)(i,j)-entry of ArA^{r} counts the distinct rr-paths from vjv_{j} to viv_{i}.
Grounded in MATH2015 Chapter 7, §7.4.3 (Markov Processes; PageRank; Counting Paths in a Directed Graph), Examples 7.14--7.17. Transition matrices here are column-stochastic: aij=P(j→i)a_{ij}=P(j\to i) and every column sums to 11.
1

Probability vectors and the transition matrix

A Markov chain is a discrete process whose next state depends only on the current state, not on past history (Def.\ 7.8). The state is a probability distribution vector x=[x1,…,xn]Tx=[x_{1},\dots,x_{n}]^{T}: every entry satisfies 0≤xi≤10\le x_{i}\le 1 and x1+⋯+xn=1x_{1}+\cdots+x_{n}=1 (Def.\ 7.9), with xix_{i} the probability of being in state ii. Any nonzero vector vv with nonnegative entries becomes a probability vector by normalizing -- dividing by its entry-sum (Rmk.\ 7.7): x=vv1+⋯+vnx=\dfrac{v}{v_{1}+\cdots+v_{n}}. For instance v=[3,2,0,1]Tv=[3,2,0,1]^{T} gives x=[12,13,0,16]Tx=\big[\tfrac12,\tfrac13,0,\tfrac16\big]^{T}. The transition probabilities live in a transition matrix A=[aij]A=[a_{ij}], where aija_{ij} is the probability of moving from state jj to state ii (note the reversed indices!). Since each column lists where a fixed source state jj can go, every column is itself a probability vector: 0≤aij≤10\le a_{ij}\le 1 and ∑iaij=1\sum_{i}a_{ij}=1 for each jj. Such an AA is called column-stochastic.

2

Evolving the chain: $x(k)=A^{k}x(0)$

The chain updates by the linear iteration x(k+1)=Ax(k)x(k+1)=Ax(k) with a fixed (time-independent) matrix AA -- that time-independence is exactly what makes it a Markov chain. Starting from a probability vector x(0)x(0), the state after kk steps is x(k)=Akx(0)x(k)=A^{k}x(0). Proposition 7.3 keeps the model sensible: if AA is a transition matrix and xx a probability vector, then AxAx is again a probability vector. Hence every x(k)x(k) is a probability vector -- a 'chain' of distributions describing the system over time. Moreover the entries of AkA^{k} are the kk-step transition probabilities: the (i,j)(i,j)-entry of AkA^{k} is the probability of going from state jj to state ii in exactly kk steps.

3

Regularity and the equilibrium distribution

A transition matrix is positive if every entry is >0>0, and regular (eventually positive) if some power AmA^{m} is positive (Def.\ 7.10). Regularity means that for some number of steps you can reach any state from any other with positive probability. For a regular AA, the Perron--Frobenius theorem (Thm.\ 7.13) gives a unique probability vector x∗x^{*} with Ax∗=x∗Ax^{*}=x^{*} -- the equilibrium distribution, all of whose entries are strictly positive -- and Amx→x∗A^{m}x\to x^{*} for every starting distribution xx. So x∗x^{*} is the (normalized) eigenvector for eigenvalue λ=1\lambda=1, and it is a globally stable equilibrium (Rmk.\ 7.8). To find it: solve the homogeneous system (A−I)x∗=0(A-I)x^{*}=0, then rescale the solution so its entries sum to 11. Not every chain is regular -- the reflection [0110]\begin{bmatrix}0&1\\1&0\end{bmatrix} has powers that only alternate between AA and II, so it never becomes positive and has no stable limit.

4

Digraphs: adjacency matrix and counting paths

A directed graph (digraph) has vertices joined by arrows (edges). Its adjacency matrix A=[aij]A=[a_{ij}] sets aij=1a_{ij}=1 when there is an edge from vjv_{j} to viv_{i} and 00 otherwise (Def.\ 7.11) -- again column == source, row == destination. An rr-path from vjv_{j} to viv_{i} is a sequence of rr consecutive directed edges leading from vjv_{j} to viv_{i} (Def.\ 7.12); single edges are the 11-paths counted by AA itself. The path-counting theorem (Thm.\ 7.14) says the (i,j)(i,j)-entry of ArA^{r} equals the number of distinct rr-paths from vjv_{j} to viv_{i}. This is the same matrix-power idea as a Markov chain, except the entries count paths instead of carrying probabilities; replacing the 11's by transition probabilities turns the digraph into a Markov chain. A PageRank web graph (Ex.\ 7.17) is precisely such a weighted digraph.

Proposition 7.3 -- Transition matrices preserve probability vectors

If AA is a transition matrix and xx is a probability vector, then AxAx is also a probability vector. Consequently, if x(0)x(0) is a probability vector then every state x(k)=Akx(0)x(k)=A^{k}x(0) is a probability vector.

Intuition. AxAx is a weighted average (convex combination) of the columns of AA, with weights xi≥0x_{i}\ge 0 summing to 11. Each column is itself a probability vector, and a weighted average of probability vectors is again one -- total probability is conserved at every step.
Theorem 7.13 -- Perron--Frobenius (equilibrium of a regular chain)

Let AA be an n×nn\times n regular transition matrix. (a) There is exactly one probability distribution vector x∗x^{*} with Ax∗=x∗Ax^{*}=x^{*}, the equilibrium distribution, and all its entries are strictly positive. (b) For every probability vector xx, lim⁡m→∞Amx=x∗\displaystyle\lim_{m\to\infty}A^{m}x=x^{*}. (c) lim⁡m→∞Am\displaystyle\lim_{m\to\infty}A^{m} is the matrix whose columns are all equal to x∗x^{*}.

Intuition. Part (a) says x∗x^{*} is the unique (normalized) eigenvector for eigenvalue λ=1\lambda=1. Part (b) says the chain forgets where it started: from any initial distribution it converges to the same x∗x^{*}, so x∗x^{*} is a globally stable equilibrium (Rmk.\ 7.8). To compute it, solve (A−I)x∗=0(A-I)x^{*}=0 and normalize.
Theorem 7.14 -- Path counting

If AA is the adjacency matrix of a digraph with nn vertices, then the (i,j)(i,j)-entry of ArA^{r} equals the number of distinct rr-paths from vjv_{j} to viv_{i}.

Intuition. (Ar)ij=∑k(Ar−1)ik akj(A^{r})_{ij}=\sum_{k}(A^{r-1})_{ik}\,a_{kj} builds every rr-path from vjv_{j} by taking one edge vj→vkv_{j}\to v_{k} (when akj=1a_{kj}=1) followed by an (r−1)(r-1)-path vk→viv_{k}\to v_{i}; summing over all intermediate vkv_{k} counts each path exactly once. It mirrors how AkA^{k} accumulates kk-step transition probabilities in a Markov chain.

Worked examples

Example 1

Weather (Ex.\ 7.14--7.15). In NYC, if today is sunny there is a 70%70\% chance tomorrow is sunny; if today is cloudy there is an 80%80\% chance tomorrow is cloudy. Write the transition matrix, find the distribution one day after a sunny day, and find the long-run (equilibrium) distribution.

  1. 1

    States: sunny ss, cloudy cc. From sunny: 0.70.7 stay sunny, 0.30.3 turn cloudy. From cloudy: 0.20.2 turn sunny, 0.80.8 stay cloudy. With aij=P(state j→state i)a_{ij}=P(\text{state }j\to\text{state }i), each column (source) is a probability vector: A=[0.70.20.30.8]A=\begin{bmatrix}0.7&0.2\\0.3&0.8\end{bmatrix} (columns sum to 11).

  2. 2

    Today is sunny: x(0)=[10]x(0)=\begin{bmatrix}1\\0\end{bmatrix}. One step gives x(1)=Ax(0)=[0.70.3]x(1)=Ax(0)=\begin{bmatrix}0.7\\0.3\end{bmatrix} -- a 70%/30%70\%/30\% split, still a probability vector (Prop.\ 7.3).

  3. 3

    AA is positive, hence regular, so a unique equilibrium exists (Thm.\ 7.13). Solve (A−I)x∗=0(A-I)x^{*}=0 with A−I=[−0.30.20.3−0.2]A-I=\begin{bmatrix}-0.3&0.2\\0.3&-0.2\end{bmatrix}: the equation −0.3x1+0.2x2=0-0.3x_{1}+0.2x_{2}=0 gives x1=23x2x_{1}=\tfrac23 x_{2}, so v=[23]v=\begin{bmatrix}2\\3\end{bmatrix} is the λ=1\lambda=1 eigenvector.

  4. 4

    Normalize vv (Rmk.\ 7.7) by dividing by 2+3=52+3=5: x∗=[2/53/5]=[0.40.6]x^{*}=\begin{bmatrix}2/5\\3/5\end{bmatrix}=\begin{bmatrix}0.4\\0.6\end{bmatrix}. Check: Ax∗=[0.7(0.4)+0.2(0.6)0.3(0.4)+0.8(0.6)]=[0.40.6]=x∗.Ax^{*}=\begin{bmatrix}0.7(0.4)+0.2(0.6)\\0.3(0.4)+0.8(0.6)\end{bmatrix}=\begin{bmatrix}0.4\\0.6\end{bmatrix}=x^{*}.

Answer. A=[0.70.20.30.8]A=\begin{bmatrix}0.7&0.2\\0.3&0.8\end{bmatrix},   x(1)=[0.70.3]\;x(1)=\begin{bmatrix}0.7\\0.3\end{bmatrix}, and the equilibrium is x∗=[0.40.6]x^{*}=\begin{bmatrix}0.4\\0.6\end{bmatrix}: in the long run about 40%40\% of days are sunny and 60%60\% cloudy, regardless of today's weather.
Example 2

PageRank mini-web (Ex.\ 7.17). Four pages link as: page 1→{2,3}1\to\{2,3\}, page 2→{1,3}2\to\{1,3\}, page 3→{4}3\to\{4\}, page 4→{2}4\to\{2\}. A surfer follows each outgoing link with equal probability. Build the transition matrix, confirm it is regular, and rank the pages by long-run visit frequency.

Example 3

Counting paths (Thm.\ 7.14). A digraph on v1,v2,v3v_{1},v_{2},v_{3} has edges v1→v1,  v1→v2,  v1→v3,  v2→v1,  v3→v2v_{1}\to v_{1},\;v_{1}\to v_{2},\;v_{1}\to v_{3},\;v_{2}\to v_{1},\;v_{3}\to v_{2}. Write its adjacency matrix and count the 22-paths and 33-paths between vertices.