I have an undirected weighted graph:
I manually calculated the centrality for each node.
1 - 0
2 - 1.5
3 - 0
4 - 3
5 - 2
Then I calculated the centrality using this algorithm
import networkx as nx
G = nx.Graph()
adj_matrix = [
[0, 4, 0, 0, 1],
[4, 0, 3, 1, 0],
[0, 3, 0, 4, 0],
[0, 1, 4, 0, 2],
[1, 0, 0, 2, 0],
]
for i in range(len(adj_matrix)):
for j in range(len(adj_matrix[i])):
if adj_matrix[i][j] != 0:
G.add_edge(i, j, weight=adj_matrix[i][j])
betweenness = nx.centrality.betweenness_centrality(G, k=None, normalized=False, weight="weight", endpoints=False, seed=None)
print(betweenness)
And got slightly different values.
1 - 0
2 - 1.667
3 - 0
4 - 3.167
5 - 2.167
Why are they different? I tried to use direct calculation of deltas instead of a recursive formula in the program.
CityOS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5