PageRank
Glossary
 Directed

Directed trait. The algorithm is welldefined on a directed graph.
 Undirected

Undirected trait. The algorithm is welldefined on an undirected graph.
 Homogeneous

Homogeneous trait. The algorithm will treat all nodes and relationships in its input graph(s) similarly, as if they were all of the same type. If multiple types of nodes or relationships exist in the graph, this must be taken into account when analysing the results of the algorithm.
 Heterogeneous

Heterogeneous trait. The algorithm has the ability to distinguish between nodes and/or relationships of different types.
 Weighted

Weighted trait. The algorithm supports configuration to set node and/or relationship properties to use as weights. These values can represent cost, time, capacity or some other domainspecific properties, specified via the nodeWeightProperty, nodeProperties and relationshipWeightProperty configuration parameters. The algorithm will by default consider each node and/or relationship as equally important.
1. Introduction
The PageRank algorithm measures the importance of each node within the graph, based on the number incoming relationships and the importance of the corresponding source nodes. The underlying assumption roughly speaking is that a page is only as important as the pages that link to it.
PageRank is introduced in the original Google paper as a function that solves the following equation:
where,

we assume that a page A has pages T_{1} to T_{n} which point to it.

d is a damping factor which can be set between 0 (inclusive) and 1 (exclusive). It is usually set to 0.85.

C(A) is defined as the number of links going out of page A.
This equation is used to iteratively update a candidate solution and arrive at an approximate solution to the same equation.
For more information on this algorithm, see:
Running this algorithm requires sufficient memory availability. Before running this algorithm, we recommend that you read Memory Estimation. 
2. Considerations
There are some things to be aware of when using the PageRank algorithm:

If there are no relationships from within a group of pages to outside the group, then the group is considered a spider trap.

Rank sink can occur when a network of pages is forming an infinite cycle.

Deadends occur when pages have no outgoing relationship.
Changing the damping factor can help with all the considerations above. It can be interpreted as a probability of a web surfer to sometimes jump to a random page and therefore not getting stuck in sinks.
3. Syntax
This section covers the syntax used to execute the PageRank algorithm in each of its execution modes. We are describing the named graph variant of the syntax. To learn more about general syntax variants, see Syntax overview.
CALL gds.pageRank.stream(
graphName: String,
configuration: Map
)
YIELD
nodeId: Integer,
score: Float
Name  Type  Default  Optional  Description 

graphName 
String 

no 
The name of a graph stored in the catalog. 
configuration 
Map 

yes 
Configuration for algorithmspecifics and/or graph filtering. 
Name  Type  Default  Optional  Description 

List of String 

yes 
Filter the named graph using the given node labels. 

List of String 

yes 
Filter the named graph using the given relationship types. 

Integer 

yes 
The number of concurrent threads used for running the algorithm. 

String 

yes 
An ID that can be provided to more easily track the algorithm’s progress. 

Boolean 

yes 
If disabled the progress percentage will not be logged. 

dampingFactor 
Float 

yes 
The damping factor of the Page Rank calculation. Must be in [0, 1). 
Integer 

yes 
The maximum number of iterations of Page Rank to run. 

Float 

yes 
Minimum change in scores between iterations. If all scores change less than the tolerance value the result is considered stable and the algorithm returns. 

String 

yes 
Name of the relationship property to use as weights. If unspecified, the algorithm runs unweighted. 

sourceNodes 
List of Node or Number 

yes 
The nodes or node ids to use for computing Personalized Page Rank. 
scaler 
String 

yes 
The name of the scaler applied for the final scores. Supported values are 
Name  Type  Description 

nodeId 
Integer 
Node ID. 
score 
Float 
PageRank score. 
CALL gds.pageRank.stats(
graphName: String,
configuration: Map
)
YIELD
ranIterations: Integer,
didConverge: Boolean,
preProcessingMillis: Integer,
computeMillis: Integer,
postProcessingMillis: Integer,
centralityDistribution: Map,
configuration: Map
Name  Type  Default  Optional  Description 

graphName 
String 

no 
The name of a graph stored in the catalog. 
configuration 
Map 

yes 
Configuration for algorithmspecifics and/or graph filtering. 
Name  Type  Default  Optional  Description 

List of String 

yes 
Filter the named graph using the given node labels. 

List of String 

yes 
Filter the named graph using the given relationship types. 

Integer 

yes 
The number of concurrent threads used for running the algorithm. 

String 

yes 
An ID that can be provided to more easily track the algorithm’s progress. 

Boolean 

yes 
If disabled the progress percentage will not be logged. 

dampingFactor 
Float 

yes 
The damping factor of the Page Rank calculation. Must be in [0, 1). 
Integer 

yes 
The maximum number of iterations of Page Rank to run. 

Float 

yes 
Minimum change in scores between iterations. If all scores change less than the tolerance value the result is considered stable and the algorithm returns. 

String 

yes 
Name of the relationship property to use as weights. If unspecified, the algorithm runs unweighted. 

sourceNodes 
List of Node or Number 

yes 
The nodes or node ids to use for computing Personalized Page Rank. 
scaler 
String 

yes 
The name of the scaler applied for the final scores. Supported values are 
Name  Type  Description 

ranIterations 
Integer 
The number of iterations run. 
didConverge 
Boolean 
Indicates if the algorithm converged. 
preProcessingMillis 
Integer 
Milliseconds for preprocessing the graph. 
computeMillis 
Integer 
Milliseconds for running the algorithm. 
postProcessingMillis 
Integer 
Milliseconds for computing the 
centralityDistribution 
Map 
Map containing min, max, mean as well as p50, p75, p90, p95, p99 and p999 percentile values of centrality values. 
configuration 
Map 
The configuration used for running the algorithm. 
CALL gds.pageRank.mutate(
graphName: String,
configuration: Map
)
YIELD
nodePropertiesWritten: Integer,
ranIterations: Integer,
didConverge: Boolean,
preProcessingMillis: Integer,
computeMillis: Integer,
postProcessingMillis: Integer,
mutateMillis: Integer,
centralityDistribution: Map,
configuration: Map
Name  Type  Default  Optional  Description 

graphName 
String 

no 
The name of a graph stored in the catalog. 
configuration 
Map 

yes 
Configuration for algorithmspecifics and/or graph filtering. 
Name  Type  Default  Optional  Description 

mutateProperty 
String 

no 
The node property in the GDS graph to which the score is written. 
List of String 

yes 
Filter the named graph using the given node labels. 

List of String 

yes 
Filter the named graph using the given relationship types. 

Integer 

yes 
The number of concurrent threads used for running the algorithm. 

String 

yes 
An ID that can be provided to more easily track the algorithm’s progress. 

dampingFactor 
Float 

yes 
The damping factor of the Page Rank calculation. Must be in [0, 1). 
Integer 

yes 
The maximum number of iterations of Page Rank to run. 

Float 

yes 
Minimum change in scores between iterations. If all scores change less than the tolerance value the result is considered stable and the algorithm returns. 

String 

yes 
Name of the relationship property to use as weights. If unspecified, the algorithm runs unweighted. 

sourceNodes 
List of Node or Number 

yes 
The nodes or node ids to use for computing Personalized Page Rank. 
scaler 
String 

yes 
The name of the scaler applied for the final scores. Supported values are 
Name  Type  Description 

ranIterations 
Integer 
The number of iterations run. 
didConverge 
Boolean 
Indicates if the algorithm converged. 
preProcessingMillis 
Integer 
Milliseconds for preprocessing the graph. 
computeMillis 
Integer 
Milliseconds for running the algorithm. 
postProcessingMillis 
Integer 
Milliseconds for computing the 
mutateMillis 
Integer 
Milliseconds for adding properties to the projected graph. 
nodePropertiesWritten 
Integer 
The number of properties that were written to the projected graph. 
centralityDistribution 
Map 
Map containing min, max, mean as well as p50, p75, p90, p95, p99 and p999 percentile values of centrality values. 
configuration 
Map 
The configuration used for running the algorithm. 
CALL gds.pageRank.write(
graphName: String,
configuration: Map
)
YIELD
nodePropertiesWritten: Integer,
ranIterations: Integer,
didConverge: Boolean,
preProcessingMillis: Integer,
computeMillis: Integer,
postProcessingMillis: Integer,
writeMillis: Integer,
centralityDistribution: Map,
configuration: Map
Name  Type  Default  Optional  Description 

graphName 
String 

no 
The name of a graph stored in the catalog. 
configuration 
Map 

yes 
Configuration for algorithmspecifics and/or graph filtering. 
Name  Type  Default  Optional  Description 

List of String 

yes 
Filter the named graph using the given node labels. 

List of String 

yes 
Filter the named graph using the given relationship types. 

Integer 

yes 
The number of concurrent threads used for running the algorithm. 

String 

yes 
An ID that can be provided to more easily track the algorithm’s progress. 

Boolean 

yes 
If disabled the progress percentage will not be logged. 

Integer 

yes 
The number of concurrent threads used for writing the result to Neo4j. 

String 

no 
The node property in the Neo4j database to which the score is written. 

dampingFactor 
Float 

yes 
The damping factor of the Page Rank calculation. Must be in [0, 1). 
Integer 

yes 
The maximum number of iterations of Page Rank to run. 

Float 

yes 
Minimum change in scores between iterations. If all scores change less than the tolerance value the result is considered stable and the algorithm returns. 

String 

yes 
Name of the relationship property to use as weights. If unspecified, the algorithm runs unweighted. 

sourceNodes 
List of Node or Number 

yes 
The nodes or node ids to use for computing Personalized Page Rank. 
scaler 
String 

yes 
The name of the scaler applied for the final scores. Supported values are 
Name  Type  Description 

ranIterations 
Integer 
The number of iterations run. 
didConverge 
Boolean 
Indicates if the algorithm converged. 
preProcessingMillis 
Integer 
Milliseconds for preprocessing the graph. 
computeMillis 
Integer 
Milliseconds for running the algorithm. 
postProcessingMillis 
Integer 
Milliseconds for computing the 
writeMillis 
Integer 
Milliseconds for writing result data back. 
nodePropertiesWritten 
Integer 
The number of properties that were written to Neo4j. 
centralityDistribution 
Map 
Map containing min, max, mean as well as p50, p75, p90, p95, p99 and p999 percentile values of centrality values. 
configuration 
Map 
The configuration used for running the algorithm. 
4. Examples
In this section we will show examples of running the PageRank algorithm on a concrete graph. The intention is to illustrate what the results look like and to provide a guide in how to make use of the algorithm in a real setting. We will do this on a small web network graph of a handful nodes connected in a particular pattern. The example graph looks like this:
CREATE
(home:Page {name:'Home'}),
(about:Page {name:'About'}),
(product:Page {name:'Product'}),
(links:Page {name:'Links'}),
(a:Page {name:'Site A'}),
(b:Page {name:'Site B'}),
(c:Page {name:'Site C'}),
(d:Page {name:'Site D'}),
(home)[:LINKS {weight: 0.2}]>(about),
(home)[:LINKS {weight: 0.2}]>(links),
(home)[:LINKS {weight: 0.6}]>(product),
(about)[:LINKS {weight: 1.0}]>(home),
(product)[:LINKS {weight: 1.0}]>(home),
(a)[:LINKS {weight: 1.0}]>(home),
(b)[:LINKS {weight: 1.0}]>(home),
(c)[:LINKS {weight: 1.0}]>(home),
(d)[:LINKS {weight: 1.0}]>(home),
(links)[:LINKS {weight: 0.8}]>(home),
(links)[:LINKS {weight: 0.05}]>(a),
(links)[:LINKS {weight: 0.05}]>(b),
(links)[:LINKS {weight: 0.05}]>(c),
(links)[:LINKS {weight: 0.05}]>(d);
This graph represents eight pages, linking to one another.
Each relationship has a property called weight
, which describes the importance of the relationship.
In the examples below we will use named graphs and native projections as the norm. However, Cypher projections can also be used. 
CALL gds.graph.project(
'myGraph',
'Page',
'LINKS',
{
relationshipProperties: 'weight'
}
)
4.1. Memory Estimation
First off, we will estimate the cost of running the algorithm using the estimate
procedure.
This can be done with any execution mode.
We will use the write
mode in this example.
Estimating the algorithm is useful to understand the memory impact that running the algorithm on your graph will have.
When you later actually run the algorithm in one of the execution modes the system will perform an estimation.
If the estimation shows that there is a very high probability of the execution going over its memory limitations, the execution is prohibited.
To read more about this, see Automatic estimation and execution blocking.
For more details on estimate
in general, see Memory Estimation.
CALL gds.pageRank.write.estimate('myGraph', {
writeProperty: 'pageRank',
maxIterations: 20,
dampingFactor: 0.85
})
YIELD nodeCount, relationshipCount, bytesMin, bytesMax, requiredMemory
nodeCount  relationshipCount  bytesMin  bytesMax  requiredMemory 

8 
14 
696 
696 
"696 Bytes" 
4.2. Stream
In the stream
execution mode, the algorithm returns the score for each node.
This allows us to inspect the results directly or postprocess them in Cypher without any side effects.
For example, we can order the results to find the nodes with the highest PageRank score.
For more details on the stream
mode in general, see Stream.
stream
mode:CALL gds.pageRank.stream('myGraph')
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).name AS name, score
ORDER BY score DESC, name ASC
name  score 

"Home" 
3.215681999884452 
"About" 
1.0542700552146722 
"Links" 
1.0542700552146722 
"Product" 
1.0542700552146722 
"Site A" 
0.3278578964488539 
"Site B" 
0.3278578964488539 
"Site C" 
0.3278578964488539 
"Site D" 
0.3278578964488539 
The above query is running the algorithm in stream
mode as unweighted
and the returned scores are not normalized.
Below, one can find an example for weighted graphs.
Another example shows the application of a scaler to normalize the final scores.
While we are using the stream mode to illustrate running the algorithm as weighted or unweighted , all the algorithm modes support this configuration parameter.

4.3. Stats
In the stats
execution mode, the algorithm returns a single row containing a summary of the algorithm result.
For example PageRank stats returns centrality histogram which can be used to monitor the distribution of PageRank score values across all computed nodes.
This execution mode does not have any side effects.
It can be useful for evaluating algorithm performance by inspecting the computeMillis
return item.
In the examples below we will omit returning the timings.
The full signature of the procedure can be found in the syntax section.
For more details on the stats
mode in general, see Stats.
CALL gds.pageRank.stats('myGraph', {
maxIterations: 20,
dampingFactor: 0.85
})
YIELD centralityDistribution
RETURN centralityDistribution.max AS max
max 

3.2156810760498047 
The centrality histogram can be useful for inspecting the computed scores or perform normalizations.
4.4. Mutate
The mutate
execution mode extends the stats
mode with an important side effect: updating the named graph with a new node property containing the score for that node.
The name of the new property is specified using the mandatory configuration parameter mutateProperty
.
The result is a single summary row, similar to stats
, but with some additional metrics.
The mutate
mode is especially useful when multiple algorithms are used in conjunction.
For more details on the mutate
mode in general, see Mutate.
mutate
mode:CALL gds.pageRank.mutate('myGraph', {
maxIterations: 20,
dampingFactor: 0.85,
mutateProperty: 'pagerank'
})
YIELD nodePropertiesWritten, ranIterations
nodePropertiesWritten  ranIterations 



4.5. Write
The write
execution mode extends the stats
mode with an important side effect: writing the score for each node as a property to the Neo4j database.
The name of the new property is specified using the mandatory configuration parameter writeProperty
.
The result is a single summary row, similar to stats
, but with some additional metrics.
The write
mode enables directly persisting the results to the database.
For more details on the write
mode in general, see Write.
write
mode:CALL gds.pageRank.write('myGraph', {
maxIterations: 20,
dampingFactor: 0.85,
writeProperty: 'pagerank'
})
YIELD nodePropertiesWritten, ranIterations
nodePropertiesWritten  ranIterations 



4.6. Weighted
By default, the algorithm is considering the relationships of the graph to be unweighted
, to change this behaviour we can use configuration parameter called relationshipWeightProperty
.
In the weighted
case, the previous score of a node send to its neighbors, is multiplied by the relationship weight and then divided by the sum of the weights of its outgoing relationships.
If the value of the relationship property is negative it will be ignored during computation.
Below is an example of running the algorithm using the relationship property.
stream
mode using relationship weights:CALL gds.pageRank.stream('myGraph', {
maxIterations: 20,
dampingFactor: 0.85,
relationshipWeightProperty: 'weight'
})
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).name AS name, score
ORDER BY score DESC, name ASC
name  score 

"Home" 
3.53751028396339 
"Product" 
1.9357838291651097 
"About" 
0.7452612763883698 
"Links" 
0.7452612763883698 
"Site A" 
0.18152677135466103 
"Site B" 
0.18152677135466103 
"Site C" 
0.18152677135466103 
"Site D" 
0.18152677135466103 
We are using stream mode to illustrate running the algorithm as weighted or unweighted , all the algorithm modes support this configuration parameter.

4.7. Tolerance
The tolerance
configuration parameter denotes the minimum change in scores between iterations.
If all scores change less than the configured tolerance
value the result stabilises, and the algorithm returns.
stream
mode using bigger tolerance
value:CALL gds.pageRank.stream('myGraph', {
maxIterations: 20,
dampingFactor: 0.85,
tolerance: 0.1
})
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).name AS name, score
ORDER BY score DESC, name ASC
name  score 

"Home" 
1.5812450669583336 
"About" 
0.5980194356381945 
"Links" 
0.5980194356381945 
"Product" 
0.5980194356381945 
"Site A" 
0.23374955154166668 
"Site B" 
0.23374955154166668 
"Site C" 
0.23374955154166668 
"Site D" 
0.23374955154166668 
In this example we are using tolerance: 0.1
, so the results are a bit different compared to the ones from stream example which is using the default value of tolerance
.
Note that the nodes 'About', 'Link' and 'Product' now have the same score, while with the default value of tolerance
the node 'Product' has higher score than the other two.
4.8. Damping Factor
The damping factor configuration parameter accepts values between 0 (inclusive) and 1 (exclusive). If its value is too high then problems of sinks and spider traps may occur, and the values may oscillate so that the algorithm does not converge. If it’s too low then all scores are pushed towards 1, and the result will not sufficiently reflect the structure of the graph.
stream
mode using smaller dampingFactor
value:CALL gds.pageRank.stream('myGraph', {
maxIterations: 20,
dampingFactor: 0.05
})
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).name AS name, score
ORDER BY score DESC, name ASC
name  score 

"Home" 
1.2487309425844906 
"About" 
0.9708121818724536 
"Links" 
0.9708121818724536 
"Product" 
0.9708121818724536 
"Site A" 
0.9597081216238426 
"Site B" 
0.9597081216238426 
"Site C" 
0.9597081216238426 
"Site D" 
0.9597081216238426 
Compared to the results from the stream example which is using the default value of dampingFactor
the score values are closer to each other when using dampingFactor: 0.05
.
Also, note that the nodes 'About', 'Link' and 'Product' now have the same score, while with the default value of dampingFactor
the node 'Product' has higher score than the other two.
4.9. Personalised PageRank
Personalized PageRank is a variation of PageRank which is biased towards a set of sourceNodes
.
This variant of PageRank is often used as part of recommender systems.
The following examples show how to run PageRank centered around 'Site A'.
MATCH (siteA:Page {name: 'Site A'})
CALL gds.pageRank.stream('myGraph', {
maxIterations: 20,
dampingFactor: 0.85,
sourceNodes: [siteA]
})
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).name AS name, score
ORDER BY score DESC, name ASC
name  score 

"Home" 
0.39902290442518784 
"Site A" 
0.16890325301726694 
"About" 
0.11220151747374331 
"Links" 
0.11220151747374331 
"Product" 
0.11220151747374331 
"Site B" 
0.01890325301726691 
"Site C" 
0.01890325301726691 
"Site D" 
0.01890325301726691 
Comparing these results to the ones from the stream example (which is not using sourceNodes
configuration parameter) shows that the 'Site A' node that we used in the sourceNodes
list now scores second instead of fourth.
4.10. Scaling centrality scores
To normalize the final scores as part of the algorithm execution, one can use the scaler
configuration parameter.
A common scaler is the L1Norm
, which normalizes each score to a value between 0 and 1.
A description of all available scalers can be found in the documentation for the scaleProperties
procedure.
stream
mode and returns normalized results:CALL gds.pageRank.stream('myGraph', {
scaler: "L1Norm"
})
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).name AS name, score
ORDER BY score DESC, name ASC
name  score 

"Home" 
0.4181682554824872 
"About" 
0.1370975954128506 
"Links" 
0.1370975954128506 
"Product" 
0.1370975954128506 
"Site A" 
0.04263473956974027 
"Site B" 
0.04263473956974027 
"Site C" 
0.04263473956974027 
"Site D" 
0.04263473956974027 
Comparing the results with the stream example, we can see that the relative order of scores is the same.
Was this page helpful?