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.
- 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 .
- 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 means page links to page . 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].
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 have vertices, out-degrees , and dangling vertices . Fix a damping factor and a teleportation distribution on (uniform unless stated otherwise). A random surfer at :
- with probability follows one of ’s out-links uniformly at random — or, if is dangling, jumps to a page drawn from ;
- with probability jumps to a page drawn from .
Write for the column-stochastic matrix of the link step with the dangling fix: if , if , and otherwise. The surfer’s distribution evolves by
The PageRank vector is a probability vector with , i.e.
where 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 , one of several conventions [Langville & Meyer 2004]. Damping (classically ) controls how far the surfer follows links before teleporting. Teleportation makes the chain irreducible and is the lever for personalization (§§15.7).
15.3 Existence, uniqueness, convergence
For probability vectors , . Hence has a unique fixed point in the probability simplex; for every starting distribution , the iterates satisfy ; and, with residual ,
. A column-stochastic matrix has non-negative entries with columns summing to one, so for any vector , . Thus is an -contraction in on the simplex, which maps to itself; Banach’s fixed-point theorem gives existence, uniqueness and , and for probability vectors. For (15.3):
In spectral terms, is a column-stochastic matrix with eigenvalue , and its second eigenvalue has modulus at most [Haveliwala & Kamvar 2003]; the contraction argument gives the rate directly without eigenvalues.
Power iteration from , stopped as soon as , stops after at most
iterations, and the returned vector is within of in .
, so once . The error claim is (15.3).
∎For and , ; for , . 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:
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}")
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 – of the true error and, after the first few iterations, is far tighter than the a-priori — this graph converges faster than the worst case, and the residual detects it.
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 , and the certified error bound ; the a-priori bound for tolerance is shown alongside.
15.4 Solvers
Equation (15.2) is also a linear system: . Power iteration is the Jacobi method for it. Gauss–Seidel updates using the newest values of the other entries within a sweep:
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 ). 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 ). 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 up to , while grew to 2,819; on the cyclic block graph, iterations grew from 27 to 485 as went from to (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.
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}")
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 alone. First, every count is far below : 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 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: operations. In memory, the standard representation is compressed sparse rows: an array of target indices, an array of offsets, and two vectors of floating-point scores — about words plus . 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 converges to the new fixed point in about iterations instead of . 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 in , 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 by a distribution concentrated on pages of interest gives personalized PageRank; a set of topic-specific vectors precomputed and mixed at query time gives topic-sensitive PageRank [Haveliwala 2002]. The mixing works because depends linearly on : from (15.1), when the dangling redistribution uses a fixed vector, so a convex combination of teleportation vectors yields the same combination of PageRank vectors. Precomputing vectors costs PageRank computations and words of storage; each query-time mixture is . This is again M-PRE, and again the break-even depends on query volume. (With the convention used here — dangling mass redistributed by itself — depends on 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.
Show that if is -regular (every vertex has in- and out-degree ) and is uniform, then is uniform for every , and power iteration from 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, for the uniform vector , because has in-neighbours. So : the uniform vector is the fixed point, the first residual is , and the stopping rule fires at . 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.)
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.
Prove that the dangling-mass convention matters: give a three-vertex graph on which redistributing dangling mass uniformly and redistributing it by a personalized produce different rankings.
Derive the warm-start iteration estimate stated in §§15.6 from Theorem 15.2.
- 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 error by per step; the residual certifies the error, and 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 operations and about 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 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
- 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.
- 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.
- Haveliwala & Kamvar 2003 T. Haveliwala, S. Kamvar (2003). The second eigenvalue of the Google matrix. Technical report, Stanford University.
- Haveliwala 2002 T. H. Haveliwala (2002). Topic-sensitive PageRank. Proc. 11th International World Wide Web Conference (WWW 2002). link.
- 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.
- 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.
- 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).
- 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.