Python Forum

Full Version: Centralities for Weighted Networks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm making the switch from Matlab to Python for purposes of performing basic network analyses, and I'm a little confused as to how weights are factored in when computing centralities using Networkx. I apologize if this post is not formatted exactly as it should be.

Below I create a simple weighted, undirected network comprised of five nodes. I first enter the adjacency matrix and construct the graph G.

import numpy as npy
import networkx as nx
A=npy.matrix([[0,3,7,0,0],[3,0,6,0,0],[7,6,0,2,1],[0,0,2,0,4],[0,0,1,4,0]])
G=nx.from_numpy_matrix(A)
BC=nx.betweenness_centrality(G,normalized=False)
The output I obtain shows that the betweenness centralities are all zero except at node three, where it is four. This is true for the unweighted version but not for the weighted. For the weighted version, when shortest paths are defined using the original weights, the betweenness is zero except at node three, where it is 5. When shortest paths are defined using link distances (reciprocals of original weights), the centrality is 5 at node 3, 3 at node 4, and zero otherwise. All these values can be verified easily using simple hand calculations.

I've looked a the networkx documentation, and it's clear I'm missing something fundamental with regards to what option I should be adding to the nx.betweenness_centrality command so as to factor in edge weights. Any clarification would be very much appreciated.