learngraphtheory.org

Guest User

Using app without sign in

Cover of the book Graph Theory Through Problems

Practice book

Graph Theory Through Problems

300 Exercises with Hints, Worked Algorithms and Complete Solutions

By Mohammed Islam Hadjoudj

Learn graph theory by solving problems: 300 exercises, from routine checks to challenging proofs, each with a complete solution.

Available inKindlePaperback

13 chapters

Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on Amazon
Algorithm Selection

Select an algorithm and generate steps to begin visualization

Personalized PageRank Calculator

Who should this vertex connect to next?

Random walk with restart from the start vertex: scores every vertex by its closeness to it and suggests the best ones not yet linked

Time: O(k(V + E))
Space: O(V)
Use Case: Friend, product and film recommendations
Showing the example graph for this algorithm.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About Personalized PageRank

Personalized PageRank scores every vertex by how close it is to one chosen vertex, the seed, through many short paths. It is PageRank with a different jump: the random surfer follows a random link with probability d = 0.85, and otherwise returns to the seed instead of to a random page. Glen Jeh and Jennifer Widom described it in 2003, and the same idea is known as random walk with restart. The scores answer personal questions: which pages, products or people matter most from this vertex's point of view.

How it works

All of the score starts on the seed. In every iteration each vertex passes 85% of its score evenly along its links, and the remaining 15% of the total returns to the seed, together with the score of vertices that have no links. The walk first reaches the seed's neighbours, then their neighbours, and the scores settle after a few dozen iterations, as each change is about 0.85 times the one before. A vertex scores high when many short paths lead to it from the seed, so a friend of three friends beats a friend of one. The best vertices that are not yet linked to the seed are its recommendations.

Applications

Social networks use it for "people you may know" suggestions, Twitter's Who To Follow service was built on it, and online shops and streaming services rank products and films by how close they are to what a user already likes. It also finds local communities around a vertex, ranks related pages in search, spreads suspicion from known fraudulent accounts to their close contacts, and in biology finds the proteins most related to a known disease gene.

Pseudocode

Personalized PageRank is PageRank with a home. The random walker follows a random edge with probability d, and otherwise jumps back to one seed vertex instead of to a random page, so the scores measure closeness to the seed.

PersonalizedPageRank(graph, seed, d = 0.85, tol = 0.0001):
    PPR[v] = 0 for every v,  PPR[seed] = 1
    repeat:
        new[v] = 0 for every v
        new[seed] = 1 - d
        for each vertex u, for each neighbor v of u:
            new[v] = new[v] + d * PPR[u] / deg(u)
        (a vertex with no edges returns its share to seed)
        change = max over v of |new[v] - PPR[v]|
        PPR = new
    until change < tol
    return PPR

PPR[v] is the long-run fraction of time a walker restarting at the seed spends at v. Equivalently, it is a weighted sum over all walks from the seed to v, where a walk of length k is weighted by (1 - d) d^k times its probability. Short walks dominate, so vertices reachable from the seed by many short routes score highest, which is exactly what friend recommendation needs.

Worked example, step by step

Recommend new friends for A on the example this page loads, a small friendship network in which one person, H, is far more connected than anyone else.

Example graph: Undirected friendships A-B, A-C, A-D, B-C, B-E, C-E, D-E, D-F, B-G, E-G, F-H, G-H, H-I, H-J and H-K. A already knows B, C and D. H has five friends, the most in the network.

  1. Start at A. All of the probability sits on A.
  2. Iteration 1. The walker moves to one of the three friends of A with probability 0.85, so B, C and D get 28.3 percent each, and the remaining 15 percent jumps back to A.
  3. Iteration 2. From B, C and D the walk reaches E, F and G, while much of it flows straight back to A, which climbs to 37.1 percent. E already gets 22.1 percent, because three of the friends of A lead to it.
  4. Iterations 3 and 4. The walk reaches H in iteration 3, and I, J and K behind it in iteration 4. Every step away from A costs a factor of 0.85, and every restart pulls mass back, so the far side of the network stays light.
  5. Convergence. The scores settle after 29 iterations, with the largest change below 0.0001.

The final scores are A 25.3 percent, B 15.5, C 13.1, E 12.3, D 11.7, G 7.1, H 6.9, F 4.5, and 1.2 each for I, J and K. Leaving out A and the people A already knows, the recommendations are E (12.3), G (7.1) and H (6.9). E shares three friends with A and comes first. Plain PageRank on the same graph puts H on top with 18.7 percent, because it only sees that H is the best connected person, not that H is far from A.

Complexity, and where it comes from

Time: O(k (V + E)) per seed · Space: O(V)

Each iteration of power iteration passes over every edge once, O(V + E), and the error shrinks by a factor of about d per iteration, so k is a few dozen for typical tolerances, 29 here. Computing it for one seed therefore costs about as much as plain PageRank. For large graphs, local push methods such as that of Andersen, Chung and Lang approximate the vector in time that depends on the tolerance and the restart probability but not on the size of the graph, because they only touch vertices near the seed. Monte Carlo estimation with a few thousand short random walks is another common approach in production recommenders.

When to use Personalized PageRank, and when not to

Several measures rank vertices by their relation to one seed. They differ in how far they look and how they treat hubs.

AlternativePrefer it whenCost
PageRankYou want global importance, the same ranking for every user, rather than relevance to one seed.O(k (V + E))
Common neighbours or Adamic-AdarOnly friends of friends matter. Counting shared neighbours, weighted down for popular ones, is cheaper and often as good.O(sum of degrees squared)
Katz indexYou want all paths between two vertices counted, with geometric decay by length, without the random walk normalisation.matrix inversion
Node embeddingsLarge graphs where similarity should also capture structural roles. Methods like node2vec train on random walks.training cost

Common pitfalls

  • Recommending what is already there. The seed and its current neighbours always score highest. Filter them out before ranking, as the visualizer does, or the top recommendations are useless.
  • Choosing the restart probability blindly. With a high restart probability, 1 - d, the scores stay very local and reduce almost to common neighbours. As d approaches 1 they approach global PageRank and lose the personalisation. Tune d for the application.
  • Rewarding hubs. Highly connected vertices collect walk mass from everywhere. Dividing PPR by degree, or by global PageRank, gives a score that measures relative closeness and is widely used in local clustering.
  • Recomputing from scratch for every user. Full power iteration per user does not scale to millions of users. Use local push or Monte Carlo approximations, which only explore the neighbourhood of the seed.

Frequently asked questions

What is personalized PageRank?
Personalized PageRank, also called random walk with restart, is PageRank in which the random jump always returns to a chosen seed vertex or set of vertices. The resulting scores measure how relevant every vertex is to the seed rather than how important it is globally.
What is the difference between PageRank and personalized PageRank?
In PageRank the random surfer jumps to a uniformly random page, so the scores are the same for everyone. In personalized PageRank the surfer jumps back to the seed, so the scores depend on who the seed is and favour vertices close to it.
How is personalized PageRank used for recommendations?
Compute PPR with the user as the seed, remove the user and the items or friends they already have, and recommend the highest scoring remaining vertices. Pinterest, Twitter and others have built recommendation systems on this principle.
What is the restart probability in personalized PageRank?
It is 1 - d, the chance that the walker returns to the seed at each step, typically 0.15. A larger restart probability keeps the scores more local to the seed, a smaller one spreads them further through the network.
How is personalized PageRank computed on large graphs?
Instead of power iteration over the whole graph, large systems use local push algorithms, which only update vertices near the seed, or Monte Carlo simulation of short random walks. Both give accurate approximations in time independent of the graph size.

Related algorithms: PageRank, Betweenness Centrality, Label Propagation, Breadth-First Search

Interactive Controls

Zoom Controls

32%
Nodes: 11
Edges: 15