Implementation:Haifengl Smile PageRank
| Knowledge Sources | |
|---|---|
| Domains | Graph Analysis, Link Analysis, Linear Algebra |
| Last Updated | 2026-02-08 22:00 GMT |
Overview
PageRank is an interface providing static methods to compute the PageRank vector of a graph using the power iteration method.
Description
The PageRank interface in the smile.math package implements the PageRank link analysis algorithm, which assigns a numerical weighting to each element of a hyperlinked set of documents. The implementation uses the power iteration method to iteratively compute the stationary distribution of a random walk on the graph.
The algorithm supports:
- Default uniform teleportation -- all nodes have equal teleportation probability (1/n)
- Custom teleportation vector -- allows personalized PageRank computation
- Configurable damping factor -- controls the probability of following links vs. teleporting (default: 0.85)
- Convergence tolerance -- the algorithm stops when the L1 change between iterations falls below the tolerance
Usage
Use PageRank when you need to rank nodes in a directed graph by importance, such as ranking web pages, computing influence in social networks, or ordering items in a citation graph.
Code Reference
Source Location
- Repository: Haifengl_Smile
- File: base/src/main/java/smile/math/PageRank.java
- Lines: 1-116
Signature
public interface PageRank {
// PageRank with uniform teleportation
static Vector of(Matrix A);
// PageRank with custom teleportation vector
static Vector of(Matrix A, Vector v);
// PageRank with full control over parameters
static Vector of(Matrix A, Vector v,
double damping, double tol, int maxIter);
}
Import
import smile.math.PageRank;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| A | Matrix |
Yes | A square matrix representing the link structure (must support matrix-vector multiplication) |
| v | Vector |
No | The teleportation vector (default: uniform 1/n for all nodes) |
| damping | double |
No | The damping factor, probability of following a link (default: 0.85) |
| tol | double |
No | The desired convergence tolerance (default: 1E-7) |
| maxIter | int |
No | The maximum number of power iterations (default: 57) |
Outputs
| Name | Type | Description |
|---|---|---|
| pagerank | Vector |
The PageRank vector where each entry represents the importance score of the corresponding node |
Usage Examples
Basic PageRank
// Create an adjacency/transition matrix A
Matrix A = ...; // n x n column-stochastic matrix
Vector ranks = PageRank.of(A);
// ranks[i] gives the PageRank score of node i
Personalized PageRank
Matrix A = ...; // transition matrix
int n = A.nrow();
Vector v = A.vector(n);
// Set personalized teleportation probabilities
v.set(0, 0.5);
v.set(1, 0.3);
v.set(2, 0.2);
Vector ranks = PageRank.of(A, v);
Custom Parameters
Matrix A = ...;
Vector v = ...;
double damping = 0.90;
double tolerance = 1E-10;
int maxIterations = 200;
Vector ranks = PageRank.of(A, v, damping, tolerance, maxIterations);