Skip to main content

Module centrality

Module centrality 

Source
Expand description

Centrality — who matters in the graph, five ways. All return a Vec<f32> indexed by node (0..n). Deterministic; no RNG.

Functions§

betweenness
Betweenness centrality (Brandes’ algorithm, undirected, unweighted). The fraction of shortest paths through each node; normalised by (n-1)(n-2) so it lands in [0, 1]. O(n·m).
closeness
Closeness centrality (undirected) — (reachable-1) / Σ dist, scaled by the reachable fraction so nodes in small components aren’t over-rated (Wasserman–Faust). 0.0 for isolated nodes. BFS from each node (unweighted).
degree
Degree centrality — undirected degree normalised by n - 1 (the fraction of other nodes a node is adjacent to). 0.0 for n ≤ 1.
eigenvector
Eigenvector centrality (undirected) via power iteration for iters steps. Iterates (A + I) rather than A — the identity shift makes every eigenvalue positive, curing the bipartite oscillation that traps plain A·x (a star / path never converges because and −λ have equal magnitude). L2-normalised each step. 0.0 everywhere for an edgeless graph (centrality is undefined there).
in_out_degree
In-degree and out-degree centrality (directed), normalised by n - 1.
pagerank
PageRank (directed) with damping d (typically 0.85) for iters power iterations. Dangling nodes (no out-edges) redistribute their mass uniformly. Returns a probability distribution summing to ≈1.