Reputation: 255
I want to calculate betweenness for a simple graph with 6 nodes:
G=nx.Graph()
e=[(1,2),(1,5),(2,3),(3,6),(5,6),(4,2),(4,3)]
G.add_edges_from(e)
btw=nx.betweenness_centrality(G)
As I calculated for each node the output should be:
{1: 1.5, 2: 2.5, 5: 1, 3: 2.5, 6: 1.5, 4: 0}
But the output is :
{1: 0.15000000000000002,
2: 0.25,
5: 0.1,
3: 0.25,
6: 0.15000000000000002,
4: 0.0}
What is the reason?
Upvotes: 2
Views: 841
Reputation: 88236
It seems you're calculating the non-normalized centrality, whereas by default betweenness_centrality
has normalized
set to True
.
Instead set it to False
:
G=nx.Graph()
e=[(1,2),(1,5),(2,3),(3,6),(5,6),(4,2),(4,3)]
G.add_edges_from(e)
btw=nx.betweenness_centrality(G, normalized=False)
# {1: 1.5, 2: 2.5, 5: 1.0, 3: 2.5, 6: 1.5, 4: 0.0}
Upvotes: 5