rustworkx.closeness_centrality#
- closeness_centrality(graph, wf_improved=True)[source]#
Compute the closeness centrality of each node in a graph object.
The closeness centrality of a node
is defined as the reciprocal of the average shortest path distance to over all reachable nodes in the graph. In it’s general form this can be expressed as:where:
- the shortest-path distance between and - the number of nodes that can reach .
In the case of a graphs with more than one connected component there is an alternative improved formula that calculates the closeness centrality as “a ratio of the fraction of actors in the group who are reachable, to the average distance” [WF]. This can be expressed as
where
is the number of nodes in the graph. This alternative formula can be used with thewf_improved
argument.- Parameters:
graph – The input graph. Can either be a
PyGraph
orPyDiGraph
.wf_improved (bool) – This is optional; the default is True. If True, scale by the fraction of nodes reachable.
- Returns:
A dictionary mapping each node index to its closeness centrality.
- Return type:
dict
[WF]Wasserman, S., & Faust, K. (1994). Social Network Analysis: Methods and Applications (Structural Analysis in the Social Sciences). Cambridge: Cambridge University Press. doi:10.1017/CBO9780511815478