Usage
The public API.
- page_rank(*, adj=None, edge_index=None, num_nodes=None, add_identity=False, max_iter=1000, alpha=0.05, epsilon=0.0001, x0=None, use_tqdm=False, device=None)[source]
Compute page rank by power iteration.
- Parameters
adj (
Optional[Tensor]) – the adjacency matrix, cf.torch_ppr.utils.prepare_page_rank_adjacency(). Preferred overedge_index.edge_index (
Optional[LongTensor]) – shape:(2, m)the edge index of the graph, i.e, the edge list. cf.torch_ppr.utils.prepare_page_rank_adjacency()num_nodes (
Optional[int]) – the number of nodes used to determine the shape of the adjacency matrix. IfNone, andadjis not already provided, it is inferred fromedge_index.add_identity (
bool) – whether to add an identity matrix toAto ensure that each node has a degree of at least one.max_iter (
int) –max_iter > 0the maximum number of iterationsalpha (
float) –0 < alpha < 1the smoothing value / teleport probabilityepsilon (
float) –epsilon > 0a (small) constant to check for convergencex0 (
Optional[Tensor]) – shape:(n,)the initial value forx. IfNone, set to a constant $1/n$ vector, cf.torch_ppr.utils.prepare_x0(). Otherwise, the tensor is checked for being valid usingtorch_ppr.utils.validate_x().use_tqdm (
bool) – whether to use a tqdm progress bardevice (
Union[None,str,device]) – the device to use, or a hint thereof
- Return type
- Returns
shape:
(n,)or(batch_size, n)the page-rank vector, i.e., a score between 0 and 1 for each node.
- personalized_page_rank(*, adj=None, edge_index=None, add_identity=False, num_nodes=None, indices=None, device=None, batch_size=None, **kwargs)[source]
Personalized Page-Rank (PPR) computation.
Note
this method supports automatic memory optimization / batch size selection using
torch_max_mem.- Parameters
adj (
Optional[Tensor]) – shape:(n, n)the adjacency matrix, cf.torch_ppr.utils.prepare_page_rank_adjacency()edge_index (
Optional[LongTensor]) – shape:(2, m)the edge index, cf.torch_ppr.utils.prepare_page_rank_adjacency()num_nodes (
Optional[int]) – the number of nodes used to determine the shape of the adjacency matrix. IfNone, andadjis not already provided, it is inferred fromedge_index.add_identity (
bool) – whether to add an identity matrix toAto ensure that each node has a degree of at least one.indices (
Optional[Tensor]) – shape:(k,)the node indices for which to calculate the PPR. Defaults to all nodes.batch_size (
Optional[int]) –batch_size > 0the batch size. Defaults to the number of indices. It will be reduced if necessary.kwargs – additional keyword-based parameters passed to
torch_ppr.utils.batched_personalized_page_rank()
- Return type
- Returns
shape:
(k, n)the PPR vectors for each node index