Survey of Mathematics

2.11 Markov chains and PageRank

A random walker who moves by fixed probabilities is described by a matrix whose columns add to 1. Its long-run behaviour is an eigenvector with eigenvalue 1, and Google ranked the web by computing that eigenvector.

Taught in 375/376Beyond the courseSpagnolie, Lecture 1 (the PageRank aside) and Lectures 16 to 18 (eigenvalues)Bryan and Leise, The $25,000,000,000 Eigenvector, SIAM Review 48 (2006)Page, Brin, Motwani and Winograd, The PageRank Citation Ranking (Stanford, 1998)Strang, Introduction to Linear Algebra, section 10.3

In Lecture 1, Spagnolie said that real systems can have “30 billion equations and 30 billion variables (Google PageRank!)” and asked “how can you even compute?!”. He called it “the $25 bil eigenvector”. This chapter shows what that eigenvector is. A person clicking links at random wanders over the web. The pages where they spend the most time are, plausibly, the important ones. The matrix that describes the wandering has an eigenvector with eigenvalue 1, and that eigenvector is the ranking.

Before you start

2.8: eigenvalues and eigenvectors, and diagonalization. 2.7: the determinant of a transpose. 2.5: matrix times vector and the transpose. In this chapter probabilities are numbers from 00 to 11, and the only probability rule used is that the chances of all the possible outcomes add to 11.

Quick checkIf Ax=3xAx = 3x for a non-zero vector xx, what is xx?
Quick checkA square matrix AA and its transpose ATA^{\mathsf T} have...
Quick checkThe matrix with rows (0,1)(0, 1) and (1,0)(1, 0) multiplies the column vector (3,5)(3, 5). What is the result?

The picture

Four web pages, and arrows for the links between them. Page 1 links to pages 2, 3 and 4, page 2 links to pages 3 and 4, page 3 links only to page 1, and page 4 links to pages 1 and 3. A surfer starts on page 1 and, at every step, clicks one of the links on the current page, each link equally likely. The bars show the chance of finding the surfer on each page. Press Next. After one step the surfer is on page 2, 3 or 4 with chance 1/31/3 each. After many steps the bars stop changing: that final set of heights is the ranking.

Two things to watch. The bars always add up to 1, because the surfer is always somewhere. And the heights settle down to the same values wherever the surfer starts. Both facts need a proof, and the proofs use eigenvalues.

The idea, in words

Number the pages 1,…,n1, \dots, n. Let PijP_{ij} be the chance that a surfer on page jj goes next to page ii. The convention is “column jj describes what happens from page jj”. With the four pages above, column 1 is (0,13,13,13)(0, \tfrac13, \tfrac13, \tfrac13) because page 1 has three links, and column 3 is (1,0,0,0)(1, 0, 0, 0) because page 3 has one link, to page 1. So

P=[00112130001312012131200].P = \begin{bmatrix} 0 & 0 & 1 & \tfrac12 \\ \tfrac13 & 0 & 0 & 0 \\ \tfrac13 & \tfrac12 & 0 & \tfrac12 \\ \tfrac13 & \tfrac12 & 0 & 0 \end{bmatrix}.

Every column adds to 1, because from any page the surfer goes somewhere.

Let xkx_k be the list of chances: (xk)i(x_k)_i is the chance the surfer is on page ii after kk steps. To land on page ii at the next step, the surfer must be on some page jj now and choose the link j→ij \to i. Add up over all jj:

(xk+1)i=∑jPij (xk)j,that isxk+1=P xk.(x_{k+1})_i = \sum_j P_{ij}\,(x_k)_j, \qquad\text{that is}\qquad x_{k+1} = P\,x_k .

So the whole story of the surfer is a matrix applied again and again. Chapter 2.8 showed what that means: write the starting vector in eigenvectors, and applying PP multiplies each part by its eigenvalue. The part with the biggest eigenvalue wins, and the others fade.

Why· Why an eigenvector with eigenvalue 1 is the ranking

If the surfer’s chances ever reach a vector π\pi that one more step does not change, then Pπ=πP\pi = \pi. That is the equation of an eigenvector with eigenvalue 11. Pages with larger entries of π\pi are the ones where the surfer spends more time. A page gets a high entry when many pages send surfers to it, and more when the pages sending them have high entries themselves. That is the idea of PageRank: a link from an important page is worth more than a link from an obscure one.

Where this came from· Markov and Eugene Onegin

Andrey Markov introduced these chains around 1906 in an argument about probability. Pavel Nekrasov had claimed that averages settle down (the law of large numbers) only for independent events. Markov showed that sequences in which each step depends on the previous state also settle, and he proved it using transition chances like the ones in this chapter. In 1913 he tried the idea on literature: he took the first 20,000 letters of Pushkin’s poem Eugene Onegin, classified each as a vowel or a consonant, and studied how a vowel or consonant follows the one before. That is a two-state chain like our weather example, and its stationary distribution is the long-run share of vowels. The mathematics came first and the web came ninety years later.

The chapter answers five questions, in order. (1) Why does PxPx stay a list of chances? (2) Why is 11 always an eigenvalue? (3) Why is it the largest? (4) When do the bars settle on one answer, and how fast? (5) What goes wrong on the real web, and what did Google do about it?

Definitions and theorems

Definition B

Markov chain

A Markov chain has a list of states 1,…,n1, \dots, n and fixed numbers Pij≥0P_{ij} \ge 0, where PijP_{ij} is the chance of moving to state ii from state jj in one step. The defining rule (the Markov property) is that this chance depends only on the current state, not on how the process got there. In the web example the states are pages and the surfer’s past clicks do not matter.

In one lineA process that moves among states, where the chance of the next state depends only on the current state and is given by fixed numbers PijP_{ij}.

Why it existsIt is the simplest model of change over time with randomness, and it turns a probability question into a matrix question.

A warning on conventions. Probability courses (including MATH 431) usually put “from” on the row: pjip_{ji} is the chance of moving from jj to ii, rows add to 1, and the chances are a row vector multiplied on the left. This book, Spagnolie and the PageRank papers put “from” on the column, so columns add to 1 and the chances are a column vector multiplied on the right. The two are transposes of each other. Nothing in the mathematics changes.

Definition B

Stochastic matrix

A list x=(x1,…,xn)x = (x_1, \dots, x_n) is a probability vector if every xi≥0x_i \ge 0 and x1+⋯+xn=1x_1 + \dots + x_n = 1. A square matrix PP is stochastic (more precisely, column-stochastic) if every entry is non-negative and every column is a probability vector, that is, every column adds to 1. Write 1=(1,1,…,1)\mathbf 1 = (1, 1, \dots, 1). Then “every column adds to 1” is the single equation 1TP=1T\mathbf 1^{\mathsf T}P = \mathbf 1^{\mathsf T}, because entry jj of 1TP\mathbf 1^{\mathsf T}P is the sum of column jj.

In one lineA square matrix with no negative entries in which every column adds to 1. Its columns are probability vectors.

Why it existsIt is exactly the shape of a matrix of transition chances, because from every state the process goes somewhere.

Worked example
A surfer on three pages: page 1 links to pages 2 and 3, page 2 links to page 3, and page 3 links to page 1. Write the matrix PP, check it is stochastic, and find the surfer's chances after one and two steps if she starts on page 1.

Solution.

  1. Write the columns from the links. Column jj lists where page jj sends the surfer, equally split among its links. Page 1 has two links: column 1 is (0,12,12)(0, \tfrac12, \tfrac12). Page 2 has one link, to page 3: column 2 is (0,0,1)(0, 0, 1). Page 3 has one link, to page 1: column 3 is (1,0,0)(1, 0, 0). Each link out of page jj is equally likely, so with ℓ\ell links each gets chance 1/ℓ1/\ell.
  2. Assemble the matrix. P=[00112001210]P = \begin{bmatrix} 0 & 0 & 1 \\ \tfrac12 & 0 & 0 \\ \tfrac12 & 1 & 0 \end{bmatrix}. Columns side by side.
  3. Check it. All entries are at least 00 and the columns add to 12+12=1\tfrac12 + \tfrac12 = 1, 11 and 11. That is the definition of stochastic.
  4. One step. Start at x0=(1,0,0)x_0 = (1, 0, 0). Then x1=Px0=(0,12,12)x_1 = Px_0 = (0, \tfrac12, \tfrac12). Px0Px_0 with x0=e1x_0 = e_1 picks out column 1.
  5. Two steps. x2=Px1=12 (column 2)+12 (column 3)=(12,0,12)x_2 = Px_1 = \tfrac12\,(\text{column }2) + \tfrac12\,(\text{column }3) = (\tfrac12, 0, \tfrac12). Px=x1⋅column 1+x2⋅column 2+…Px = x_1 \cdot \text{column } 1 + x_2 \cdot \text{column } 2 + \dots, a combination of the columns with the entries of xx as weights.

Answer. After one step the surfer is on page 2 or page 3 with chance 12\tfrac12 each. After two steps she is on page 1 or page 3 with chance 12\tfrac12 each. Both lists add to 11.

Theorem B Strang 10.3; Bryan and Leise, section 3

A stochastic matrix keeps probability vectors

Let PP be stochastic and xx a probability vector. Then PxPx is a probability vector. If PP and QQ are both stochastic n×nn \times n matrices, so is PQPQ. In particular PkP^k is stochastic for every kk, and Pkx0P^kx_0 is a probability vector for every kk.

In one lineIf PP is stochastic and xx is a probability vector, then PxPx is a probability vector. Also a product of stochastic matrices is stochastic.

Why it is trueProbability is never lost or created. It is moved around, and each column says how it moves.

ProofBryan and Leise section 3
The idea: Entries: sums of products of non-negative numbers. Total: swap the order of summation and use that each column adds to 1.
Every entry of PxPx is non-negative.
Entry ii of PxPx is ∑jPijxj\sum_j P_{ij}x_j. Every Pij≥0P_{ij} \ge 0 and every xj≥0x_j \ge 0, so every term is at least 00.
∑i(Px)i=∑i∑jPijxj\displaystyle \sum_i (Px)_i = \sum_i \sum_j P_{ij}x_j.
Add up all the entries of PxPx and write each as its sum over jj.
=∑jxj(∑iPij)\displaystyle = \sum_j x_j \Big( \sum_i P_{ij} \Big).
A finite double sum can be added in either order. We add over ii first, because that is the sum of a column of PP.
=∑jxj⋅1=1\displaystyle = \sum_j x_j \cdot 1 = 1. So PxPx is a probability vector.
Each column adds to 1. Then the entries of xx add to 1.
For products: column jj of PQPQ is PP times column jj of QQ.
The columns of PQPQ are PP times the columns of QQ (2.5). Each column of QQ is a probability vector, so by the first part each column of PQPQ is one, hence PQPQ is stochastic.
PkP^k is stochastic for all kk, and so Pkx0P^kx_0 is a probability vector.
Induction on kk: Pk+1=P⋅PkP^{k+1} = P \cdot P^k.
Quick checkPP is stochastic and x=(0.2,0.3,0.5)x = (0.2, 0.3, 0.5). What do the entries of PxPx add up to?
Worked example
Prove that the product PQPQ of two stochastic matrices is stochastic, and check it by squaring the weather matrix (columns (0.8,0.2)(0.8, 0.2) and (0.4,0.6)(0.4, 0.6)).

Solution.

  1. Entries. (PQ)ij=∑kPikQkj(PQ)_{ij} = \sum_k P_{ik}Q_{kj} is a sum of products of non-negative numbers, so it is at least 00. Products and sums of non-negative numbers are non-negative.
  2. Column sum. ∑i(PQ)ij=∑i∑kPikQkj=∑kQkj∑iPik\sum_i (PQ)_{ij} = \sum_i \sum_k P_{ik}Q_{kj} = \sum_k Q_{kj}\sum_i P_{ik}. Swap the two finite sums, and pull QkjQ_{kj} out of the sum over ii because it does not depend on ii.
  3. Use that PP is stochastic. ∑iPik=1\sum_i P_{ik} = 1 for every kk, so the column sum is ∑kQkj=1\sum_k Q_{kj} = 1. First PP‘s columns add to 1, then QQ‘s column does.
  4. Numerical check. P2=[0.720.560.280.44]P^2 = \begin{bmatrix} 0.72 & 0.56 \\ 0.28 & 0.44 \end{bmatrix} and the columns add to 0.72+0.28=10.72 + 0.28 = 1 and 0.56+0.44=10.56 + 0.44 = 1. An independent check on the formula.

Answer. The product is stochastic. Interpretation: P2P^2 gives the chances of two steps, and two steps is still a chain that goes somewhere.

Staying put: stationary distributions

Definition B

Stationary distribution

A probability vector π\pi is a stationary distribution of the stochastic matrix PP if Pπ=πP\pi = \pi. In the language of chapter 2.8, it is a probability vector that is an eigenvector of PP with eigenvalue 11.

In one lineA probability vector π\pi with Pπ=πP\pi = \pi: the chances do not change when the surfer takes another step.

Why it existsIt is the long-run answer. If the chances settle down at all, they settle at a stationary distribution, and it is the PageRank vector.

Theorem B Bryan and Leise, Prop. 1

One is always an eigenvalue of a stochastic matrix

Every stochastic matrix PP has 11 as an eigenvalue. So there is a non-zero real vector vv with Pv=vPv = v.

In one lineEvery stochastic matrix has eigenvalue 1.

Why it is trueThe all-ones row vector is a left eigenvector with eigenvalue 1 because the columns add to 1. A matrix and its transpose share eigenvalues, so the matrix itself has eigenvalue 1 too.

ProofBryan and Leise
The idea: Find the eigenvector of the transpose, which is easy (all ones), then move the eigenvalue back to P because P and its transpose have the same characteristic polynomial.
PT1=1P^{\mathsf T}\mathbf 1 = \mathbf 1.
Entry jj of PT1P^{\mathsf T}\mathbf 1 is the sum of column jj of PP, which is 1. (The columns of PP are the rows of PTP^{\mathsf T}.)
So 11 is an eigenvalue of PTP^{\mathsf T}.
1\mathbf 1 is not the zero vector, so by the definition in 2.8 it is an eigenvector of PTP^{\mathsf T} with eigenvalue 1.
det⁡(λI−PT)=det⁡((λI−P)T)=det⁡(λI−P)\det(\lambda I - P^{\mathsf T}) = \det\big((\lambda I - P)^{\mathsf T}\big) = \det(\lambda I - P).
The determinant of a transpose equals the determinant (2.7), and (λI−P)T=λI−PT(\lambda I - P)^{\mathsf T} = \lambda I - P^{\mathsf T}.
PP and PTP^{\mathsf T} have the same eigenvalues, so 11 is an eigenvalue of PP.
The eigenvalues are the roots of the characteristic polynomial (2.8). Equal polynomials have equal roots.
A non-zero real vv with Pv=vPv = v exists.
P−IP - I is a real matrix with determinant 00, so it is not invertible and its null space contains a non-zero vector. That vector can be taken real, since the system (P−I)v=O(P - I)v = O has real coefficients.
Why· The picture behind the proof

In the visualizer, the left eigenvector 1\mathbf 1 says “add up the bars”. The statement 1TP=1T\mathbf 1^{\mathsf T}P = \mathbf 1^{\mathsf T} is the fact that the total height of the bars is the same before and after a step: the bars are rearranged, not created. A quantity that every step leaves unchanged is exactly what an eigenvalue of 1 means. The matrix PP itself has a different eigenvector for eigenvalue 1 (the stationary bars), and that one is not all ones.

Worked example
Let M be a square matrix whose rows (not columns) each add to 1. Prove that 1 is an eigenvalue of M, and say how this differs from the case of a column-stochastic P.

Solution.

  1. Compute M1M\mathbf 1. Entry ii of M1M\mathbf 1 is row ii of MM dotted with (1,…,1)(1, \dots, 1), which is the sum of row ii. Multiplying by the all-ones vector adds up each row.
  2. Use the hypothesis. Every row adds to 11, so M1=1M\mathbf 1 = \mathbf 1. This is the definition of the matrix.
  3. Name the eigenvector. 1≠O\mathbf 1 \ne O, so 11 is an eigenvalue of MM with eigenvector 1\mathbf 1. An eigenvector is a non-zero vector with Mv=λvMv = \lambda v.
  4. Compare with columns. For a column-stochastic PP the same computation gives PT1=1P^{\mathsf T}\mathbf 1 = \mathbf 1, an eigenvector of the transpose. Columns of PP are rows of PTP^{\mathsf T}. Then PP itself gets the eigenvalue 11 because PP and PTP^{\mathsf T} have the same characteristic polynomial, but its eigenvector is a different vector, the stationary distribution.

Answer. M1=1M\mathbf 1 = \mathbf 1, so 11 is an eigenvalue and 1\mathbf 1 is its eigenvector. This is the row-stochastic convention of probability books. In this book the all-ones vector belongs to PTP^{\mathsf T}, not to PP.

So there is an eigenvector. Is it a probability vector, and is it unique? The answers wait for the next sections. First, the size of the other eigenvalues.

Theorem B Bryan and Leise, Prop. 2

Eigenvalues of a stochastic matrix have size at most one

Let PP be stochastic and Pv=λvPv = \lambda v with v≠Ov \ne O (complex numbers allowed). Then ∣λ∣≤1|\lambda| \le 1.

In one lineEvery eigenvalue λ\lambda of a stochastic matrix, real or complex, satisfies ∣λ∣≤1|\lambda| \le 1.

Why it is trueA step never increases the total size of a vector, measured by adding the absolute values of its entries. An eigenvector that grew by more than 1 per step would contradict that.

Here ∣λ∣|\lambda| is the size of λ\lambda: for a complex number a+bia + bi it is a2+b2\sqrt{a^2 + b^2}, its distance from 00 in the complex plane. For a vector xx (real or complex), let ∥x∥1=∣x1∣+⋯+∣xn∣\lVert x \rVert_1 = |x_1| + \dots + |x_n| be the 1-norm: add the sizes of the entries. It measures size in a different way from the length x⋅x\sqrt{x \cdot x} used in 2.9. We use only two of its properties: it is 00 only for OO, and ∥cx∥1=∣c∣ ∥x∥1\lVert cx \rVert_1 = |c|\,\lVert x \rVert_1.

ProofBryan and Leise
The idea: Show that P never makes the 1-norm bigger. Then an eigenvector with eigenvalue lambda has its norm multiplied by |lambda|, which therefore cannot exceed 1.
∣(Px)i∣≤∑jPij ∣xj∣\displaystyle |(Px)_i| \le \sum_j P_{ij}\,|x_j|.
Entry ii of PxPx is ∑jPijxj\sum_j P_{ij}x_j. The absolute value of a sum is at most the sum of the absolute values (the triangle inequality), and ∣Pijxj∣=Pij∣xj∣|P_{ij}x_j| = P_{ij}|x_j| because Pij≥0P_{ij} \ge 0.
∥Px∥1≤∑i∑jPij∣xj∣\displaystyle \lVert Px \rVert_1 \le \sum_i \sum_j P_{ij}|x_j|.
Add this up over ii.
=∑j∣xj∣(∑iPij)=∑j∣xj∣=∥x∥1\displaystyle = \sum_j |x_j| \Big( \sum_i P_{ij} \Big) = \sum_j |x_j| = \lVert x \rVert_1.
Swap the sums, as in the previous proof, and use that every column of PP adds to 1.
∣λ∣ ∥v∥1≤∥v∥1|\lambda|\,\lVert v \rVert_1 \le \lVert v \rVert_1.
For an eigenvector, Pv=λvPv = \lambda v, so ∥Pv∥1=∣λ∣ ∥v∥1\lVert Pv \rVert_1 = |\lambda|\,\lVert v \rVert_1.
∣λ∣≤1|\lambda| \le 1.
v≠Ov \ne O, so ∥v∥1>0\lVert v \rVert_1 > 0, and we can divide.
Proof workshopRebuild the proof that no eigenvalue of a stochastic matrix is bigger than 1

Tap the lines in the order a proof would write them. Each line can only use what is already above it.

    The proof gives more than the statement. For every vector, ∥Px∥1≤∥x∥1\lVert Px \rVert_1 \le \lVert x \rVert_1, and equality holds for non-negative xx (then no absolute values change). The triangle inequality is where mass can be lost: if the entries PijxjP_{ij}x_j in a row have mixed signs, they partly cancel. We will use that.

    Quick checkCan a stochastic matrix have the eigenvalue 2?
    Worked example
    Prove that for a stochastic matrix P and a vector x with all entries at least 0, the 1-norm of Px equals the 1-norm of x. Say where the inequality of the earlier proof becomes an equality.

    Solution.

    1. Sign of the entries. Every entry of PxPx is ∑jPijxj\sum_jP_{ij}x_j, a sum of products of non-negative numbers, so it is at least 00. Both PijP_{ij} and xjx_j are non-negative.
    2. Drop the absolute values. So ∥Px∥1=∑i(Px)i\lVert Px \rVert_1 = \sum_i (Px)_i and ∥x∥1=∑jxj\lVert x \rVert_1 = \sum_j x_j. The 1-norm adds absolute values, and absolute values of non-negative numbers change nothing.
    3. Add up the entries of PxPx. ∑i∑jPijxj=∑jxj∑iPij=∑jxj\sum_i\sum_jP_{ij}x_j = \sum_jx_j\sum_iP_{ij} = \sum_jx_j. Swap the finite sums, then each column of PP adds to 11.
    4. Find the equality. In the earlier proof the only inequality was the triangle inequality ∣∑jPijxj∣≤∑jPij∣xj∣\big|\sum_jP_{ij}x_j\big| \le \sum_jP_{ij}|x_j|. For x≥0x \ge 0 the terms PijxjP_{ij}x_j are all non-negative, so the left side equals the right side. The triangle inequality is an equality exactly when no terms cancel, and non-negative numbers cannot cancel.

    Answer. ∥Px∥1=∥x∥1\lVert Px \rVert_1 = \lVert x \rVert_1 for x≥0x \ge 0. A vector with mixed signs can lose norm, because its positive and negative parts partly cancel. That cancellation is the “wobble” that shrinks as the chain settles.

    Lemma B Bryan and Leise, Lemma

    Other eigenvectors have entries adding to zero

    Let PP be stochastic and Pv=λvPv = \lambda v with λ≠1\lambda \ne 1. Then 1Tv=0\mathbf 1^{\mathsf T}v = 0.

    In one lineIf Pv=λvPv = \lambda v with λ≠1\lambda \ne 1, the entries of vv add to 00.

    Why it is trueThe total of the entries is conserved by PP. A vector that gets multiplied by a number other than 1 and also keeps its total must have total zero.

    ProofBryan and Leise
    The idea: Compute the total of the entries of Pv in two ways.
    1T(Pv)=1Tv\mathbf 1^{\mathsf T}(Pv) = \mathbf 1^{\mathsf T}v.
    1TP=1T\mathbf 1^{\mathsf T}P = \mathbf 1^{\mathsf T} because the columns add to 1.
    1T(Pv)=λ 1Tv\mathbf 1^{\mathsf T}(Pv) = \lambda\,\mathbf 1^{\mathsf T}v.
    Pv=λvPv = \lambda v.
    (λ−1) 1Tv=0(\lambda - 1)\,\mathbf 1^{\mathsf T}v = 0.
    Subtract the two lines.
    1Tv=0\mathbf 1^{\mathsf T}v = 0.
    λ≠1\lambda \ne 1, so the first factor is not zero and can be divided out.
    Worked example
    Find the stationary distribution of the weather chain: a sunny day is followed by a sunny day with chance 0.8 and a rainy day with chance 0.2; a rainy day is followed by a sunny day with chance 0.4 and a rainy day with chance 0.6. Also find the eigenvalues, and the chances kk days after a sunny day.

    Solution.

    1. Write the matrix. P=[0.80.40.20.6]P = \begin{bmatrix} 0.8 & 0.4 \\ 0.2 & 0.6 \end{bmatrix}, with the sunny state first. Column 1 describes what follows a sunny day, column 2 what follows a rainy one. Each column adds to 1.
    2. Write Pπ=πP\pi = \pi as a homogeneous system. (P−I)π=O(P - I)\pi = O gives −0.2π1+0.4π2=0-0.2\pi_1 + 0.4\pi_2 = 0 and 0.2π1−0.4π2=00.2\pi_1 - 0.4\pi_2 = 0. Moving π\pi to the left side makes it a null-space problem, as in 2.8.
    3. Solve. Both equations say π1=2π2\pi_1 = 2\pi_2. A basis of the null space is (2,1)(2, 1). The two equations are multiples of each other, because P−IP - I is singular, as the theorem on eigenvalue 1 promised.
    4. Scale to a probability vector. Divide by the sum 33: π=(23,13)\pi = (\tfrac23, \tfrac13). A stationary distribution must be a probability vector, with entries adding to 1.
    5. Find the other eigenvalue. The trace of PP is 1.41.4 and it equals the sum of the eigenvalues (2.8), so the other eigenvalue is 0.40.4. Its eigenvector is (−1,1)(-1, 1), the vector with entries adding to 00, as the lemma says. Check: P(−1,1)=(−0.8+0.4, −0.2+0.6)=(−0.4,0.4)=0.4 (−1,1)P(-1, 1) = (-0.8 + 0.4,\ -0.2 + 0.6) = (-0.4, 0.4) = 0.4\,(-1, 1).
    6. Chances after a sunny day. Write x0=(1,0)=π+13(1,−1)x_0 = (1, 0) = \pi + \tfrac13(1, -1). Applying PP kk times multiplies each eigen-part by its eigenvalue: xk=π+13(0.4)k(1,−1)x_k = \pi + \tfrac13(0.4)^k(1, -1), that is (23+13(0.4)k, 13−13(0.4)k)\big(\tfrac23 + \tfrac13(0.4)^k,\ \tfrac13 - \tfrac13(0.4)^k\big). Pπ=πP\pi = \pi and P(1,−1)=0.4 (1,−1)P(1, -1) = 0.4\,(1, -1).
    7. Check k=1k = 1. x1=(23+0.1333,13−0.1333)=(0.8,0.2)x_1 = (\tfrac23 + 0.1333, \tfrac13 - 0.1333) = (0.8, 0.2), the first column of PP. An independent check of the formula.

    Answer. Long-run, two days in three are sunny. The chances approach (23,13)(\tfrac23, \tfrac13) geometrically, with the error shrinking by a factor 0.40.4 each day.

    Quick checkSolving (P−I)π=O(P - I)\pi = O for a 2×22\times2 stochastic matrix gives the null-space vector (3,4)(3, 4). What is the stationary distribution?
    Your answerA weather chain has P=[0.60.30.40.7]P = \begin{bmatrix} 0.6 & 0.3 \\ 0.4 & 0.7 \end{bmatrix}. What fraction of days are sunny in the long run (the first entry of π\pi)?
    Your answerA 2×22\times2 stochastic matrix has P=[0.750.50.250.5]P = \begin{bmatrix} 0.75 & 0.5 \\ 0.25 & 0.5 \end{bmatrix}. What is its other eigenvalue (besides 1)?
    Worked example Bryan and Leise's example; the visualizer above
    Find the stationary distribution of the four-page web (page 1 links to 2, 3, 4; page 2 to 3, 4; page 3 to 1; page 4 to 1, 3).

    Solution.

    1. Write Pπ=πP\pi = \pi row by row, using the matrix in the chapter’s introduction. π1=π3+12π4\pi_1 = \pi_3 + \tfrac12\pi_4,  π2=13π1\ \pi_2 = \tfrac13\pi_1,  π3=13π1+12π2+12π4\ \pi_3 = \tfrac13\pi_1 + \tfrac12\pi_2 + \tfrac12\pi_4,  π4=13π1+12π2\ \pi_4 = \tfrac13\pi_1 + \tfrac12\pi_2. Each equation says “page ii gets the same share after a step as before”. Row ii lists the pages that link to ii and how much of their share they send.
    2. Choose a parameter. Put π1=3t\pi_1 = 3t. Then π2=t\pi_2 = t. Equation 2 gives π2\pi_2 in terms of π1\pi_1; choosing π1=3t\pi_1 = 3t avoids fractions. One equation is redundant because P−IP - I is singular, so one free parameter is expected.
    3. Find π4\pi_4 and π3\pi_3. π4=13(3t)+12t=32t\pi_4 = \tfrac13(3t) + \tfrac12 t = \tfrac32 t. Then 3t=π3+34t3t = \pi_3 + \tfrac34 t gives π3=94t\pi_3 = \tfrac94 t. Equation 4 gives π4\pi_4. Equation 1 gives π3\pi_3.
    4. Check the unused equation. Equation 3: 94t=?t+12t+34t=94t\tfrac94 t \overset{?}{=} t + \tfrac12 t + \tfrac34 t = \tfrac94 t. Yes. It was not used, so it checks the arithmetic independently.
    5. Scale. The entries are 3t,t,94t,32t3t, t, \tfrac94 t, \tfrac32 t, which add to 314t\tfrac{31}{4}t. Setting this to 1 gives t=431t = \tfrac4{31} and π=(12,4,9,6)/31\pi = (12, 4, 9, 6)/31. A probability vector must add to 1.

    Answer. π=(12,4,9,6)/31≈(0.387,0.129,0.290,0.194)\pi = (12, 4, 9, 6)/31 \approx (0.387, 0.129, 0.290, 0.194), the heights the visualizer settles on. Page 1 ranks first, although page 3 has the most links in. Page 3 gives its entire share to page 1.

    Does it settle? Convergence and the power method

    Eigenvalue 1 exists and the others have size at most 1. If every other eigenvalue has size strictly less than 1, repeated multiplication kills their parts and leaves only the eigenvalue-1 part. This is the “apply it 100 times” idea of chapter 2.8.

    Theorem B Strang 10.3; Bryan and Leise, section 4

    Convergence for a diagonalizable chain with a simple eigenvalue 1

    Suppose PP is stochastic and diagonalizable, with eigenvalues 1,λ2,…,λn1, \lambda_2, \dots, \lambda_n where ∣λi∣<1|\lambda_i| < 1 for i≥2i \ge 2. Then there is exactly one stationary distribution π\pi, and for every probability vector x0x_0,

    Pkx0→πas k→∞,with error of size about ∣λ2∣k,P^kx_0 \to \pi \quad\text{as } k \to \infty, \qquad\text{with error of size about } |\lambda_2|^k,

    where λ2\lambda_2 is the eigenvalue of largest size among the others.

    In one lineLet PP be stochastic and diagonalizable. If 11 is an eigenvalue with a one-dimensional eigenspace and every other eigenvalue has size less than 1, then Pkx0P^kx_0 approaches the same stationary distribution π\pi from every starting probability vector x0x_0.

    Why it is trueWrite x0x_0 in the eigenvectors. Applying PP kk times multiplies the part along each eigenvector by λk\lambda^k. The parts with ∣λ∣|\lambda| less than 1 die away, and only the part along π\pi is left.

    ProofStrang 10.3
    The idea: Expand x0 in an eigenbasis. The coefficient of the eigenvalue-1 part is forced to be 1 by the fact that probability is conserved (the lemma). Every other part is multiplied by lambda to the k, which goes to 0.
    Let v1,…,vnv_1, \dots, v_n be an eigenbasis, λ1=1\lambda_1 = 1.
    PP is diagonalizable (2.8), so there is a basis of eigenvectors v1,…,vnv_1, \dots, v_n of Cn\mathbb C^n with Pvi=λiviPv_i = \lambda_iv_i. We take λ1=1\lambda_1 = 1, with eigenvector v1v_1. The eigenvalues are complex numbers in general.
    The entries of viv_i add to 00 for i≥2i \ge 2.
    By the lemma, 1Tvi=0\mathbf 1^{\mathsf T}v_i = 0 for i≥2i \ge 2, because λi≠1\lambda_i \ne 1.
    So 1Tv1≠0\mathbf 1^{\mathsf T}v_1 \ne 0. Rescale v1v_1 (dividing by the number 1Tv1\mathbf 1^{\mathsf T}v_1) so that its entries add to 1, and call it π\pi. We show in the last step that π\pi is real.
    If also 1Tv1=0\mathbf 1^{\mathsf T}v_1 = 0, then 1T\mathbf 1^{\mathsf T} would vanish on a whole basis, hence on every vector. But 1T1=n≠0\mathbf 1^{\mathsf T}\mathbf 1 = n \ne 0.This is the quiet step that makes the proof work.
    x0=c1π+c2v2+⋯+cnvnx_0 = c_1\pi + c_2v_2 + \dots + c_nv_n.
    Every vector is a combination of a basis (2.2).
    1=c11 = c_1.
    Apply 1T\mathbf 1^{\mathsf T}. The left side is 11 (probability vector). On the right, the terms with i≥2i \ge 2 vanish, and 1Tπ=1\mathbf 1^{\mathsf T}\pi = 1.
    Pkx0=π+c2λ2kv2+⋯+cnλnkvnP^kx_0 = \pi + c_2\lambda_2^kv_2 + \dots + c_n\lambda_n^kv_n.
    Apply PP kk times; Pkvi=λikviP^kv_i = \lambda_i^kv_i because each application multiplies by λi\lambda_i.
    As k→∞k \to \infty, every term after the first goes to OO, so Pkx0→πP^kx_0 \to \pi.
    ∣λi∣<1|\lambda_i| < 1 for i≥2i \ge 2, so λik→0\lambda_i^k \to 0 (a geometric sequence with ratio of size less than 1). The error is dominated by the largest ∣λi∣|\lambda_i|.
    π\pi is a stationary distribution, and it is the only one.
    Every Pkx0P^kx_0 is a real probability vector (the first theorem of this chapter), and a limit of such vectors is real, has entries at least 00 and adds to 1. So π\pi is a probability vector. Applying PP to both sides of Pkx0→πP^kx_0 \to \pi gives Pπ=πP\pi = \pi. Uniqueness: any stationary distribution π′\pi' satisfies Pkπ′=π′P^k\pi' = \pi', so by the above it also tends to π\pi.
    Why· The picture behind the proof

    Press Next in the first visualizer again and watch the bars. The starting bars are one tall bar on page 1. Each step keeps the total height and removes a little more of the “wobble”, the part along the other eigenvectors, which has total height zero (it has bars above and below the stationary heights). The wobble shrinks by a factor of ∣λ2∣≈0.55|\lambda_2| \approx 0.55 at each step for this web, which is why about eight to ten steps leave bars that look still. The numbers are in the power-method example below.

    Definition B

    Power method

    The power method for a matrix AA chooses a starting vector x0x_0 and computes xk+1=Axkx_{k+1} = Ax_k (in general, rescaling each result to keep its size under control). If the eigenvalue of largest size is unique and the starting vector has a component along its eigenvector, the iterates line up with that eigenvector, at the rate ∣λ2/λ1∣k|\lambda_2/\lambda_1|^k. For a stochastic matrix and a probability vector no rescaling is needed, since PxPx is again a probability vector, and the eigenvalue of largest size is 11.

    In one lineFind the dominant eigenvector by starting anywhere and applying the matrix again and again.

    Why it existsIt computes the eigenvector using only matrix-times-vector, which is cheap even when the matrix is enormous and never written down in full.

    Worked example Bryan and Leise's example; the visualizer above
    Run the power method on the four-page web from x0=(1,0,0,0)x_0 = (1, 0, 0, 0), and watch the error shrink.

    Solution.

    1. Start. x0=(1,0,0,0)x_0 = (1, 0, 0, 0), so the surfer is on page 1. The 1-norm distance to π=(12,4,9,6)/31\pi = (12, 4, 9, 6)/31 is about 1.2261.226. We measure the error as ∥xk−π∥1\lVert x_k - \pi \rVert_1, the sum of the absolute differences of the entries.
    2. Apply PP once. x1=Px0=(0,13,13,13)x_1 = Px_0 = (0, \tfrac13, \tfrac13, \tfrac13), error ≈0.774\approx 0.774. Applying PP to e1e_1 picks out column 1: page 1 sends a third of the surfer to each of pages 2, 3, 4.
    3. Apply PP again. x2=(12,0,13,16)x_2 = (\tfrac12, 0, \tfrac13, \tfrac16), error ≈0.312\approx 0.312. Page 1 receives all of page 3’s 13\tfrac13 and half of page 4’s 13\tfrac13, which is 13+16=12\tfrac13 + \tfrac16 = \tfrac12. Page 2 receives nothing, since only page 1 links to it and page 1 is empty.
    4. Keep going. x3=(512,16,14,16)x_3 = (\tfrac5{12}, \tfrac16, \tfrac14, \tfrac16) with error ≈0.134\approx 0.134, and x4=(13,536,1136,29)x_4 = (\tfrac13, \tfrac5{36}, \tfrac{11}{36}, \tfrac29) with error ≈0.108\approx 0.108. The entries rise and fall around the final values, because two of the other three eigenvalues of PP are complex and make their part of the error rotate as it shrinks.
    5. Read the rate. x7=(55144,55432,127432,85432)x_7 = (\tfrac{55}{144}, \tfrac{55}{432}, \tfrac{127}{432}, \tfrac{85}{432}) has error ≈0.0137\approx 0.0137, and x12≈(0.3866,0.1292,0.2904,0.1938)x_{12} \approx (0.3866, 0.1292, 0.2904, 0.1938) has error ≈0.00095\approx 0.00095. Over steps 4 to 7 the error shrinks by about 0.50.5 per step, close to ∣λ2∣≈0.547|\lambda_2| \approx 0.547. The eigenvalues other than 11 are the roots of 12λ3+12λ2+6λ+112\lambda^3 + 12\lambda^2 + 6\lambda + 1, about −0.279-0.279 and −0.361±0.411i-0.361 \pm 0.411i.
    6. Verify the limit exactly. Pπ=131(9+3, 4, 4+2+3, 4+2)=131(12,4,9,6)=πP\pi = \tfrac1{31}(9 + 3,\ 4,\ 4 + 2 + 3,\ 4 + 2) = \tfrac1{31}(12, 4, 9, 6) = \pi. One application of PP to π\pi in exact arithmetic leaves it unchanged, so π\pi is stationary.

    The step-through below shows the same iteration with the exact fractions.

    Answer. The iterates approach (12,4,9,6)/31(12, 4, 9, 6)/31. A web of billions of pages needs the same steps; what changes is that each application of PP costs about one operation per link, not one per pair of pages.

    Python labThe power method on the four-page web, and the Google matrix
    import numpy as np
    
    # Column j lists where a surfer on page j goes next (Bryan and Leise's web).
    P = np.array([[0,   0,   1, 1/2],
                  [1/3, 0,   0, 0  ],
                  [1/3, 1/2, 0, 1/2],
                  [1/3, 1/2, 0, 0  ]])
    exact = np.array([12, 4, 9, 6]) / 31
    
    x = np.array([1.0, 0, 0, 0])            # start on page 1
    for k in range(0, 31, 5):
        print(f"step {k:2d}: x = {np.round(x, 4)}   error = {np.abs(x - exact).sum():.2e}")
        for _ in range(5):
            x = P @ x
    
    vals = np.linalg.eigvals(P)
    print("eigenvalue sizes:", np.round(sorted(abs(vals), reverse=True), 4))
    
    d, n = 0.85, 4                          # the Google matrix: follow a link with probability d
    G = d * P + (1 - d) / n * np.ones((n, n))
    x = np.ones(n) / n
    for _ in range(100):
        x = G @ x
    print("PageRank with d = 0.85:", np.round(x, 4))

    Try this. The error shrinks by a factor of about 0.04850.0485 every five steps. Check that this is 0.546850.5468^5, where 0.54680.5468 is the second largest eigenvalue size printed at the end: the rate ∣λ2/λ1∣k|\lambda_2/\lambda_1|^k from the text. Then change d to 0.50.5 and see the ranking move toward equal shares, and add a fifth page that links only to page 1.

    Your answerIn the four-page web, a surfer has the chances x=(12,0,13,16)x = (\tfrac12, 0, \tfrac13, \tfrac16). What is entry 3 of PxPx, the chance of being on page 3 one step later?
    Worked example
    A walker moves on the graph with vertices 1, 2, 3, 4 and edges 12, 23, 34, 41, 13, each step to a uniformly random neighbour. Write P, find the stationary distribution, and say whether the walker's chances settle.

    Solution.

    1. List the neighbours. Vertex 1 has neighbours 2, 3, 4. Vertex 2 has 1, 3. Vertex 3 has 2, 4, 1. Vertex 4 has 3, 1. Read each vertex’s edges from the list.
    2. Write the columns. Column jj puts 1/deg⁡j1/\deg j on each neighbour of jj: column 1 is (0,13,13,13)(0, \tfrac13, \tfrac13, \tfrac13), column 2 is (12,0,12,0)(\tfrac12, 0, \tfrac12, 0), column 3 is (13,13,0,13)(\tfrac13, \tfrac13, 0, \tfrac13), column 4 is (12,0,12,0)(\tfrac12, 0, \tfrac12, 0). From a vertex with ℓ\ell neighbours each neighbour has chance 1/ℓ1/\ell. Each column adds to 11.
    3. Use the degree rule. The degrees are 3,2,3,23, 2, 3, 2, adding to 10=2×510 = 2 \times 5 edges. So π=(3,2,3,2)/10\pi = (3, 2, 3, 2)/10. On an undirected graph the walker visits each vertex in proportion to its degree (proved in the “Where it is used” section).
    4. Check it. Row 1 of PπP\pi is 12π2+13π3+12π4=110+110+110=310\tfrac12\pi_2 + \tfrac13\pi_3 + \tfrac12\pi_4 = \tfrac1{10} + \tfrac1{10} + \tfrac1{10} = \tfrac3{10}. Row 2 is 13π1+13π3=210\tfrac13\pi_1 + \tfrac13\pi_3 = \tfrac2{10}. Multiplying back is the check that does not depend on the rule being remembered correctly.
    5. Decide about settling. The graph has triangles (1,2,31, 2, 3 and 1,3,41, 3, 4), so the walker can return in 2 or 3 steps, and the chain is not stuck in a lockstep cycle. The eigenvalues are 11, −13-\tfrac13, −23-\tfrac23 and 00, all other than 11 of size less than 11. Contrast with the path 1−2−31 - 2 - 3, where the walker alternates between the middle and the ends and the eigenvalue −1-1 never fades.

    Answer. π=(3,2,3,2)/10\pi = (3, 2, 3, 2)/10, and Pkx0→πP^kx_0 \to \pi from every start, at the rate (23)k(\tfrac23)^k.

    Your answerA walker on an undirected graph with 5 edges has stationary distribution πv=deg⁡(v)/10\pi_v = \deg(v)/10. What is πv\pi_v for a vertex of degree 3?

    Now the theorem that says when the hypotheses hold. It is the major result of this area, and we state it without proof.

    Theorem B Perron 1907, Frobenius 1912; Bryan and Leise, section 4 (proof not given here)

    Perron–Frobenius theorem for regular chains

    Call a stochastic matrix regular if some power PmP^m has every entry strictly positive (every state can reach every state in exactly mm steps). For a regular PP, there is exactly one stationary distribution π\pi, all of its entries are positive, every eigenvalue other than 11 has size less than 11, and Pkx0→πP^kx_0 \to \pi for every probability vector x0x_0.

    In one lineIf some power of the stochastic matrix PP has all entries strictly positive (a regular chain), then 11 is a simple eigenvalue with a positive eigenvector, every other eigenvalue has size less than 1, and Pkx0→πP^kx_0 \to \pi for every probability vector x0x_0.

    Why it is truePositive entries mean every state can reach every other, and in a way that mixes time well enough to forget the start. That removes the ways the conclusion can fail.

    We do not prove this theorem. It is a result of Perron (1907) for positive matrices, extended by Frobenius (1912). Diagonalizability is not needed. The proof without it uses the Jordan form, which is beyond this chapter. For positive matrices there is a short idea behind the size claim, and it reuses the proof that ∣λ∣≤1|\lambda| \le 1.

    Beyond the course: for understanding· Why positive entries push the other eigenvalues strictly inside (a sketch)

    In the proof that ∥Px∥1≤∥x∥1\lVert Px \rVert_1 \le \lVert x \rVert_1, equality needs equality in every triangle inequality ∣∑jPijxj∣≤∑jPij∣xj∣\big|\sum_j P_{ij}x_j\big| \le \sum_j P_{ij}|x_j|. For complex numbers, this holds only if all the non-zero terms PijxjP_{ij}x_j point in the same direction in the complex plane. If every PijP_{ij} is positive, that means all entries xjx_j of the vector point in the same direction. Rotate the vector so they are all real and at least 00. Then PxPx is also real and non-negative, so Px=λxPx = \lambda x forces λ≥0\lambda \ge 0, and the equality of norms forces λ=1\lambda = 1. So an eigenvalue of size exactly 1 must be 11 itself, and its eigenvector can be taken positive. An eigenvector with mixed signs loses norm at every step: that is the “wobble” shrinking in the picture. For a regular chain, apply the same argument to the positive matrix PmP^m. It shows that an eigenvalue λ\lambda of PP with ∣λ∣=1|\lambda| = 1 has λm=1\lambda^m = 1. To get λ=1\lambda = 1 one more fact is needed, that 11 is a simple eigenvalue. This is a sketch of the main idea. It leaves out why 11 is a simple eigenvalue, that last step, and the case without diagonalizability.

    Quick checkPP is the stochastic matrix that swaps the two entries of a vector (columns (0,1)(0, 1) and (1,0)(1, 0)), and the surfer starts at x0=(1,0)x_0 = (1, 0). What happens to Pkx0P^kx_0?

    What goes wrong on the real web

    Where this came from· Page, Brin and the random surfer

    In 1996 Larry Page and Sergey Brin, then students at Stanford, began work on ranking web pages by importance, as well as by whether they contained the search words. They borrowed an idea from scholarly citations: a page is important if important pages link to it. That sentence is circular. The way out was the surfer who follows links at random, so that importance becomes a stationary distribution. Brin and Page’s 1998 paper on the Google search engine gives d=0.85d = 0.85 as the usual damping factor, and the Stanford technical report of the same year by Page, Brin, Rajeev Motwani and Terry Winograd describes the ranking itself. The patent, granted in 2001 with Page as inventor, belongs to Stanford, and Google, founded in 1998, held an exclusive licence.

    The picture works for the four-page web. The real web has features that break the hypotheses, and each is shown below with a small example. One idea fixes all of them.

    • Dead ends (dangling pages). A page with no links has a zero column, so PP is not stochastic. A surfer reaching it vanishes: for pages 1→21 \to 2 and a dead-end page 2, xk→(0,0)x_k \to (0, 0). Probability leaks out.
    • Cycles in lockstep (periodicity). Pages 1↔21 \leftrightarrow 2 swap the surfer forever. The eigenvalue −1-1 never fades, and the chances never settle.
    • Disconnected pieces. If pages {1,2}\{1, 2\} link only to each other and {3,4}\{3, 4\} link only to each other, then every mixture of the two pieces’ stationary vectors is stationary. The ranking is not unique.
    • Spider traps. A page that links only to itself (or a small group that only links to itself) absorbs the surfer for good. With pages 1→2,31 \to 2, 3; 2→12 \to 1; 3→33 \to 3, the only stationary distribution is (0,0,1)(0, 0, 1): page 3 gets all the rank and the others get nothing.

    Google’s fix is to make the surfer occasionally bored. This is the matrix.

    Definition B

    Google matrix

    Let PP be stochastic (first replace every zero column, from a dead-end page, by the column (1n,…,1n)(\tfrac1n, \dots, \tfrac1n): a stuck surfer jumps to a random page). Choose a damping factor dd with 0≤d<10 \le d < 1. The Google matrix is

    G=d P+1−dn 11T,G = d\,P + \frac{1 - d}{n}\,\mathbf 1\mathbf 1^{\mathsf T},

    where 11T\mathbf 1\mathbf 1^{\mathsf T} is the n×nn \times n matrix with every entry 11. So Gij=dPij+1−dnG_{ij} = dP_{ij} + \tfrac{1-d}{n}. Page and Brin’s papers use d=0.85d = 0.85: the surfer follows a link 85 times in 100 and teleports 15 times in 100.

    In one lineG=dP+1−dn11TG = dP + \tfrac{1-d}{n}\mathbf 1\mathbf 1^{\mathsf T}: with chance dd the surfer follows a link, and with chance 1−d1 - d jumps to a page chosen uniformly at random.

    Why it existsThe random jumps connect every page to every page, so none of the failures above can happen, and a unique ranking always exists.

    Each column of GG adds to d⋅1+n⋅1−dn=1d \cdot 1 + n \cdot \tfrac{1-d}{n} = 1, so GG is stochastic. Every entry is at least 1−dn>0\tfrac{1-d}{n} > 0, so GG is regular (already G1G^1 is positive). By Perron–Frobenius, which we did not prove, GG has a unique stationary distribution. For this matrix we can prove everything we need directly, and get a speed guarantee at the same time.

    Theorem B Haveliwala and Kamvar (2003) for the rate; Bryan and Leise, section 5

    The Google matrix has a unique stationary distribution

    Let PP be stochastic, 0≤d<10 \le d < 1, and G=dP+1−dn11TG = dP + \tfrac{1-d}{n}\mathbf 1\mathbf 1^{\mathsf T}. Then:

    1. GG is stochastic with every entry at least 1−dn\tfrac{1-d}{n}.
    2. GG has a stationary distribution π\pi, and every entry of π\pi is at least 1−dn\tfrac{1-d}{n}.
    3. For every probability vector x0x_0 and every kk, ∥Gkx0−π∥1≤2dk\lVert G^kx_0 - \pi \rVert_1 \le 2d^k. In particular π\pi is the only stationary distribution.
    4. Every eigenvalue λ≠1\lambda \ne 1 of GG has ∣λ∣≤d|\lambda| \le d.

    In one lineFor 0≤d<10 \le d < 1, GG has exactly one stationary distribution π\pi, all its entries are at least 1−dn\tfrac{1-d}{n}, and from any starting probability vector ∥Gkx0−π∥1≤2dk\lVert G^kx_0 - \pi \rVert_1 \le 2d^k. Every eigenvalue other than 11 has size at most dd.

    Why it is trueOn vectors whose entries add to zero, the teleport part of GG vanishes and GG acts as dd times PP. So the wobble shrinks by at least a factor dd per step, whatever the web looks like.

    ProofBryan and Leise section 5; Haveliwala and Kamvar
    The idea: Existence: the eigenvalue-1 theorem plus a sign argument. Convergence: the difference of two probability vectors adds to zero, and on such vectors G is d times P, which never increases the 1-norm.
    GG is stochastic with all entries positive.
    Part 1. Each column of GG adds to d⋅1+n⋅1−dn=1d \cdot 1 + n \cdot \tfrac{1-d}{n} = 1, and each entry is dPij+1−dn≥1−dndP_{ij} + \tfrac{1-d}{n} \ge \tfrac{1-d}{n}.
    Take a real v≠Ov \ne O with Gv=vGv = v.
    Part 2. By the eigenvalue-1 theorem GG has a non-zero real vv with Gv=vGv = v.
    Suppose vv has entries of both signs. Then ∣vi∣=∣(Gv)i∣<∑jGij∣vj∣|v_i| = |(Gv)_i| < \sum_j G_{ij}|v_j| for every ii.
    Suppose, for contradiction, that vv has an entry above 00 and an entry below 00. In every row ii, the term with the negative entry vkv_k satisfies Gikvk<Gik∣vk∣G_{ik}v_k < G_{ik}|v_k| because Gik>0G_{ik} > 0 (strictly). So ∣∑jGijvj∣<∑jGij∣vj∣\big|\sum_j G_{ij}v_j\big| < \sum_j G_{ij}|v_j| in every row: the positive and negative terms cancel a little.
    Then ∥v∥1<∑j∣vj∣∑iGij=∥v∥1\lVert v \rVert_1 < \sum_j |v_j|\sum_i G_{ij} = \lVert v \rVert_1, which is absurd.
    Add over ii, swap the sums, and use that the columns of GG add to 1 (the computation from the 1-norm theorem, now with strict inequality).
    So vv can be taken non-negative, and rescaled to a stationary distribution π\pi.
    So all entries of vv have the same sign (some may be zero). Replace vv by −v-v if needed, so that v≥0v \ge 0 with v≠Ov \ne O. Then its entries add to a positive number, and dividing by it gives a probability vector π\pi with Gπ=πG\pi = \pi.
    Every πi≥1−dn>0\pi_i \ge \tfrac{1-d}{n} > 0.
    Since Gπ=πG\pi = \pi and π\pi adds to 1, each entry is πi=(Gπ)i=∑jGijπj≥1−dn∑jπj\pi_i = (G\pi)_i = \sum_j G_{ij}\pi_j \ge \tfrac{1-d}{n}\sum_j\pi_j.
    Gy=dPyGy = dPy.
    Part 3. Let yy be any vector whose entries add to 00. Then 11Ty=1 (1Ty)=O\mathbf 1\mathbf 1^{\mathsf T}y = \mathbf 1\,(\mathbf 1^{\mathsf T}y) = O, the teleport part sees nothing.This is the heart of the proof: the damping splits G into 'follow a link' (scaled by d) and 'teleport', and the difference of two probability vectors is invisible to teleporting.
    Gky=dkPkyG^ky = d^kP^ky, and ∥Gky∥1≤dk∥y∥1\lVert G^ky \rVert_1 \le d^k\lVert y \rVert_1.
    1T(Py)=1Ty=0\mathbf 1^{\mathsf T}(Py) = \mathbf 1^{\mathsf T}y = 0, so PyPy also adds to 00. Repeating the step kk times, and using ∥Pz∥1≤∥z∥1\lVert Pz \rVert_1 \le \lVert z \rVert_1 each time, gives the bound.
    ∥Gkx0−π∥1=∥Gk(x0−π)∥1≤2dk\lVert G^kx_0 - \pi \rVert_1 = \lVert G^k(x_0 - \pi) \rVert_1 \le 2d^k.
    y=x0−πy = x_0 - \pi adds to 1−1=01 - 1 = 0, and Gkπ=πG^k\pi = \pi. The triangle inequality gives ∥x0−π∥1≤∥x0∥1+∥π∥1=2\lVert x_0 - \pi \rVert_1 \le \lVert x_0 \rVert_1 + \lVert \pi \rVert_1 = 2.
    The stationary distribution is unique.
    If π′\pi' is also stationary, then Gkπ′=π′G^k\pi' = \pi', so ∥π′−π∥1≤2dk\lVert \pi' - \pi \rVert_1 \le 2d^k for every kk. This tends to 00, so π′=π\pi' = \pi.
    ∣λ∣ ∥v∥1=d ∥Pv∥1≤d ∥v∥1|\lambda|\,\lVert v \rVert_1 = d\,\lVert Pv \rVert_1 \le d\,\lVert v \rVert_1, so ∣λ∣≤d|\lambda| \le d.
    Part 4. If Gv=λvGv = \lambda v with λ≠1\lambda \ne 1, then 1Tv=0\mathbf 1^{\mathsf T}v = 0 by the lemma, so λv=Gv=dPv\lambda v = Gv = dPv. Take 1-norms and use the bound ∥Pv∥1≤∥v∥1\lVert Pv \rVert_1 \le \lVert v \rVert_1.
    Proof workshopRebuild the speed bound: the Google chain forgets its start at least as fast as d to the k

    Tap the lines in the order a proof would write them. Each line can only use what is already above it.

      Why· The picture behind the proof

      Turn on the damping slider in the visualizer below. At d=1d = 1 you get the undamped web. Lower dd and the stationary bars flatten toward equal heights, because more of the surfer’s time is spent teleporting. At d=0.85d = 0.85 the bars become (0.368,0.142,0.288,0.202)(0.368, 0.142, 0.288, 0.202) instead of (0.387,0.129,0.290,0.194)(0.387, 0.129, 0.290, 0.194): pages ranked low gain a little, high-ranked pages lose a little. Step through with the slider at a small dd and the bars settle in very few steps; at dd near 11 they take longer. That is the bound 2dk2d^k in motion: damping is the price paid for speed and uniqueness.

      Quick checkWhy does the damping factor guarantee a unique ranking and fast convergence?

      How fast is 2dk2d^k for d=0.85d = 0.85? 0.8550≈3.0×10−40.85^{50} \approx 3.0 \times 10^{-4} and 0.85100≈8.7×10−80.85^{100} \approx 8.7 \times 10^{-8}. The bound does not depend on the number of pages. This is the answer to Spagnolie’s “how can you even compute?!”. Page, Brin, Motwani and Winograd (1998) report that for a web of 322 million links, the iteration converged to a tolerable limit in about 52 steps. Two facts make each step cheap. First, PP is sparse: a page has maybe tens of links, so PxPx costs about one operation per link, not n2n^2. Second, one never builds the dense matrix GG: for a probability vector xx,

      Gx=d Px+1−dn 1 (1Tx)=d Px+1−dn 1,Gx = d\,Px + \frac{1-d}{n}\,\mathbf 1\,(\mathbf 1^{\mathsf T}x) = d\,Px + \frac{1-d}{n}\,\mathbf 1 ,

      so a step of the damped chain is a step of the sparse chain, scaled by dd, plus the same small number added to every page.

      Worked example
      Let G = dP + ((1 − d)/n)·1·1ᵀ with P stochastic. Prove that for every probability vector x, Gx = dPx + ((1 − d)/n)·1, and that Gx is a probability vector.

      Solution.

      1. Split the product. Gx=dPx+1−dn1(1Tx)Gx = dPx + \tfrac{1-d}{n}\mathbf 1(\mathbf 1^{\mathsf T}x). Matrix multiplication distributes over the sum, and we group 11Tx\mathbf 1\mathbf 1^{\mathsf T}x as 1(1Tx)\mathbf 1(\mathbf 1^{\mathsf T}x), which is allowed because matrix multiplication is associative.
      2. Evaluate the bracket. 1Tx\mathbf 1^{\mathsf T}x is the sum of the entries of xx, which is 11. xx is a probability vector.
      3. Conclude the formula. Gx=dPx+1−dn1Gx = dPx + \tfrac{1-d}{n}\mathbf 1. Replace the bracket by 11. The dense matrix GG never needs to be written down.
      4. Entries are non-negative. PxPx has entries at least 00 and 0≤d<10 \le d < 1, and the added number 1−dn\tfrac{1-d}{n} is positive. Sums and products of non-negative numbers are non-negative.
      5. Entries add to 1. The entries of dPxdPx add to d⋅1d\cdot1 because PxPx is a probability vector. The added vector contributes n⋅1−dn=1−dn\cdot\tfrac{1-d}{n} = 1 - d. The total is d+(1−d)=1d + (1 - d) = 1. This is the stochastic-matrix theorem for PP, plus counting nn equal entries.

      Answer. Gx=dPx+1−dn1Gx = dPx + \tfrac{1-d}{n}\mathbf 1, and GxGx is a probability vector.

      Your answerThe Google matrix for n=4n = 4 pages with d=0.85d = 0.85 has Gij=0.85 Pij+0.154G_{ij} = 0.85\,P_{ij} + \tfrac{0.15}{4}. If P21=13P_{21} = \tfrac13, what is G21G_{21} (to 4 decimal places is plenty)?
      Your answerFor the Google matrix with d=0.9d = 0.9, the bound ∥Gkx0−π∥1≤2dk\lVert G^kx_0 - \pi \rVert_1 \le 2d^k holds. What is the smallest whole number kk for which the bound is below 0.010.01?
      Worked example
      Find the PageRank vector of the three-page web (1 links to 2 and 3; 2 links to 3; 3 links to 1) with damping factor d=34d = \tfrac34.

      Solution.

      1. State what to solve. Gπ=πG\pi = \pi with 1Tπ=1\mathbf 1^{\mathsf T}\pi = 1. Since Gπ=d Pπ+1−dn1G\pi = d\,P\pi + \tfrac{1-d}{n}\mathbf 1 for a probability vector, this is (I−dP)π=1−dn1=1121(I - dP)\pi = \tfrac{1-d}{n}\mathbf 1 = \tfrac1{12}\mathbf 1. Using the shortcut for GxGx avoids writing the full GG. Here n=3n = 3 and 1−d=141 - d = \tfrac14.
      2. Write the three equations, with PP from the first example: π1−34π3=112\pi_1 - \tfrac34\pi_3 = \tfrac1{12},  π2−38π1=112\ \pi_2 - \tfrac38\pi_1 = \tfrac1{12},  π3−38π1−34π2=112\ \pi_3 - \tfrac38\pi_1 - \tfrac34\pi_2 = \tfrac1{12}. Row ii of PP lists which pages send surfers to page ii. Page 1 receives all of page 3; page 2 receives half of page 1; page 3 receives half of page 1 and all of page 2.
      3. Express π1\pi_1 and π2\pi_2 in terms of π3\pi_3. π1=112+34π3\pi_1 = \tfrac1{12} + \tfrac34\pi_3. Then π2=112+38π1=1196+932π3\pi_2 = \tfrac1{12} + \tfrac38\pi_1 = \tfrac{11}{96} + \tfrac9{32}\pi_3. Equations 1 and 2 solve for the first two unknowns directly.
      4. Substitute into equation 3. π3=112+38(112+34π3)+34(1196+932π3)\pi_3 = \tfrac1{12} + \tfrac38\big(\tfrac1{12} + \tfrac34\pi_3\big) + \tfrac34\big(\tfrac{11}{96} + \tfrac9{32}\pi_3\big). The constants add to 112+132+11128=77384\tfrac1{12} + \tfrac1{32} + \tfrac{11}{128} = \tfrac{77}{384}, and the π3\pi_3 terms to 932π3+27128π3=63128π3\tfrac9{32}\pi_3 + \tfrac{27}{128}\pi_3 = \tfrac{63}{128}\pi_3. Common denominator 384384 for the constants: 32+12+33=7732 + 12 + 33 = 77.
      5. Solve for π3\pi_3. (1−63128)π3=77384\big(1 - \tfrac{63}{128}\big)\pi_3 = \tfrac{77}{384}, so 65128π3=77384\tfrac{65}{128}\pi_3 = \tfrac{77}{384} and π3=77195\pi_3 = \tfrac{77}{195}. Multiply both sides by 12865\tfrac{128}{65}.
      6. Back-substitute. π1=112+34⋅77195=74195\pi_1 = \tfrac1{12} + \tfrac34 \cdot \tfrac{77}{195} = \tfrac{74}{195} and π2=1196+932⋅77195=44195\pi_2 = \tfrac{11}{96} + \tfrac9{32} \cdot \tfrac{77}{195} = \tfrac{44}{195}. Plug π3\pi_3 into the formulas of step 3.
      7. Check. 74+44+77195=1\tfrac{74 + 44 + 77}{195} = 1, and every entry is at least 1−dn=112≈0.083\tfrac{1-d}{n} = \tfrac1{12} \approx 0.083. The theorem promises a probability vector with entries at least 1−dn\tfrac{1-d}{n}.

      Answer. π=(74,44,77)/195≈(0.379,0.226,0.395)\pi = (74, 44, 77)/195 \approx (0.379, 0.226, 0.395). Compare the undamped ranking (2,1,2)/5=(0.4,0.2,0.4)(2, 1, 2)/5 = (0.4, 0.2, 0.4): damping pulls the answer toward equal shares. (The undamped matrix has eigenvalues 11 and −1±i2\tfrac{-1 \pm i}{2}, which have size 0.7070.707.)

      Worked example
      A spider trap: page 1 links to 2 and 3, page 2 links to 1, page 3 links only to itself. Find the undamped stationary distribution and the PageRank with d=0.85d = 0.85.

      Solution.

      1. Write PP. P=[01012001201]P = \begin{bmatrix} 0 & 1 & 0 \\ \tfrac12 & 0 & 0 \\ \tfrac12 & 0 & 1 \end{bmatrix}. Column 3 is (0,0,1)(0, 0, 1) because page 3 sends the surfer back to itself.
      2. Undamped stationary vectors. Pπ=πP\pi = \pi: the first equation is π1=π2\pi_1 = \pi_2, the second is π2=12π1\pi_2 = \tfrac12\pi_1. Together, π1=π2=0\pi_1 = \pi_2 = 0. The third equation then holds for any π3\pi_3, and π3=1\pi_3 = 1. Page 1 and 2 keep losing half their chance to page 3, which never returns it.
      3. Read the meaning. π=(0,0,1)\pi = (0, 0, 1): page 3 gets all the rank. Starting anywhere, the surfer ends in the trap. The trap is a set of pages with no links out, which breaks the “every page can reach every page” requirement.
      4. Damp it. Solve (I−0.85P)π=0.1531(I - 0.85P)\pi = \tfrac{0.15}{3}\mathbf 1 exactly. The solution is π=(74,57,380)/511≈(0.145,0.112,0.744)\pi = (74, 57, 380)/511 \approx (0.145, 0.112, 0.744). The same method as the previous example, with d=17/20d = 17/20; the unique solution is guaranteed by the theorem. Check: 74+57+380=51174 + 57 + 380 = 511 and every entry exceeds 0.050.05.

      Answer. Undamped: (0,0,1)(0, 0, 1). Damped with d=0.85d = 0.85: about (0.145,0.112,0.744)(0.145, 0.112, 0.744). Damping lets the other pages keep a share. The trap still takes about three quarters of the rank. Real search engines had to deal with exactly this: people built groups of pages that link only to each other to inflate their rank, which is why ranking involves much more than this one matrix.

      Examples and non-examples

      The worked examples sit beside the ideas they practise, above. A few more.

      A non-example: a vector that is stationary but not reached. For P=[0110]P = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}, the vector (12,12)(\tfrac12, \tfrac12) is stationary, and it is a probability vector. But Pkx0P^kx_0 does not approach it from x0=(1,0)x_0 = (1, 0), because the eigenvalue −1-1 does not fade. “Stationary exists” and “the chain converges to it” are different statements.

      A non-example: a matrix that is not stochastic. [0.50.20.50.7]\begin{bmatrix} 0.5 & 0.2 \\ 0.5 & 0.7 \end{bmatrix} has columns adding to 11 and 0.90.9. After many steps the total chance leaks away, and the eigenvalues are not 11 and a smaller number: the eigenvalue-1 theorem needs every column sum to be exactly 11.

      Convergence is about the matrix, not the starting point. For the four-page web every starting probability vector leads to the same π\pi, because the hypotheses hold. The visualizer starts at page 1. Starting at page 3 changes the path and leaves the limit the same.

      Where it is used

      Used inside maths· Inside maths: random walks on graphs, and the stationary distribution given by the degrees

      On an undirected graph, let a walker at a vertex move to a uniformly random neighbour. Take the graph with four vertices A,B,C,DA, B, C, D and edges ABAB, BCBC, CACA, CDCD (a triangle with a tail). The degrees (numbers of edges at each vertex) are 2,2,3,12, 2, 3, 1, adding to 88, which is twice the number of edges. Claim: πv=deg⁡(v)/8\pi_v = \deg(v)/8, that is π=(2,2,3,1)/8\pi = (2, 2, 3, 1)/8, is stationary.

      Proof for any such graph, with mm edges. The chance of going from uu to vv is 1/deg⁡(u)1/\deg(u) when u,vu, v are neighbours. So (Pπ)v=∑u∼v1deg⁡u⋅deg⁡u2m=#{u:u∼v}2m=deg⁡v2m=πv(P\pi)_v = \sum_{u \sim v}\frac{1}{\deg u}\cdot\frac{\deg u}{2m} = \frac{\#\{u : u \sim v\}}{2m} = \frac{\deg v}{2m} = \pi_v. The factor deg⁡u\deg u cancels, and the sum counts the neighbours of vv. So a walker visits a vertex in proportion to its degree. Check on the triangle with a tail: the second entry of PπP\pi is 12⋅28+13⋅38=18+18=28\tfrac12\cdot\tfrac28 + \tfrac13\cdot\tfrac38 = \tfrac18 + \tfrac18 = \tfrac28. This is the idea of the CS 240 graph chapters turned into linear algebra: the adjacency structure, scaled, is a stochastic matrix. (The chain on this graph has eigenvalues 11, −12-\tfrac12 and two others of size less than 1, so the walker’s chances settle.)

      Used in the real world· PageRank: the 25 billion dollar eigenvector

      The name PageRank plays on Larry Page’s surname as well as on “web page”. Bryan and Leise’s article (SIAM Review, 2006) is the standard mathematical account, and its title is where Spagnolie’s aside came from. The picture is the one in this chapter: the web is a directed graph, PP puts weight 1/ℓ1/\ell on each of a page’s ℓ\ell links, d=0.85d = 0.85, and the ranking is the stationary vector of GG. Each page’s score is πi\pi_i. A page with few but important links in beats a page with many obscure ones. In the worked example, page 3 had the most links in, and page 1 still came first because page 3, the most-linked page, passed its entire share to page 1.

      The real computation: about 50 to 100 sparse matrix-vector products, each costing one operation per link. At d=0.85d = 0.85 the bound 2dk2d^k is below 10−310^{-3} by k=50k = 50 whatever the size of the web, which is why the method scales to billions of pages. Search engines today combine PageRank-like scores with hundreds of other signals; the matrix described here is the original idea.

      Used in the real world· Queueing: a shop with room for two customers

      A tiny shop has room for two customers. Each minute, with chance 0.30.3 one customer walks in (if there is room), or with chance 0.50.5 one customer finishes and leaves (if anyone is there); otherwise nothing changes. The states are 0,1,20, 1, 2 customers, and

      P=[0.70.500.30.20.500.30.5].P = \begin{bmatrix} 0.7 & 0.5 & 0 \\ 0.3 & 0.2 & 0.5 \\ 0 & 0.3 & 0.5 \end{bmatrix}.

      Solving Pπ=πP\pi = \pi: the first row gives 0.3π0=0.5π10.3\pi_0 = 0.5\pi_1, so π1=0.6π0\pi_1 = 0.6\pi_0, and the last row gives 0.3π1=0.5π20.3\pi_1 = 0.5\pi_2, so π2=0.6π1=0.36π0\pi_2 = 0.6\pi_1 = 0.36\pi_0. The total is 1.96π0=11.96\pi_0 = 1, so π=(25,15,9)/49≈(0.51,0.31,0.18)\pi = (25, 15, 9)/49 \approx (0.51, 0.31, 0.18). The shop is empty half the time and full about 18 percent of the time, and the owner can find out whether a second server is worth hiring by changing the numbers and re-solving. Telephone exchanges and computer networks are analysed with the same equations, and the weather model of the worked example is a two-state version.

      Used in the real world· Generating text: the ancestor of language models (CS 532 and AI)

      Take the text “the cat sat on the mat . the cat ate the fish .” and make each distinct token a state. Count how often each token follows each token and divide by the totals. The token “the” is followed by “cat” twice, “mat” once and “fish” once, so column “the” has 12\tfrac12 for cat, 14\tfrac14 for mat and 14\tfrac14 for fish. “cat” is followed by “sat” or “ate”, each with chance 12\tfrac12. Every other token has one possible successor. Treating the text as a loop (the last ”.” leads back to “the”) makes the matrix stochastic, and its stationary distribution is exactly the word frequencies: “the” has 4/134/13, “cat” and ”.” have 2/132/13 each, and the other five tokens have 1/131/13 each. Walking the chain generates sentences like “the cat ate the mat .” that follow the statistics of the text, with no idea what they mean.

      This is an n-gram model (here a bigram, the last 1 word). Claude Shannon showed text built this way in his 1948 paper on information theory. A modern language model, which predicts the next token from the last NN tokens of its context window, is a Markov chain too, formally a chain whose state is the whole window. The states are far too many to write as a matrix, and the transition chances come from a neural network rather than a table. The object (a state, a next-state distribution, a sequence) is still the one in this chapter.

      Beyond the course: for understanding· Markov chain Monte Carlo (a mention)

      Often you want random samples from a hard distribution π\pi (a Bayesian posterior over model weights, for example), and you cannot sample from it directly. The idea of Markov chain Monte Carlo is to build a chain whose stationary distribution is π\pi and run it for a long time. The Metropolis–Hastings algorithm constructs such a chain by accepting or rejecting random moves so that the “detailed balance” condition holds (see the stretch problem below). The convergence theory is the theory of this chapter: the chain must be regular, and its second eigenvalue sets how long the walk takes to forget its start.

      Traps

      Watch out· Columns add to 1, not rows

      In this book PijP_{ij} is the chance of going from jj to ii, so the COLUMNS add to 1 and the chances are a column vector multiplied on the right. In many probability textbooks it is the other way: rows add to 1 and the chances form a row vector multiplied on the left. If you copy a formula between books, transpose it. Checking the column sums is the first thing to do with any new matrix.

      Watch out· Stationary does not mean the chain converges

      Pπ=πP\pi = \pi only says π\pi is unchanged by a step. The bouncing chain [0110]\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} has a stationary vector (12,12)(\tfrac12, \tfrac12) and never approaches it. Convergence needs the other eigenvalues to have size less than 1, which is what regularity (or damping) gives.

      Watch out· The eigenvector for 1 is of P, not of P-transpose

      The proof that 11 is an eigenvalue uses the vector 1\mathbf 1, which is an eigenvector of PTP^{\mathsf T}. It is not the stationary distribution. The stationary distribution is an eigenvector of PP itself, and it is not all ones (that would give every page the same rank). PP and PTP^{\mathsf T} share eigenvalues, not eigenvectors.

      Watch out· Do not forget to scale

      Solving (P−I)π=O(P - I)\pi = O gives a line of solutions, a null space. The stationary distribution is the one on that line whose entries add to 1. Writing (2,1)(2, 1) for the weather chain instead of (23,13)(\tfrac23, \tfrac13) is the most common slip.

      Watch out· Eigenvalues can be complex

      The three-page web has eigenvalues −1±i2\tfrac{-1 \pm i}{2}. The theorem ∣λ∣≤1|\lambda| \le 1 includes them, and this is why the proof uses the size of a complex number. Complex eigenvalues are what make the bars in the visualizer rise and fall as they settle instead of approaching monotonically.

      Watch out· Damping changes the answer

      The PageRank vector is the stationary distribution of GG, not of PP. They are different vectors (for the four pages, (0.368,0.142,0.288,0.202)(0.368, 0.142, 0.288, 0.202) against (0.387,0.129,0.290,0.194)(0.387, 0.129, 0.290, 0.194)). The damped one is the ranking that is used in practice, and the small 1−d1 - d share of random jumping is what makes it exist and be unique.

      Problems

      check

      Is [0.50.20.50.7]\begin{bmatrix} 0.5 & 0.2 \\ 0.5 & 0.7 \end{bmatrix} stochastic? Is [0.30.60.70.4]\begin{bmatrix} 0.3 & 0.6 \\ 0.7 & 0.4 \end{bmatrix}?

      Solution

      The first has column sums 1.01.0 and 0.90.9, so it is not stochastic. The second has column sums 1.01.0 and 1.01.0 and no negative entries, so it is.

      check

      Three pages: page 1 links to page 2, page 2 links to pages 1 and 3, page 3 links to page 1. Write PP, and find the surfer’s chances after one step from page 2.

      Solution

      Column 1 is (0,1,0)(0, 1, 0) (one link, to page 2). Column 2 is (12,0,12)(\tfrac12, 0, \tfrac12). Column 3 is (1,0,0)(1, 0, 0). So P=[01211000120]P = \begin{bmatrix} 0 & \tfrac12 & 1 \\ 1 & 0 & 0 \\ 0 & \tfrac12 & 0 \end{bmatrix}. Starting at x0=(0,1,0)x_0 = (0, 1, 0), x1=Px0x_1 = Px_0 is column 2: (12,0,12)(\tfrac12, 0, \tfrac12).

      check

      Find the stationary distribution of [0.90.50.10.5]\begin{bmatrix} 0.9 & 0.5 \\ 0.1 & 0.5 \end{bmatrix}.

      Solution

      (P−I)π=O(P - I)\pi = O gives −0.1π1+0.5π2=0-0.1\pi_1 + 0.5\pi_2 = 0, so π1=5π2\pi_1 = 5\pi_2. A basis vector is (5,1)(5, 1); scaled to add to 11, π=(56,16)\pi = (\tfrac56, \tfrac16). Check: 0.9⋅56+0.5⋅16=4.5+0.56=560.9 \cdot \tfrac56 + 0.5 \cdot \tfrac16 = \tfrac{4.5 + 0.5}{6} = \tfrac56.

      use

      For P=[0.70.20.30.8]P = \begin{bmatrix} 0.7 & 0.2 \\ 0.3 & 0.8 \end{bmatrix} find the stationary distribution, the other eigenvalue, and a formula for xkx_k starting from x0=(1,0)x_0 = (1, 0).

      Solution

      (P−I)π=O(P - I)\pi = O gives −0.3π1+0.2π2=0-0.3\pi_1 + 0.2\pi_2 = 0, so π2=1.5π1\pi_2 = 1.5\pi_1; the vector (2,3)(2, 3) scaled to sum 11 is π=(0.4,0.6)\pi = (0.4, 0.6). The trace is 1.51.5, so the other eigenvalue is 0.50.5, with eigenvector (1,−1)(1, -1) (check: P(1,−1)=(0.5,−0.5)P(1, -1) = (0.5, -0.5)). Write x0=(1,0)=π+0.6 (1,−1)x_0 = (1, 0) = \pi + 0.6\,(1, -1). Then xk=π+0.6 (0.5)k(1,−1)=(0.4+0.6⋅0.5k, 0.6−0.6⋅0.5k)x_k = \pi + 0.6\,(0.5)^k(1, -1) = (0.4 + 0.6\cdot 0.5^k,\ 0.6 - 0.6\cdot 0.5^k). Check k=1k = 1: (0.7,0.3)(0.7, 0.3), the first column of PP.

      use

      A walker on the path with three vertices 1−2−31 - 2 - 3 moves to a uniformly random neighbour. Write PP, find the stationary distribution, and say what happens to Pkx0P^kx_0 from x0=(1,0,0)x_0 = (1, 0, 0).

      Solution

      Vertex 1 has one neighbour (2), vertex 2 has neighbours 1 and 3, vertex 3 has one neighbour (2). So P=[01201010120]P = \begin{bmatrix} 0 & \tfrac12 & 0 \\ 1 & 0 & 1 \\ 0 & \tfrac12 & 0 \end{bmatrix}. By the degree rule the stationary distribution is π=(1,2,1)/4\pi = (1, 2, 1)/4; check: row 1 of PπP\pi is 12⋅24=14\tfrac12 \cdot \tfrac24 = \tfrac14, row 2 is 14+14=12\tfrac14 + \tfrac14 = \tfrac12. From x0=(1,0,0)x_0 = (1, 0, 0) the walker alternates: x1=(0,1,0)x_1 = (0, 1, 0), x2=(12,0,12)x_2 = (\tfrac12, 0, \tfrac12), x3=(0,1,0)x_3 = (0, 1, 0), x4=(12,0,12)x_4 = (\tfrac12, 0, \tfrac12), and so on. It never settles because the graph is bipartite and the chain is periodic: the eigenvalues are 1,0,−11, 0, -1, and the eigenvalue −1-1 has size 11.

      use

      Pages: 1 links to 2; 2 links to 1 and 3; 3 links to 1. Find the PageRank vector with d=12d = \tfrac12.

      Solution

      P=[01211000120]P = \begin{bmatrix} 0 & \tfrac12 & 1 \\ 1 & 0 & 0 \\ 0 & \tfrac12 & 0 \end{bmatrix} and 1−dn=16\tfrac{1-d}{n} = \tfrac16. Solve (I−12P)π=161(I - \tfrac12P)\pi = \tfrac16\mathbf 1: π1−14π2−12π3=16\pi_1 - \tfrac14\pi_2 - \tfrac12\pi_3 = \tfrac16,  π2−12π1=16\ \pi_2 - \tfrac12\pi_1 = \tfrac16,  π3−14π2=16\ \pi_3 - \tfrac14\pi_2 = \tfrac16. From the last two, π2=16+12π1\pi_2 = \tfrac16 + \tfrac12\pi_1 and π3=16+14π2=16+124+18π1=524+18π1\pi_3 = \tfrac16 + \tfrac14\pi_2 = \tfrac16 + \tfrac1{24} + \tfrac18\pi_1 = \tfrac{5}{24} + \tfrac18\pi_1. The first equation then reads π1−124−18π1−548−116π1=16\pi_1 - \tfrac1{24} - \tfrac18\pi_1 - \tfrac5{48} - \tfrac1{16}\pi_1 = \tfrac16, so 1316π1=16+124+548=8+2+548=1548\tfrac{13}{16}\pi_1 = \tfrac16 + \tfrac1{24} + \tfrac5{48} = \tfrac{8 + 2 + 5}{48} = \tfrac{15}{48}, giving π1=1548⋅1613=513\pi_1 = \tfrac{15}{48}\cdot\tfrac{16}{13} = \tfrac5{13}. Then π2=16+526=13+1578=1439\pi_2 = \tfrac16 + \tfrac5{26} = \tfrac{13 + 15}{78} = \tfrac{14}{39} and π3=524+5104=65+15312=1039\pi_3 = \tfrac5{24} + \tfrac5{104} = \tfrac{65 + 15}{312} = \tfrac{10}{39}. So π=(15,14,10)/39\pi = (15, 14, 10)/39, which adds to 11. (Undamped, it is (2,2,1)/5(2, 2, 1)/5.)

      prove

      Prove that if PP is a stochastic matrix then PkP^k is stochastic for every k≥1k \ge 1. Then prove that for a probability vector xx and every kk, ∥Pkx∥1=1\lVert P^kx \rVert_1 = 1.

      Solution

      For k=1k = 1 this is the hypothesis. If PkP^k is stochastic, then Pk+1=P⋅PkP^{k+1} = P \cdot P^k is a product of two stochastic matrices, hence stochastic by the product theorem (the argument: its entries are sums of products of non-negative numbers, and its column sums are ∑i∑lPil(Pk)lj=∑l(Pk)lj∑iPil=∑l(Pk)lj=1\sum_i\sum_l P_{il}(P^k)_{lj} = \sum_l(P^k)_{lj}\sum_iP_{il} = \sum_l(P^k)_{lj} = 1). By induction every PkP^k is stochastic. For a probability vector xx, PkxP^kx is a probability vector by the theorem, and the 1-norm of a vector with non-negative entries is the sum of its entries, which is 11.

      prove

      Let MM be a square matrix whose rows (not columns) each add to 11. Prove that 11 is an eigenvalue of MM, with eigenvector 1\mathbf 1.

      Solution

      Entry ii of M1M\mathbf 1 is the sum of row ii of MM, which is 11. So M1=1M\mathbf 1 = \mathbf 1 and 1≠O\mathbf 1 \ne O, so 11 is an eigenvalue with eigenvector 1\mathbf 1. (This is the row-stochastic convention of probability textbooks; for our column-stochastic matrices the same eigenvector belongs to PTP^{\mathsf T}, and the eigenvalue moves to PP through the characteristic polynomial.)

      prove

      Prove that for a stochastic matrix PP and a vector xx with all entries non-negative, ∥Px∥1=∥x∥1\lVert Px \rVert_1 = \lVert x \rVert_1. Where in the proof that ∥Px∥1≤∥x∥1\lVert Px \rVert_1 \le \lVert x \rVert_1 does the argument become an equality?

      Solution

      For x≥0x \ge 0 every entry of PxPx is non-negative, so ∥Px∥1\lVert Px \rVert_1 is the sum of the entries of PxPx, which is ∑jxj∑iPij=∑jxj=∥x∥1\sum_j x_j\sum_iP_{ij} = \sum_jx_j = \lVert x \rVert_1. In the earlier proof the only inequality was the triangle inequality ∣∑jPijxj∣≤∑jPij∣xj∣|\sum_jP_{ij}x_j| \le \sum_jP_{ij}|x_j|, and when every xj≥0x_j \ge 0 the terms PijxjP_{ij}x_j are non-negative, so the absolute values change nothing and the inequality is an equality.

      prove

      Let G=dP+1−dn11TG = dP + \tfrac{1-d}{n}\mathbf 1\mathbf 1^{\mathsf T} with PP stochastic. Prove that for every probability vector xx, Gx=dPx+1−dn1Gx = dPx + \tfrac{1-d}{n}\mathbf 1, and that GxGx is a probability vector.

      Solution

      Gx=dPx+1−dn1(1Tx)Gx = dPx + \tfrac{1-d}{n}\mathbf 1(\mathbf 1^{\mathsf T}x). For a probability vector 1Tx=1\mathbf 1^{\mathsf T}x = 1, so Gx=dPx+1−dn1Gx = dPx + \tfrac{1-d}{n}\mathbf 1. The entries are non-negative (a sum of non-negative terms). They add to d⋅1+n⋅1−dn=1d \cdot 1 + n \cdot \tfrac{1-d}{n} = 1, using that PxPx adds to 11. So GxGx is a probability vector. This is why one never needs to write the dense matrix GG.

      stretchthe idea behind Metropolis–Hastings

      Let PP be stochastic and π\pi a probability vector satisfying detailed balance: Pijπj=PjiπiP_{ij}\pi_j = P_{ji}\pi_i for all i,ji, j (the flow from jj to ii equals the flow from ii to jj). Prove that π\pi is stationary. Use it to re-prove that πv=deg⁡(v)/2m\pi_v = \deg(v)/2m is stationary for the random walk on a graph.

      Solution

      (Pπ)i=∑jPijπj=∑jPjiπi=πi∑jPji(P\pi)_i = \sum_jP_{ij}\pi_j = \sum_jP_{ji}\pi_i = \pi_i\sum_jP_{ji}. The last sum is the total chance of leaving state ii for some state jj, which is column ii of PP added up: it equals 11. So (Pπ)i=πi(P\pi)_i = \pi_i. For the graph walk, Pij=1/deg⁡(j)P_{ij} = 1/\deg(j) when i∼ji \sim j, and Pijπj=1deg⁡j⋅deg⁡j2m=12mP_{ij}\pi_j = \tfrac1{\deg j}\cdot\tfrac{\deg j}{2m} = \tfrac1{2m}, which is symmetric in ii and jj. So detailed balance holds (for non-neighbours both sides are 00) and π\pi is stationary.

      stretch

      For the two-state chain P=[1−aba1−b]P = \begin{bmatrix} 1 - a & b \\ a & 1 - b \end{bmatrix} with 0<a,b≤10 < a, b \le 1, find the stationary distribution, the other eigenvalue, and decide when Pkx0P^kx_0 converges for every probability vector x0x_0.

      Solution

      (P−I)π=O(P - I)\pi = O gives −aπ1+bπ2=0-a\pi_1 + b\pi_2 = 0, so π∝(b,a)\pi \propto (b, a) and π=(b,a)a+b\pi = \dfrac{(b, a)}{a + b}. The trace is 2−a−b2 - a - b, so the other eigenvalue is 1−a−b1 - a - b, with eigenvector (1,−1)(1, -1). Its size is less than 11 exactly when 0<a+b<20 < a + b < 2. Since a,b>0a, b > 0 the sum is positive, and a+b=2a + b = 2 only for a=b=1a = b = 1, the bouncing chain, where the eigenvalue is −1-1. So Pkx0→πP^kx_0 \to \pi for every x0x_0 unless a=b=1a = b = 1. (Check with the weather chain, a=0.2a = 0.2, b=0.4b = 0.4: π=(0.4,0.2)/0.6=(23,13)\pi = (0.4, 0.2)/0.6 = (\tfrac23, \tfrac13) and the other eigenvalue is 0.40.4.)

      Summary

      • A Markov chain moves among states with fixed chances PijP_{ij} (from jj to ii). The chances of being in each state evolve by xk+1=Pxkx_{k+1} = Px_k.
      • A stochastic matrix has non-negative entries and columns adding to 1. It keeps probability vectors probability vectors, because the total of the entries of PxPx is 1TPx=1Tx\mathbf 1^{\mathsf T}Px = \mathbf 1^{\mathsf T}x.
      • A stationary distribution is a probability vector with Pπ=πP\pi = \pi: an eigenvector for eigenvalue 1. Every stochastic matrix has eigenvalue 1 (because PT1=1P^{\mathsf T}\mathbf 1 = \mathbf 1 and PP, PTP^{\mathsf T} share eigenvalues) and no eigenvalue larger than 1 in size (the 1-norm never grows).
      • If the other eigenvalues have size less than 1, repeated steps kill their parts and Pkx0→πP^kx_0 \to \pi at the rate ∣λ2∣k|\lambda_2|^k. This holds for regular chains (Perron–Frobenius, stated here without proof). The power method computes π\pi using only matrix-times-vector.
      • The real web has dead ends, cycles, disconnected pieces and spider traps. Teleporting with chance 1−d1 - d gives the Google matrix G=dP+1−dn11TG = dP + \tfrac{1-d}{n}\mathbf 1\mathbf 1^{\mathsf T}, with d=0.85d = 0.85.
      • For GG we proved everything: a unique π\pi with entries at least 1−dn\tfrac{1-d}{n}, error at most 2dk2d^k from any start, and every other eigenvalue of size at most dd. The bound does not depend on the size of the web.
      • The four-page web has π=(12,4,9,6)/31\pi = (12, 4, 9, 6)/31 undamped and about (0.368,0.142,0.288,0.202)(0.368, 0.142, 0.288, 0.202) at d=0.85d = 0.85. A random walk on an undirected graph has πv=deg⁡(v)/2m\pi_v = \deg(v)/2m.
      • Text generated word by word from counts (an n-gram model) is a Markov chain, as is a language model on its context window; Markov chain Monte Carlo designs a chain with the stationary distribution you want.

      Watch and read

      The same ideas explained by someone else. Use these when an explanation here does not land.

      Where this sits

      Comes from
      2.8 Eigenvalues and eigenvectors
      2.10 Least squares and regression as projection
      Leads to
      See the next unit
      Same idea elsewhere
      MATH 431: A Markov chain is a sequence of random states in which the next state depends only on the current one. The identity x_{k+1} = P x_k below is the law of total probability: P(next is i) is the sum over j of P(next is i given now j) times P(now is j). If you meet conditional probability in 431, this is the same sum written as a matrix product.
      CS 240: A directed graph is the picture of a web: pages are vertices, links are arrows. The matrix here is the graph's adjacency matrix with each column divided by the number of out-arrows. The random walk on an undirected graph, below, has a stationary distribution given by the degrees.
      CS 532 / AI: A language model that predicts the next word from the last N words is a Markov chain on the last N words. The n-gram model below is its simplest ancestor. Markov chain Monte Carlo, which samples from hard probability distributions, designs a chain whose stationary distribution is the one you want.