ClosenessCentrality[g]
finds the closeness centrality.
ClosenessCentrality
ClosenessCentrality[g]
finds the closeness centrality.
Details and Options
- ClosenessCentrality functionality is now available in the built-in Wolfram Language function ClosenessCentrality.
- To use ClosenessCentrality, you first need to load the Graph Utilities Package using Needs["GraphUtilities`"].
- The closeness centrality of a vertex u is defined as the inverse of the sum of the distance from u to all other vertices. The closeness centrality of a vertex in a disconnected graph is based on the closeness centrality of the component where this vertex belongs.
- The following options can be given:
-
Weighted True whether edge weight is to be used in calculating distance Normalize False whether to normalize the output
Examples
open all close allBasic Examples (2)
Needs["GraphUtilities`"]g = {1 -> 2, 2 -> 1, 2 -> 3, 3 -> 2};GraphPlot[g, VertexLabeling -> True, DirectedEdges -> True]Compute the closeness centrality:
ClosenessCentrality[g, "Normalize" -> True]This function has been superseded by ClosenessCentrality in the Wolfram System:
g = Graph[{1 -> 2, 2 -> 1, 2 -> 3, 3 -> 2}]ClosenessCentrality[g]Scope (1)
Needs["GraphUtilities`"]This defines a disconnected graph and finds the closeness centrality:
g = {1 -> 2, 2 -> 3, 3 -> 1, 4 -> 5, 5 -> 6, 6 -> 7, 7 -> 8, 8 -> 4};GraphPlot[g, VertexLabeling -> True]Thread[VertexList[g] -> ClosenessCentrality[g]]Options (1)
Weighted (1)
This defines a graph with edge weights:
Needs["GraphUtilities`"]g = {{0, 2.}, {1, .0}};GraphPlot[{{1 -> 2, 2.}, {2 -> 1, 1.}}, VertexLabeling -> True]By default, edge weights are taken into account:
ClosenessCentrality[g]This gives the closeness centrality if edge weights are assumed to be 1.:
ClosenessCentrality[g, Weighted -> False]Applications (1)
A plot of a grid graph with vertices of high centrality in red:
Needs["GraphUtilities`"]g = GridGraph[10, 14];
cs = ClosenessCentrality[g];
color = 0.7 * (1 - cs / Max[cs]);
GraphPlot[g, Method -> None, VertexRenderingFunction -> ({Hue[color[[#3]]], Disk[#, .2]}&)]Properties & Relations (1)
Needs["GraphUtilities`"]The centrality of a vertex that cannot reach all other vertices in its component is zero:
ClosenessCentrality[{1 -> 2}]The centrality of a disconnected graph is calculated by treating each component separately:
ClosenessCentrality[{1 -> 2, 3 -> 4}]See Also
Tech Notes
Related Guides
-
▪
- Graph Utilities Package ▪
- Graphs & Networks ▪
- Graph Visualization ▪
- Computation on Graphs ▪
- Graph Construction & Representation ▪
- Graphs and Matrices ▪
- Graph Properties & Measurements ▪
- Graph Operations and Modifications ▪
- Statistical Analysis ▪
- Social Network Analysis ▪
- Graph Properties ▪
- Mathematical Data Formats ▪
- Discrete Mathematics
Text
Wolfram Research (2007), ClosenessCentrality, Wolfram Language function, https://reference.wolfram.com/language/GraphUtilities/ref/ClosenessCentrality.html.
CMS
Wolfram Language. 2007. "ClosenessCentrality." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/GraphUtilities/ref/ClosenessCentrality.html.
APA
Wolfram Language. (2007). ClosenessCentrality. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/GraphUtilities/ref/ClosenessCentrality.html
BibTeX
@misc{reference.wolfram_2026_closenesscentrality, author="Wolfram Research", title="{ClosenessCentrality}", year="2007", howpublished="\url{https://reference.wolfram.com/language/GraphUtilities/ref/ClosenessCentrality.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_closenesscentrality, organization={Wolfram Research}, title={ClosenessCentrality}, year={2007}, url={https://reference.wolfram.com/language/GraphUtilities/ref/ClosenessCentrality.html}, note=[Accessed: 13-June-2026]}