Skip to content

Lectures on the Google Technology Stack 2: Building our PageRank Intuition

by Michael Nielsen on December 9, 2008

This is one in a series of posts about the Google Technology Stack – PageRank, MapReduce, and so on – based on a lecture series I’m giving in 2008 and 2009. If you’d like to know more about the series, please see the course syllabus. There is a FriendFeed room for the series here.

In today’s lecture, we’ll build our intuition about PageRank. We’ll figure out the minimal and maximal possible values for PageRank; study how PageRank works for a web with a random link structure, seeing a sort of “central limit theorem” for PageRank emerge; and find out how spammers can spam PageRank, and how to defeat them.

Building our PageRank Intuition

In the last lecture we defined PageRank, but we haven’t yet developed a deep understanding. In this lecture we’ll build our intuition, working through many basic examples of PageRank in action, and answering many fundamental questions.

The minimal and maximal values for PageRank

Recall from last lecture that the PageRank vector q is an N-dimensional probability distribution, with the probability q_j measuring the importance of webpage j. Because q is a probability distribution, the total of all the probabilities must add up to one, and so the average PageRank is 1/N.

It’s interesting that we can get this precise value for the average PageRank, but what we’d really like is more detailed information about the way PageRank behaves for typical pages. Let’s start by studying the minimal and maximal possible values for PageRank.

Intuitively, we expect that the minimal value for PageRank occurs when a page isn’t linked to by any other page. This intuition can be made more rigorous as follows. Recall our definition of PageRank using a websurfer randomly surfing through webpages. At any given step of their random walk, the crazy websurfer has a probability at least t P_j of teleporting to vertex j, and thus we must have

   q_j \geq t P_j

for all pages j. Furthermore, it’s possible for the PageRank to be equal to this value if, for example, no other pages link to page j. Thus tP_j is the minimal value for the PageRank of page j. A more algebraic way of putting this argument is to recall from the last lecture that tP = (I-sG)q, and thus t P_j = q_j – s(Gq)_j \leq q_j, since (Gq)_j \geq 0. For the original PageRank algorithm, P_j = 1/N, and so the minimal PageRank is t/N for all webpages, a factor t smaller than the average PageRank.

Exercises

  • We will say that webpage k eventually leads to webpage j if there is a link path leading from k to j. Show that q_j   = tP_j if and only if P_k = 0 for all pages k that eventually lead to page j. Obviously, this can’t happen for the original PageRank algorithm, where P_j = 1/N, unless there are no pages at all linking to page j. Generically, therefore, most pages have PageRank greater than this minimum.

We can use the value for the minimal PageRank to deduce the maximal possible PageRank. Because the sum of all PageRanks is 1, the maximal possible PageRank for page j occurs if all other PageRanks have their minimal value, tP_k. In this case q_j = 1-\sum_{k\neq   j} t P_k = 1-t(1-P_j) = s+tP_j, and so we have

   q_j \leq s + t P_j.

An example where maximal PageRank occurs is a web with a “star” topology of links, with the central webpage, which we’ll label 1, having only a single outgoing link, to itself, and every other webpage 2,\ldots,N having a single link going to page 1. Pages 2,\ldots,N have no incoming links, and thus have minimal PageRank tP_j, and so page 1 has maximal PageRank, s+tP_1.

Exercises

  • In the previous example show explicitly that q =   (s+tP_1,tP_2,\ldots,tP_N) satisfies the equation Mq = q.
  • In the star topology example, we required that webpage 1 link to itself. The reason was so that page 1 was not a dangling page, and thus treated by PageRank as effectively linked to every page. What happens to the PageRank of page 1 if we make it dangling?

Typical values of PageRank

It’s all very well to know the maximal and minimal values of PageRank, but in practice those situations are rather unusual. What can we say about typical values of PageRank? To answer this question, let’s build a model of the web, and study its properties. We’ll assume a very simple model of a web with just 5,000 pages, with each page randomly linking to 10 others. The following code plots a histogram of the PageRanks, for the case s = 0.85.

 
# Generates a 5,000 page web, with each page randomly 
# linked to 10 others, computes the PageRank vector, and 
# plots a histogram of PageRanks.
# 
# Runs under python 2.5 with the numpy and matplotlib 
# libraries.  If these are not already installed, you'll 
# need to install them.

from numpy import * 
import random 
import matplotlib.pyplot as plt

# Returns an n-dimensional column vector with m random 
# entries set to 1.  There must be a more elegant way to 
# do this! 
def randomcolumn(n,m):
  values = random.sample(range(0,n-1),m)
  rc = mat(zeros((n,1)))
  for value in values:
    rc[value,0] = 1
  return rc

# Returns the G matrix for an n-webpage web where every 
# page is linked to m other pages. 
def randomG(n,m):   
  G = mat(zeros((n,n)))
  for j in range(0,n-1):
    G[:,j] = randomcolumn(n,m)
  return (1.0/m)*G

# Returns the PageRank vector for a web with parameter s 
# and whose link structure is described by the matrix G. 
def pagerank(G,s):
  n = G.shape[0]
  id = mat(eye(n))
  teleport = mat(ones((n,1)))/n
  return (1-s)*((id-s*G).I)*teleport

G = randomG(5000,20)
pr = pagerank(G,0.85)
print std(pr)
plt.hist(pr,50) 
plt.show() 

Problems

  • The randomcolumn function in the code above isn’t very elegant. Can you find a better way of implementing it?

The result of running the code is the following histogram of PageRank values – the horizontal axis is PageRank, while the vertical axis is the frequency with which it occurs:

We see from this graph that PageRank has a mean of 1/5000, as we expect, and an empirical standard deviation of 0.000055. Roughly speaking, it looks Gaussian, although, of course, PageRank is bounded above and below, and so can’t literally be Gaussian.

Suppose now that we change the number of links per page to 100, but keep everything else the same. Then the resulting histogram is:

This also looks Gaussian, but has a smaller standard deviation of 0.000017. Notice that while we approach the minimal possible value of PageRank (t/N = 0.00003) in the first graph, in neither graph do we come anywhere near the maximal possible value of PageRank, which is just a tad over s = 0.85.

Looking at these results, and running more numerical experiments in a similar vein, we see that as the number of outgoing links is increased, the standard deviation in PageRank seems to decrease. A bit of playing around suggests that the standard deviation decreases as one over the square root of the number of outgoing links, at least when the number of outgoing links is small compared with the total number of pages. More numerical experimentation suggests that the standard deviation is also proportional to s/N. As a result, I conjecture:

Conjecture: Consider a random web with n pages and m outgoing links per page. Then for 1 \ll m \ll n the PageRank distribution approaches a Gaussian with mean 1/n and standard deviation s/(n\sqrt{m}).

For the case n = 5000, m = 10, s = 0.85 this suggests a standard deviation of 0.000054, while for the case n = 5000, m = 100, s = 0.85 it suggests a standard deviation of 0.000017. Both these results are in close accord with the earlier empirical findings. The further numerical investigations I’ve done (not a lot, it must be said) also confirm it.

Incidentally, you might wonder why I chose to use a web containing 5,000 pages. The way I’ve computed PageRank in the program above, we compute the matrix inverse of a 5,000 by 5,000 matrix. Assuming we’re using 64-bit floating point arithmetic, that means just storing the matrix requires 200 megabytes. Not surprisingly, it turns out that my small laptop can’t cope with 10,000 webpages, so I stuck with 5,000. Still, it’s notable that at that size the program still ran quite quickly. In the next lecture we’ll see how to cope with much larger sets of webpages.

Exercises

  • Modify the program above to run with m=1. You’ll find that the PageRank distribution does not look Gaussian. What conjecture do you think describes the PageRank distribution in this case? What’s a good reason we might not expect Gaussian behaviour for small values of m?
  • Do you trust the Python code to produce the correct outcomes? One of the problems in using numeric libraries as black boxes is that it can be hard to distinguish between real results and numerical artifacts. How would you determine which is the case for the code above? (For the record, I do believe the results, but have plans to do more checks in later lectures!)

Problems

  • Can you prove or disprove the above conjecture? If it’s wrong, is there another similar type of result you can prove for PageRank, a sort of “central limit theorem” for PageRank? Certainly, the empirical results strongly suggest that some type of result in this vein is true! I expect that a good strategy for attacking this problem is to first think about the problem from first principles, and, if you’re getting stuck, to consult some of the literature about random walks on random graphs.
  • What happens if instead of linking to a fixed number of webpages, the random link structure is governed by a probability distribution? You might like to do some computational experiments, and perhaps formulate (and, ideally, prove) a conjecture for this case.
  • Following up on the last problem, I believe that a much better model of the web than the one we’ve used is to assume a power-law distribution of incoming (not outgoing) links to every page. Can you formulate (and, ideally, prove) a type of central limit theorem for PageRank in this case? I expect to see a much broader distribution of PageRanks than the Gaussian we saw in the case of a fixed number of outgoing links.

A simple technique to spam PageRank

One of the difficulties faced by search engines is spammers who try to artificially inflate the prominence of webpages by pumping up their PageRank. To defeat this problem, we need to understand how such inflation can be done, and find ways of avoiding it. Here’s one simple technique for getting a high PageRank.

Suppose the web contains N pages, and we build a link farm containing M additional pages, in the star topology described earlier. That is, we number our link farm pages 1,\ldots,M, make page 1 link only to itself, and all the other pages link only to page 1. Then if we use the original PageRank, with uniform teleportation probabilities 1/(N+M), a similar argument to earlier shows that the PageRank for page 1 is

   (s + t/M) \frac{M}{M+N}.

As we increase the size, M, of the link farm it eventually becomes comparable to the size of the rest of the web, N, and this results in an enormous PageRank for page 1 of the link farm. This is not just a theoretical scenario. In the past, spammers have built link farms containing billions of pages, using a technique similar to that described above to inflate their PageRank. They can then sell links from page 1 to other pages on the web, essentially renting out some of their PageRank.

How could we defeat this strategy? If we assume that we can detect the link farm being built, then a straightforward way of dealing with it is to modify the teleportation vector so that all pages in the link farm are assigned teleportation probabilities of zero, eliminating all the spurious PageRank accumulated due to the large number of pages in the link farm. Unfortunately, this still leaves the problem of detecting the link farm to begin with. That’s not so easy, and I won’t discuss it in this lecture, although I hope to come back to it in a later lecture.

Exercises

  • Prove that the PageRank for page 1 of the link farm is, as claimed above, (s+t/M) M/(M+N).
  • The link topology described for the link farm is not very realistic. To get all the pages into the Google index the link farm would need to be crawled by Google’s webcrawler. But the crawler would never discover most of the pages, since they aren’t linked to by any other pages. Can you think of a more easily discoverable link farm topology that still gains at least one of the pages a large PageRank?

That concludes the second lecture. Next lecture, we’ll look at how to build a more serious implementation of PageRank, one that can be applied to a web containing millions of pages, not just thousands of pages.

From → GTS

2 Comments
  1. bob permalink

    your randomcolumn() function is incorrect.

    random.sample(range(0,n-1),m)
    will select m indices between 0 and n-2 inclusive, that means the last element (index n-1) could never be set to 1

Trackbacks and Pingbacks

  1. Michael Nielsen » Building intuition about PageRank (video)

Comments are closed.