Part V · PageRank, Search, and Information Retrieval

Chapter 15

PageRank from First Principles

mixed Established mathematics with complete proofs of the results used; experiments reproducible. Nothing here concerns any search engine's production systems.

Learning objectives
  • Build the PageRank model from a directed graph: transition matrix, dangling pages, damping, teleportation.
  • Prove that the PageRank vector exists and is unique, and that power iteration converges geometrically with rate α\alpha.
  • Certify the error of an approximate PageRank vector from the last residual, and bound the number of iterations in advance.
  • Compare power iteration and Gauss–Seidel, and explain why the vertex order matters for one and not the other.
  • State the cost of one iteration in time, memory and communication, and the effect of graph updates and personalization.

15.1 The ranking problem

A collection of hyperlinked pages forms a directed graph: an edge u→vu \to v means page uu links to page vv. PageRank assigns each page a score meant to capture how much attention the link structure directs to it. It was introduced by Page, Brin, Motwani and Winograd [Page et al. 1999] and described as part of the prototype of the Google search engine by Brin and Page [Brin & Page 1998]. The mathematics is now standard [Langville & Meyer 2006; Langville & Meyer 2004; Bianchini et al. 2005].

Claim boundary

This chapter and the next treat PageRank as a published algorithm on mathematical graphs. They say nothing about any search engine’s current ranking systems, which combine many signals and are not public. No result here should be read as an improvement to, or an endorsement by, any company’s production search.

15.2 The random surfer

Let G=(V,E)G = (V, E) have nn vertices, out-degrees o(u)o(u), and dangling vertices D={u:o(u)=0}D = \{u : o(u) = 0\}. Fix a damping factor α∈[0,1)\alpha \in [0, 1) and a teleportation distribution vv on VV (uniform unless stated otherwise). A random surfer at uu:

Write MM for the n×nn \times n column-stochastic matrix of the link step with the dangling fix: Mwu=1/o(u)M_{wu} = 1/o(u) if u→wu \to w, Mwu=vwM_{wu} = v_w if u∈Du \in D, and 00 otherwise. The surfer’s distribution evolves by

xk+1=T(xk),T(x)=α Mx+(1−α) v.(15.1)x_{k+1} = T(x_k), \qquad T(x) = \alpha\, M x + (1 - \alpha)\, v . \tag{15.1}
Definition 15.1 (PageRank vector)

The PageRank vector π\pi is a probability vector with T(π)=πT(\pi) = \pi, i.e.

π=α(P⊤π+(∑u∈Dπu) v)+(1−α) v,(15.2)\pi = \alpha \Big( P^{\top} \pi + \big(\textstyle\sum_{u \in D} \pi_u\big)\, v \Big) + (1 - \alpha)\, v, \tag{15.2}

where P⊤P^\top distributes each non-dangling page’s score equally over its out-links.

Three modelling choices are hidden in (15.2) and each matters in practice. Dangling pages (no out-links: images, PDFs, pages not yet crawled) would otherwise leak probability; here their mass is redistributed by vv, one of several conventions [Langville & Meyer 2004]. Damping α\alpha (classically 0.850.85) controls how far the surfer follows links before teleporting. Teleportation vv makes the chain irreducible and is the lever for personalization (§§15.7).

15.3 Existence, uniqueness, convergence

Theorem 15.2 (Contraction of the PageRank map)EstablishedCGT-THM-008

For probability vectors x,yx, y, ∥T(x)−T(y)∥1≤α∥x−y∥1\|T(x) - T(y)\|_1 \le \alpha \|x - y\|_1. Hence TT has a unique fixed point π\pi in the probability simplex; for every starting distribution x0x_0, the iterates satisfy ∥xk−π∥1≤αk∥x0−π∥1≤2αk\|x_k - \pi\|_1 \le \alpha^k \|x_0 - \pi\|_1 \le 2\alpha^k; and, with residual rk=∥xk−xk−1∥1r_k = \|x_k - x_{k-1}\|_1,

∥xk−π∥1≤α1−α rk.(15.3)\|x_k - \pi\|_1 \le \frac{\alpha}{1 - \alpha}\, r_k . \tag{15.3}
Proof.

T(x)−T(y)=αM(x−y)T(x) - T(y) = \alpha M (x - y). A column-stochastic matrix has non-negative entries with columns summing to one, so for any vector zz, ∥Mz∥1=∑w∣∑uMwuzu∣≤∑u∣zu∣∑wMwu=∥z∥1\|Mz\|_1 = \sum_w |\sum_u M_{wu} z_u| \le \sum_u |z_u| \sum_w M_{wu} = \|z\|_1. Thus TT is an α\alpha-contraction in L1L_1 on the simplex, which TT maps to itself; Banach’s fixed-point theorem gives existence, uniqueness and ∥xk−π∥≤αk∥x0−π∥\|x_k - \pi\| \le \alpha^k \|x_0 - \pi\|, and ∥x0−π∥1≤2\|x_0 - \pi\|_1 \le 2 for probability vectors. For (15.3):

∥xk−1−π∥1≤∥xk−1−xk∥1+∥xk−π∥1≤rk+α ∥xk−1−π∥1,so∥xk−1−π∥1≤rk1−α,∥xk−π∥1≤α ∥xk−1−π∥1≤α1−α rk.\begin{aligned} \|x_{k-1} - \pi\|_1 &\le \|x_{k-1} - x_k\|_1 + \|x_k - \pi\|_1 \le r_k + \alpha\, \|x_{k-1} - \pi\|_1, \\ \text{so}\quad \|x_{k-1} - \pi\|_1 &\le \frac{r_k}{1-\alpha}, \qquad \|x_k - \pi\|_1 \le \alpha\,\|x_{k-1} - \pi\|_1 \le \frac{\alpha}{1 - \alpha}\, r_k . \end{aligned}
∎

In spectral terms, αM+(1−α)v1⊤\alpha M + (1 - \alpha) v \mathbf{1}^\top is a column-stochastic matrix with eigenvalue 11, and its second eigenvalue has modulus at most α\alpha [Haveliwala & Kamvar 2003]; the contraction argument gives the rate directly without eigenvalues.

Proposition 15.3 (A-priori iteration bound)EstablishedCGT-PROP-009

Power iteration from x0=vx_0 = v, stopped as soon as α1−αrk≤τ\frac{\alpha}{1-\alpha} r_k \le \tau, stops after at most

k∗=⌈log⁡(τ(1−α)/2)log⁡α⌉k^* = \left\lceil \frac{\log\big(\tau (1 - \alpha)/2\big)}{\log \alpha} \right\rceil

iterations, and the returned vector is within τ\tau of π\pi in L1L_1.

Proof.

rk=∥T(xk−1)−T(xk−2)∥≤αk−1r1≤2αk−1r_k = \|T(x_{k-1}) - T(x_{k-2})\| \le \alpha^{k-1} r_1 \le 2\alpha^{k-1}, so α1−αrk≤2αk1−α≤τ\frac{\alpha}{1-\alpha} r_k \le \frac{2\alpha^k}{1-\alpha} \le \tau once αk≤τ(1−α)/2\alpha^k \le \tau(1-\alpha)/2. The error claim is (15.3).

∎

For α=0.85\alpha = 0.85 and τ=10−10\tau = 10^{-10}, k∗=158k^* = 158; for α=0.99\alpha = 0.99, k∗=2,819k^* = 2{,}819. The bound is a worst case. The SDK’s tests check the per-step contraction against an exact linear solve, and the experiments found it respected on every instance:

Python · executed by the book's example checker
from cgtsdk.algorithms import pagerank_exact, pagerank_power

adj = [[1, 2], [2], [0, 3], [], [0, 3, 2]]          # page 3 is dangling
pi = pagerank_exact(adj, 0.85)                       # Gaussian elimination, the oracle
print("PageRank (exact):", [round(p, 6) for p in pi])
for k in (1, 2, 5, 10, 20, 40):
    x = pagerank_power(adj, 0.85, tol=0, max_iter=k)
    err = sum(abs(a - b) for a, b in zip(x.scores, pi))
    print(f"k={k:2d}  true error {err:.2e}   certified bound {x.error_bound:.2e}   2*alpha^k {2 * 0.85**k:.2e}")
Output (checked)
PageRank (exact): [0.223817, 0.163171, 0.321147, 0.223817, 0.068049]
k= 1  true error 1.09e-01   certified bound 2.12e+00   2*alpha^k 1.70e+00
k= 2  true error 7.58e-02   certified bound 8.90e-01   2*alpha^k 1.44e+00
k= 5  true error 8.59e-03   certified bound 1.15e-01   2*alpha^k 8.87e-01
k=10  true error 4.02e-04   certified bound 6.80e-03   2*alpha^k 3.94e-01
k=20  true error 7.14e-07   certified bound 8.54e-06   2*alpha^k 7.75e-02
k=40  true error 1.23e-12   certified bound 2.15e-11   2*alpha^k 3.00e-03

The certified bound stays within a factor of about 1010–2020 of the true error and, after the first few iterations, is far tighter than the a-priori 2αk2\alpha^k — this graph converges faster than the worst case, and the residual detects it.

Interactive laboratory

Text alternative: pick one of several small graphs (or edit the out-link lists) and a damping factor; step through power iteration one iteration at a time, watching the scores, the residual ∥xk−xk−1∥1\|x_k - x_{k-1}\|_1, and the certified error bound α1−α∥xk−xk−1∥1\frac{\alpha}{1-\alpha}\|x_k - x_{k-1}\|_1; the a-priori bound k∗k^* for tolerance 10−1010^{-10} is shown alongside.

15.4 Solvers

Equation (15.2) is also a linear system: (I−αM)π=(1−α)v(I - \alpha M)\pi = (1 - \alpha) v. Power iteration is the Jacobi method for it. Gauss–Seidel updates πi\pi_i using the newest values of the other entries within a sweep:

πi←(1−α)vi+α(∑u→i, u≠iπu/o(u)+vi∑u∈D, u≠iπu)1−αMii.\pi_i \leftarrow \frac{(1-\alpha) v_i + \alpha \big( \sum_{u \to i,\, u \ne i} \pi_u / o(u) + v_i \sum_{u \in D,\, u \ne i} \pi_u \big)}{1 - \alpha M_{ii}} .

The SDK implements both, plus an exact solver by Gaussian elimination used as an oracle on small graphs. The experiments (CGT-EXP-009) show that neither iterative method dominates. On a graph with host-like blocks and many cycles, Gauss–Seidel needed fewer sweeps than power iteration needed iterations (56 versus 104 at α=0.85\alpha = 0.85). On an acyclic “copying-model” graph whose links all point to earlier vertices, sweeping in the natural order works against the direction of information flow, and Gauss–Seidel was dramatically slower (1,561 sweeps versus 37 iterations at α=0.99\alpha = 0.99). Reversing the vertex order cut its sweeps from 110 to 34. Power iteration, by contrast, is invariant under reordering: the same linear map, the same iteration count and the same number of edge operations in any order (CGT-OBS-016). The ledger records “Gauss–Seidel is faster” as a rejected general hypothesis (CGT-REJ-003).

The convergence data also contain a surprise that this book cannot yet explain. On the acyclic copying-model graph, power iteration stopped after 17–37 iterations for every α\alpha up to 0.990.99, while k∗k^* grew to 2,819; on the cyclic block graph, iterations grew from 27 to 485 as α\alpha went from 0.50.5 to 0.990.99 (CGT-OBS-015). A tempting explanation — without cycles, probability cannot circulate, so the iteration settles after about the length of the longest path — is contradicted by the next example, in which the acyclic graph converges more slowly than the cyclic one: dangling pages send their mass back through teleportation, which re-creates circulation.

Python · executed by the book's example checker
from cgtsdk.algorithms import pagerank_gauss_seidel, pagerank_power
import math, random

rng, n = random.Random(4), 400
cyclic = [[(u + 1) % n, rng.randrange(n)] for u in range(n)]           # a ring plus one random link each
acyclic = [[w for w in nbrs if w > u] for u, nbrs in enumerate(cyclic)]  # keep only forward links
print("alpha    k*   power: cyclic acyclic   Gauss-Seidel: cyclic acyclic")
for alpha in (0.5, 0.85, 0.99):
    kstar = math.ceil(math.log(1e-10 * (1 - alpha) / 2) / math.log(alpha))
    p = [pagerank_power(g, alpha, tol=1e-10).iterations for g in (cyclic, acyclic)]
    s = [pagerank_gauss_seidel(g, alpha, tol=1e-10 * (1 - alpha)).iterations for g in (cyclic, acyclic)]
    print(f"{alpha:5}  {kstar:5d}        {p[0]:5d}  {p[1]:6d}               {s[0]:5d}  {s[1]:6d}")
Output (checked)
alpha    k*   power: cyclic acyclic   Gauss-Seidel: cyclic acyclic
  0.5     36           22      29                  12       5
 0.85    158           48     104                  37      10
 0.99   2819           78     393                 523      78

Three observations, each consistent with the theory and none implied by α\alpha alone. First, every count is far below k∗k^*: the bound is a worst case. Second, the acyclic graph needs more power iterations than the cyclic one here, the opposite of the copying graph. Third, on the acyclic graph every link points forward, so Gauss–Seidel’s natural sweep order follows the flow of probability and it needs a small fraction of power iteration’s work; on the cyclic graph at α=0.99\alpha = 0.99 it needs several times more. Which structural parameters govern these counts is an open question for this program; that the order of evaluation relative to the link direction matters for Gauss–Seidel and not for power iteration is established (CGT-OBS-016).

15.5 Cost of an iteration: memory and communication

One power iteration reads every edge once and every vertex a constant number of times: Θ(n+m)\Theta(n + m) operations. In memory, the standard representation is compressed sparse rows: an array of mm target indices, an array of n+1n + 1 offsets, and two vectors of nn floating-point scores — about mm words plus 3n3n. This is the adjacency-list representation of Chapter 6 laid out contiguously, so that the edge array is read sequentially (arithmetic addressing of edges by offset).

At web scale the graph does not fit in one machine’s memory. Partitioning the vertices across machines makes each iteration a local multiply plus an exchange of the scores flowing along cut edges; the communication per iteration is proportional to the number of cut edges, which is why host-based partitioning helps — most links stay within a host [Kamvar et al. 2003]. These are system-level costs that the word-RAM model does not capture; the book states them qualitatively and makes no measured claim about them.

15.6 Updates and incremental ranking

When the graph changes, the old vector is a good starting point. Since Theorem 15.2 holds from any start, a warm start from the previous π\pi converges to the new fixed point in about log⁡(∥πold−πnew∥1/τ)/log⁡(1/α)\log(\|\pi_{\text{old}} - \pi_{\text{new}}\|_1 / \tau) / \log(1/\alpha) iterations instead of log⁡(2/τ)/log⁡(1/α)\log(2/\tau)/\log(1/\alpha). The saving therefore shrinks as the update moves the fixed point further. In the experiment (CGT-OBS-017), on a 3,000-page graph a single inserted link cut iterations from 38 to 27; after 10,000 random insertions, which moved the ranking by 0.510.51 in L1L_1, there was no saving at all. Incremental ranking is precomputation with invalidation — the break-even logic of Chapter 12 in a numerical setting [Langville & Meyer 2004].

15.7 Personalization

Replacing the uniform vv by a distribution concentrated on pages of interest gives personalized PageRank; a set of tt topic-specific vectors precomputed and mixed at query time gives topic-sensitive PageRank [Haveliwala 2002]. The mixing works because π\pi depends linearly on vv: from (15.1), π=(1−α)(I−αM)−1v\pi = (1 - \alpha)(I - \alpha M)^{-1} v when the dangling redistribution uses a fixed vector, so a convex combination of teleportation vectors yields the same combination of PageRank vectors. Precomputing tt vectors costs tt PageRank computations and tntn words of storage; each query-time mixture is O(tn)\Oh(tn). This is again M-PRE, and again the break-even depends on query volume. (With the convention used here — dangling mass redistributed by vv itself — MM depends on vv and exact linearity requires redistributing dangling mass by a fixed vector instead. The SDK computes each personalized vector directly.)

15.8 Evaluating a ranking

Convergence and certified error say how accurately the PageRank vector has been computed. They say nothing about whether the ranking is useful. Usefulness is measured against relevance judgments on real queries with standard metrics, and requires real corpora and human or behavioural evidence. This book has no such data and makes no claim about ranking quality, here or in the next chapter.

Exercise 15.1

Show that if GG is dd-regular (every vertex has in- and out-degree dd) and vv is uniform, then π\pi is uniform for every α\alpha, and power iteration from vv stops after one step. Why does this make regular graphs useless as benchmarks for PageRank solvers?

Solution to Exercise 15.1

With no dangling vertices, (P⊤u)w=∑u→w1n⋅1d=1n(P^\top \mathbf{u})_w = \sum_{u \to w} \frac{1}{n}\cdot\frac{1}{d} = \frac{1}{n} for the uniform vector u\mathbf{u}, because ww has dd in-neighbours. So T(u)=αu+(1−α)u=uT(\mathbf{u}) = \alpha \mathbf{u} + (1-\alpha)\mathbf{u} = \mathbf{u}: the uniform vector is the fixed point, the first residual is 00, and the stopping rule fires at k=1k = 1. Any solver started from the uniform vector “converges” immediately on such graphs, so they measure nothing about solvers. (An earlier draft of this chapter used a chorded cycle as its example and fell into exactly this trap; the example checker exposed it.)

Exercise 15.2

Reverse every link of the acyclic graph in the example (so links point backward) and rerun Gauss–Seidel. Predict the result from the discussion of sweep order before running it, and compare with CGT-OBS-016.

Exercise 15.3

Prove that the dangling-mass convention matters: give a three-vertex graph on which redistributing dangling mass uniformly and redistributing it by a personalized vv produce different rankings.

Exercise 15.4

Derive the warm-start iteration estimate stated in §§15.6 from Theorem 15.2.

Summary
  • PageRank is the stationary distribution of a damped random surfer with dangling pages and teleportation; it exists, is unique, and attracts every start (CGT-THM-008).
  • Power iteration contracts the L1L_1 error by α\alpha per step; the residual certifies the error, and k∗=⌈log⁡(τ(1−α)/2)/log⁡α⌉k^* = \lceil \log(\tau(1-\alpha)/2)/\log\alpha \rceil iterations always suffice (CGT-PROP-009).
  • Gauss–Seidel can be faster or much slower depending on vertex order relative to link direction; power iteration is order-invariant.
  • One iteration costs Θ(n+m)\Theta(n + m) operations and about m+3nm + 3n words in compressed sparse rows; distribution costs communication on cut edges.
  • Warm starts save iterations in proportion to how little the update moves the fixed point; personalization is linear in vv under a fixed dangling convention.
  • Accuracy of the vector is not usefulness of the ranking; the latter needs relevance data this book does not have.

References cited in this chapter

  1. Bianchini et al. 2005 M. Bianchini, M. Gori, F. Scarselli (2005). Inside PageRank. ACM Transactions on Internet Technology 5(1):92–128. doi:10.1145/1052934.1052938.
  2. Brin & Page 1998 S. Brin, L. Page (1998). The anatomy of a large-scale hypertextual Web search engine. Computer Networks and ISDN Systems 30:107–117.
  3. Haveliwala & Kamvar 2003 T. Haveliwala, S. Kamvar (2003). The second eigenvalue of the Google matrix. Technical report, Stanford University.
  4. Haveliwala 2002 T. H. Haveliwala (2002). Topic-sensitive PageRank. Proc. 11th International World Wide Web Conference (WWW 2002). link.
  5. Kamvar et al. 2003 S. Kamvar, T. Haveliwala, C. Manning, G. Golub (2003). Exploiting the block structure of the Web for computing PageRank. Technical Report 2003-17, Stanford University.
  6. Langville & Meyer 2004 A. N. Langville, C. D. Meyer (2004). Deeper inside PageRank. Internet Mathematics 1(3):335–380. doi:10.1080/15427951.2004.10129091.
  7. Langville & Meyer 2006 A. N. Langville, C. D. Meyer (2006). Google's PageRank and Beyond: The Science of Search Engine Rankings. Princeton University Press (ISBN 978-0-691-12202-1).
  8. Page et al. 1999 L. Page, S. Brin, R. Motwani, T. Winograd (1999). The PageRank citation ranking: Bringing order to the Web. Technical Report 1999-66, Stanford InfoLab. link.

Report an erratum or an unclear passage in this chapter