aryagraph.algorithms.centrality.pagerank#
- aryagraph.algorithms.centrality.pagerank(g: Any, alpha: float = 0.85, personalization: Mapping[Hashable, float] | None = None, weight: str | Callable[[Hashable, Hashable, dict], float] | None = 'weight', max_iter: int = 100, tol: float = 1e-06, dangling: Mapping[Hashable, float] | None = None, nstart: Mapping[Hashable, float] | None = None) NodeMap[source]#
PageRank by vectorised power iteration (
O(m)per step).Undirected graphs are treated as bidirected. A node whose out-weight is 0 is dangling: its mass is redistributed by the dangling vector, which defaults to the personalization vector (uniform unless given). This is exactly the networkx scheme. Stops when the L1 change is below
n·tol.- Parameters:
personalization, dangling, nstart – Node → non-negative value mappings, normalised to sum 1; nodes left out count as 0 (unknown nodes raise
NodeNotFound).- Raises:
ConvergenceError – If max_iter iterations are not enough.
Examples
>>> pr = pagerank(Graph([(1, 2), (2, 3)])) >>> round(sum(pr.values()), 12) 1.0