Centrality Module
Centrality measures for identifying important nodes in graphs.
Provides degree, closeness, harmonic, betweenness, PageRank, eigenvector, Katz,
and alpha centrality measures. All functions return a Map
Overview
Measure |
Function |
Best For |
Complexity |
|---|---|---|---|
Degree |
degree |
Local connectivity |
O(V + E) |
Closeness |
closeness |
Distance to all others |
O(V(V+E)logV) |
Harmonic |
harmonicCentrality |
Disconnected graphs |
O(V(V+E)logV) |
Betweenness |
betweenness |
Bridge/gatekeeper detection |
O(VE) |
PageRank |
pagerank |
Link-quality importance |
O(iterations×(V+E)) |
Eigenvector |
eigenvector |
Neighbor importance |
O(iterations×(V+E)) |
Katz |
katz |
Attenuated paths |
O(iterations×(V+E)) |
Alpha |
alphaCentrality |
Directed influence |
O(iterations×(V+E)) |
Types
| Type | Description |
|
A mapping of Node IDs to their calculated centrality scores. |
|
|
Specifies which edges to consider for directed graphs. |
|
|
PageRank options for convergence. |
Functions and values
| Function or value |
Description
|
|
Calculates Alpha Centrality for all nodes. Alpha centrality is a generalization of Katz centrality for directed graphs. Unlike Katz, it does not include a constant beta term. Formula: C(v) = α * Σ C(u) for all predecessors u (or neighbors for undirected) Time Complexity: O(max_iterations * (V + E)) Parameters: - alpha: Attenuation factor (typically 0.1-0.5) - initial: Initial centrality value for all nodes
|
Full Usage:
betweenness zero add compare graph
Parameters:
'e
add : 'e -> 'e -> 'e
compare : 'e -> 'e -> int
graph : Graph<'n, 'e>
Returns: Centrality
|
Calculates Betweenness Centrality using Brandes' Algorithm.
|
|
|
|
|
Full Usage:
closeness zero add compare toFloat graph
Parameters:
'e
add : 'e -> 'e -> 'e
compare : 'e -> 'e -> int
toFloat : 'e -> float
graph : Graph<'n, 'e>
Returns: Centrality
|
Calculates Closeness Centrality for all nodes. Closeness centrality measures how close a node is to all other nodes. Formula: C(v) = (n - 1) / Σ d(v, u) for all u ≠ v Note: In disconnected graphs, nodes that cannot reach all others get 0.0. Consider using harmonicCentrality for disconnected graphs. Time Complexity: O(V * (V + E) log V) using Dijkstra from each node
|
|
|
|
|
|
|
Full Usage:
degree mode graph
Parameters:
DegreeMode
graph : Graph<'n, 'e>
Returns: Centrality
|
Calculates the Degree Centrality for all nodes in the graph.
|
|
|
|
|
Full Usage:
harmonicCentrality zero add compare toFloat graph
Parameters:
'e
add : 'e -> 'e -> 'e
compare : 'e -> 'e -> int
toFloat : 'e -> float
graph : Graph<'n, 'e>
Returns: Centrality
|
Calculates Harmonic Centrality for all nodes. Harmonic centrality is a variation of closeness that handles disconnected graphs gracefully. It sums the reciprocals of shortest path distances. Formula: H(v) = Σ (1 / d(v, u)) / (n - 1) for all reachable u ≠ v Time Complexity: O(V * (V + E) log V)
|
|
|
|
|
|
Calculates Katz Centrality for all nodes. Katz centrality adds an attenuation factor (alpha) to prevent infinite accumulation in cycles, plus a constant term (beta) for base centrality. Formula: C(v) = α * Σ C(u) + β for all neighbors u Time Complexity: O(max_iterations * (V + E)) Parameters: - alpha: Attenuation factor (must be < 1/largest_eigenvalue, typically 0.1-0.3) - beta: Base centrality (typically 1.0)
|
Full Usage:
pagerank options graph
Parameters:
PageRankOptions
graph : Graph<'n, 'e>
Returns: Centrality
|
Calculates PageRank Centrality for all nodes.
|