get_ppr
¶
get_ppr(
edge_index: array,
alpha: float = 0.2,
eps: float = 1e-05,
target: Optional[Union[array, Sequence[int]]] = None,
num_nodes: Optional[int] = None,
) -> tuple[array, array]
Computes approximate personalized PageRank (PPR) vectors with the push algorithm of "Local Graph Partitioning using PageRank Vectors", as used in "Predict then Propagate".
The PPR vector of a node i is the stationary distribution of a random
walk along the edges of edge_index that teleports back to i with
probability alpha at each step. Runs on the host (pure Python), so it
is meant for small to medium graphs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
a [2, num_edges] array representing the source and target nodes of each edge |
required |
alpha
|
float
|
Teleport (restart) probability. Default: |
0.2
|
eps
|
float
|
Approximation threshold: residuals below |
1e-05
|
target
|
Optional[Union[array, Sequence[int]]]
|
Nodes whose PPR vectors are computed. Default: |
None
|
num_nodes
|
Optional[int]
|
Number of nodes in the graph. Inferred from |
None
|
Returns:
| Type | Description |
|---|---|
A tuple `(ppr_edge_index, ppr_weights)`
|
an edge |
array
|
weight |
tuple[array, array]
|
|
Example:
edge_index = mx.array([[0, 1, 1, 2], [1, 0, 2, 1]])
ppr_edge_index, ppr_weights = get_ppr(edge_index, target=mx.array([0]))
# ppr_edge_index: mx.array([[0, 0, 0], [0, 1, 2]])
# ppr_weights: e.g. mx.array([0.38, 0.44, 0.18])
Source code in mlx_graphs/utils/ppr.py
from mlx_graphs.utils import get_ppr · mlx_graphs/utils/ppr.py