Note
This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.
rustworkx.digraph_closeness_centrality#
- digraph_closeness_centrality(graph, wf_improved=True, parallel_threshold=50)#
Compute the closeness centrality of each node in a
PyDiGraph
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 its 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.This function is multithreaded and will run in parallel if the number of nodes in the graph is above the value of
parallel_threshold
(it defaults to 50). If the function will be running in parallel the env varRAYON_NUM_THREADS
can be used to adjust how many threads will be used.- Parameters:
graph (PyDiGraph) – 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.
parallel_threshold (int) – The number of nodes to calculate the the betweenness centrality in parallel at if the number of nodes in the graph is less than this value it will run in a single thread. The default value is 50
- Returns:
A dictionary mapping each node index to its closeness centrality.
- Return type: