---
title: "ClosenessCentrality"
language: "en"
type: "Symbol"
summary: "As of Version 10, all the functionality of the GraphUtilities package is built into the Wolfram System. >>"
keywords: 
- graph centrality graph distance graph geodesic
canonical_url: "https://reference.wolfram.com/language/GraphUtilities/ref/ClosenessCentrality.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Graphs & Networks"
    link: "https://reference.wolfram.com/language/guide/GraphsAndNetworks.en.md"
  - 
    title: "Graph Visualization"
    link: "https://reference.wolfram.com/language/guide/GraphVisualization.en.md"
  - 
    title: "Computation on Graphs"
    link: "https://reference.wolfram.com/language/guide/ComputationOnGraphs.en.md"
  - 
    title: "Graph Construction & Representation"
    link: "https://reference.wolfram.com/language/guide/GraphConstructionAndRepresentation.en.md"
  - 
    title: "Graphs and Matrices"
    link: "https://reference.wolfram.com/language/guide/GraphsAndMatrices.en.md"
  - 
    title: "Graph Properties & Measurements"
    link: "https://reference.wolfram.com/language/guide/GraphPropertiesAndMeasurements.en.md"
  - 
    title: "Graph Operations and Modifications"
    link: "https://reference.wolfram.com/language/guide/GraphModifications.en.md"
  - 
    title: "Statistical Analysis"
    link: "https://reference.wolfram.com/language/guide/RandomGraphs.en.md"
  - 
    title: "Social Network Analysis"
    link: "https://reference.wolfram.com/language/guide/SocialNetworks.en.md"
  - 
    title: "Graph Properties"
    link: "https://reference.wolfram.com/language/guide/GraphProperties.en.md"
  - 
    title: "Mathematical Data Formats"
    link: "https://reference.wolfram.com/language/guide/MathematicalDataFormats.en.md"
  - 
    title: "Discrete Mathematics"
    link: "https://reference.wolfram.com/language/guide/DiscreteMathematics.en.md"
related_functions: 
  - 
    title: "ClosenessCentrality"
    link: "https://reference.wolfram.com/language/ref/ClosenessCentrality.en.md"
  - 
    title: "GraphDistance"
    link: "https://reference.wolfram.com/language/ref/GraphDistance.en.md"
related_tutorials: 
  - 
    title: "Upgrading from Graph Utilities Package"
    link: "https://reference.wolfram.com/language/Compatibility/tutorial/GraphUtilities.en.md"
---
## GraphUtilities\`

# ClosenessCentrality

⚠ As of Version 10, all the functionality of the ``GraphUtilities`` package is built into the Wolfram System. [`>>`](https://reference.wolfram.com/language/ref/ClosenessCentrality.en.md)

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](https://reference.wolfram.com/language/GraphUtilities/guide/GraphUtilitiesPackage.en.md) 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 (6)

### Basic Examples (2)

```wl
In[1]:= Needs["GraphUtilities`"]
```

This defines a small graph:

```wl
In[2]:= g = {1 -> 2, 2 -> 1, 2 -> 3, 3 -> 2};

In[3]:= GraphPlot[g, VertexLabeling -> True, DirectedEdges -> True]

Out[3]= [image]
```

Compute the closeness centrality:

```wl
In[4]:= ClosenessCentrality[g, "Normalize" -> True]

Out[4]= {0.666667, 1., 0.666667}
```

---

This function has been superseded by ``ClosenessCentrality`` in the Wolfram System:

```wl
In[1]:= g = Graph[{1 -> 2, 2 -> 1, 2 -> 3, 3 -> 2}]

Out[1]= [image]

In[2]:= ClosenessCentrality[g]

Out[2]= {0.666667, 1., 0.666667}
```

### Scope (1)

```wl
In[1]:= Needs["GraphUtilities`"]
```

This defines a disconnected graph and finds the closeness centrality:

```wl
In[2]:= g = {1 -> 2, 2 -> 3, 3 -> 1, 4 -> 5, 5 -> 6, 6 -> 7, 7 -> 8, 8 -> 4};

In[3]:= GraphPlot[g, VertexLabeling -> True]

Out[3]= [image]

In[4]:= Thread[VertexList[g] -> ClosenessCentrality[g]]

Out[4]= {1 -> 0.333333, 2 -> 0.333333, 3 -> 0.333333, 4 -> 0.1, 5 -> 0.1, 6 -> 0.1, 7 -> 0.1, 8 -> 0.1}
```

### Options (1)

#### Weighted (1)

This defines a graph with edge weights:

```wl
In[1]:= Needs["GraphUtilities`"]

In[2]:= g = {{0, 2.}, {1, .0}};

In[3]:= GraphPlot[{{1 -> 2, 2.}, {2 -> 1, 1.}}, VertexLabeling -> True]

Out[3]= [image]
```

By default, edge weights are taken into account:

```wl
In[4]:= ClosenessCentrality[g]

Out[4]= {0.5, 1.}
```

This gives the closeness centrality if edge weights are assumed to be 1.:

```wl
In[5]:= ClosenessCentrality[g, Weighted -> False]

Out[5]= {1., 1.}
```

### Applications (1)

A plot of a grid graph with vertices of high centrality in red:

```wl
In[1]:= Needs["GraphUtilities`"]

In[2]:=
g = GridGraph[10, 14];
cs = ClosenessCentrality[g];
color = 0.7 * (1 - cs / Max[cs]);
GraphPlot[g, Method -> None, VertexRenderingFunction -> ({Hue[color[[#3]]], Disk[#, .2]}&)]

Out[2]= [image]
```

### Properties & Relations (1)

```wl
In[1]:= Needs["GraphUtilities`"]
```

The centrality of a vertex that cannot reach all other vertices in its component is zero:

```wl
In[2]:= ClosenessCentrality[{1 -> 2}]

Out[2]= {1., 0.}
```

The centrality of a disconnected graph is calculated by treating each component separately:

```wl
In[3]:= ClosenessCentrality[{1 -> 2, 3 -> 4}]

Out[3]= {1., 0., 1., 0.}
```

## See Also

* [`ClosenessCentrality`](https://reference.wolfram.com/language/ref/ClosenessCentrality.en.md)
* [PageRanks](https://reference.wolfram.com/language/GraphUtilities/ref/PageRanks.en.md)
* [`GraphDistance`](https://reference.wolfram.com/language/ref/GraphDistance.en.md)

## Tech Notes

* [Upgrading from Graph Utilities Package](https://reference.wolfram.com/language/Compatibility/tutorial/GraphUtilities.en.md)
* [Graph Utilities Package](https://reference.wolfram.com/language/GraphUtilities/tutorial/GraphUtilities.en.md)

## Related Guides

* [Graph Utilities Package](https://reference.wolfram.com/language/GraphUtilities/guide/GraphUtilitiesPackage.en.md)
* [Graphs & Networks](https://reference.wolfram.com/language/guide/GraphsAndNetworks.en.md)
* [Graph Visualization](https://reference.wolfram.com/language/guide/GraphVisualization.en.md)
* [Computation on Graphs](https://reference.wolfram.com/language/guide/ComputationOnGraphs.en.md)
* [Graph Construction & Representation](https://reference.wolfram.com/language/guide/GraphConstructionAndRepresentation.en.md)
* [Graphs and Matrices](https://reference.wolfram.com/language/guide/GraphsAndMatrices.en.md)
* [Graph Properties & Measurements](https://reference.wolfram.com/language/guide/GraphPropertiesAndMeasurements.en.md)
* [Graph Operations and Modifications](https://reference.wolfram.com/language/guide/GraphModifications.en.md)
* [Statistical Analysis](https://reference.wolfram.com/language/guide/RandomGraphs.en.md)
* [Social Network Analysis](https://reference.wolfram.com/language/guide/SocialNetworks.en.md)
* [Graph Properties](https://reference.wolfram.com/language/guide/GraphProperties.en.md)
* [Mathematical Data Formats](https://reference.wolfram.com/language/guide/MathematicalDataFormats.en.md)
* [Discrete Mathematics](https://reference.wolfram.com/language/guide/DiscreteMathematics.en.md)