How to calculate the closeness centrality of the node in a directed graph step by step?

Viewed 175

I have a simple directed network graph object G. It is created as follows:

import networkx as nx

G = nx.DiGraph()

nodes = ["A","B","C","D","E","F","G","H"]

G.add_nodes_from(nodes)

G.add_edges_from([("A","B"), ("A","C"),
                  ("B","D"), ("B", "E"),
                  ("C", "F"), ("C", "G"), ("C","H")])

pos = {"A":(10, 10),
      "B":(7.5, 7.5), "C":(12.5, 7.5),
      "D":(6, 6), "E":(9, 6),
      "F":(11, 6), "G":(14, 6), "H":(17, 6)}

nx.draw_networkx(G, pos = pos, arrows = True,
                 node_shape = "s", node_color = "white")

It looks as shown below. A is the root node. B and C are intermediate nodes. And D, E, F, G, and H are leaves. enter image description here

Closeness centrality is calculated as the average of the shortest path length from the node to every other node in the network according to this source page 27.

I can calculate the closeness centrality of this graph using nx.closeness_centrality(G). And I get the following results:

{'A': 0.0,
 'B': 0.14285714285714285,
 'C': 0.14285714285714285,
 'D': 0.19047619047619047,
 'E': 0.19047619047619047,
 'F': 0.19047619047619047,
 'G': 0.19047619047619047,
 'H': 0.19047619047619047}

The closeness centrality of A is 0 because it is the root node. The closeness centrality of B and C are 1/7 because the distance from A is 1 and from all other nodes is 0. I think it is calculated as (1+0+0+0+0+0+0)/7. However, I cannot understand why the closeness centrality of other nodes is same. Their value is equivalent to 2/10.5. I am not sure how it is calculated.

Is it possible to show how the closeness centrality is calculated step by step rather than getting it directly from nx.closeness_centrality(G)?

0 Answers
Related