PageRank was originally proposed in the context of World Wide Web (WWW), it takes advantage of the link structure of WWW to produce a global objective 'importance' ranking of webpages that can be used by search engines. This algorithm was proposed in 1997-1998 by Google co-founders Larry Page and Sergey Brin.
With the development of technology and the emergence of enormous correlation data, PageRank has been adopted in many other fields too.
In WWW, hypertexts contained in webpages create links between webpages. Every webpage (node) can have some forward links (via out-edges) and backlinks (via in-edges). In the following graph, A and B are backlinks of C, D is a forward link of C.

Webpages vary greatly in terms of the number of backlinks they have. Naturally, webpages that are more important, authoritative or of high quality are likely to receive more or more important backlinks.
PageRank can be described as this: a page has high rank if the sum of the ranks of its backlinks is high. This covers both the case when a page has many backlinks and when a page has a few highly ranked backlinks.
The ranks (scores) of all pages are computed in a recursive way by starting with any set of ranks and iterating the computation until it converges. In each iteration, a page gives out its rank to all its forward links evenly to contribute to the ranks of the pages it points to; meanwhile every page receives ranks from its backlinks, so the rank of page u after one iteration is:

where Bu is the backlink set of u.
Below shows a steady state of a set of pages:

Consider the following kinds of webpages:
To overcome these problems, a damping factor, whose value is between 0 and 1, is introduced. It gives each webpage a base rank while weakening the ranks passed from backlinks. The rank of page u after one iteration becomes:

where d is the damping factor. For example, when d is 0.7, if a webpage receives 8 ranks in total from backlinks, then the rank of this webpage is updated to 0.7*8 + (1-0.7) = 5.9.
Damping factor can also be understood as the probability that a web surfer randomly jump to a webpage that is not one of the forward links of the current webpage.

Run the following statements on an empty graph to define its structure and insert data:
ALTER GRAPH CURRENT_GRAPH ADD NODE { account () }; ALTER GRAPH CURRENT_GRAPH ADD EDGE { follow ()-[]->() }; INSERT (A:account {_id: "A"}), (B:account {_id: "B"}), (C:account {_id: "C"}), (D:account {_id: "D"}), (E:account {_id: "E"}), (F:account {_id: "F"}), (G:account {_id: "G"}), (H:account {_id: "H"}), (I:account {_id: "I"}), (J:account {_id: "J"}), (K:account {_id: "K"}), (L:account {_id: "L"}), (M:account {_id: "M"}), (N:account {_id: "N"}), (A)-[:follow]->(E), (B)-[:follow]->(E), (C)-[:follow]->(A), (C)-[:follow]->(H), (D)-[:follow]->(J), (E)-[:follow]->(G), (E)-[:follow]->(G), (E)-[:follow]->(I), (E)-[:follow]->(N), (F)-[:follow]->(L), (F)-[:follow]->(B), (H)-[:follow]->(C), (H)-[:follow]->(E), (I)-[:follow]->(E), (J)-[:follow]->(E), (K)-[:follow]->(E), (K)-[:follow]->(M), (L)-[:follow]->(E), (L)-[:follow]->(F), (L)-[:follow]->(N), (M)-[:follow]->(E), (N)-[:follow]->(F);
To load the entire graph to the HDC server hdc-server-1 as my_hdc_graph:
CREATE HDC GRAPH my_hdc_graph ON "hdc-server-1" OPTIONS { nodes: {"*": ["*"]}, edges: {"*": ["*"]}, direction: "undirected", load_id: true, update: "static" }
Algorithm name: page_rank
Name | Type | Spec | Default | Optional | Description |
|---|---|---|---|---|---|
init_value | Float | >0 | 0.2 | Yes | The initial rank assigned to all nodes. |
loop_num | Integer | ≥1 | 5 | Yes | The maximum number of iteration rounds. The algorithm terminates after all iterations are completed. |
damping | Float | (0,1) | 0.8 | Yes | The damping factor. |
weaken | Integer | 1, 2 | 1 | Yes | Keeps it as 1 for PageRank. Sets to 2 will run ArticleRank. |
return_id_uuid | String | uuid, id, both | uuid | Yes | Includes _uuid, _id, or both values to represent nodes in the results. |
limit | Integer | ≥-1 | -1 | Yes | Limits the number of results returned; -1 includes all results. |
order | String | asc, desc | / | Yes | Sorts the results by rank. |
algo(page_rank).params({ projection: "my_hdc_graph", return_id_uuid: "id", init_value: 1, loop_num: 50, damping: 0.8, weaken: 1, order: "desc" }).write({ file: { filename: "rank" } })
Result:
File: rank_id,rank E,2.3906 G,1.15624 F,1.03774 N,0.842146 I,0.67812 B,0.615097 L,0.615097 J,0.36 C,0.333333 A,0.333333 H,0.333333 M,0.28 K,0.2 D,0.2
Writes the rank values from the results to the specified node property. The property type is float.
algo(page_rank).params({ projection: "my_hdc_graph", loop_num: 50, weaken: 1 }).write({ db:{ property: "rank" } })
exec{ algo(page_rank).params({ return_id_uuid: "id", init_value: 1, loop_num: 50, damping: 0.8, weaken: 1, order: "desc", limit: 5 }) as PR return PR } on my_hdc_graph
Result:
| _id | rank |
|---|---|
| E | 2.390599 |
| G | 1.15624 |
| F | 1.037742 |
| N | 0.842146 |
| I | 0.67812 |
exec{ algo(page_rank).params({ return_id_uuid: "id", loop_num: 50, damping: 0.8, weaken: 1, order: "desc", limit: 5 }).stream() as PR return PR } on my_hdc_graph
Result:
| _id | rank |
|---|---|
| E | 2.390599 |
| G | 1.15624 |
| F | 1.037742 |
| N | 0.842146 |
| I | 0.67812 |
To project the entire graph to its shard servers as myProj:
CREATE PROJECTION myProj OPTIONS { nodes: {"*": ["*"]}, edges: {"*": ["*"]}, direction: "undirected", load_id: true }
Algorithm name: page_rank
Name | Type | Spec | Default | Optional | Description |
|---|---|---|---|---|---|
init_value | Float | >0 | 0.2 | Yes | The initial rank assigned to all nodes. |
loop_num | Integer | ≥1 | 10 | Yes | The maximum number of iteration rounds. The algorithm will terminate after completing all rounds. |
damping | Float | (0,1) | 0.8 | Yes | The damping factor. |
weaken | Integer | 1, 2 | 1 | Yes | Keeps it as 1 for PageRank. Sets to 2 will run ArticleRank. |
limit | Integer | ≥-1 | -1 | Yes | Limits the number of results returned; -1 includes all results. |
order | String | asc, desc | / | Yes | Sorts the results by rank. |
algo(page_rank).params({ projection: "myProj", init_value: 1, loop_num: 50, damping: 0.8, weaken: 1, order: "desc" }).write({ file: { filename: "rank" } })
Result:
File: rank_id,rank E,2.3906 G,1.15624 F,1.03774 N,0.842146 I,0.67812 B,0.615097 L,0.615097 J,0.36 C,0.333333 A,0.333333 H,0.333333 M,0.28 K,0.2 D,0.2
Writes the rank values from the results to the specified node property. The property type is double.
algo(page_rank).params({ projection: "myProj", loop_num: 50, weaken: 1 }).write({ db:{ property: "rank" } })