I'm having some trouble with successfully calculating Katz centrality in a weighted network and would like to see if anyone has an example of it being implemented in NetworkX. I'm getting negative numbers as outputs. Here's the code I have so far:
#katz centrality
G = nx.from_numpy_matrix(network_matrix)
katz_centrality = nx.katz_centrality_numpy(G, weight = 'weight')
for x in range(16):
print(katz_centrality[x])
Which outputs:
-0.0884332150881479
-0.32425466748018883
-0.3110317711173531
-0.3242546674801888
-0.04185470336734943
0.09838584696311473
0.09838584696311474
0.059865838163826485
0.16708256470211458
0.3491707134096127
0.3033563463599785
0.1478838644009215
0.329818599950434
0.3771672006736501
0.35188750514365186
0.1478838644009215
And for reference, network_matrix looks like this:
[[0. 5. 5. 5. 9. 3. 3. 3. 2. 3. 0. 0. 2. 0. 0. 0.]
[5. 0. 7. 9. 4. 2. 2. 2. 1. 0. 1. 0. 0. 0. 0. 0.]
[5. 7. 0. 7. 4. 1. 1. 1. 0. 0. 1. 0. 0. 0. 0. 0.]
[5. 9. 7. 0. 4. 2. 2. 2. 1. 0. 1. 0. 0. 0. 0. 0.]
[9. 4. 4. 4. 0. 2. 2. 2. 1. 4. 0. 0. 2. 0. 0. 0.]
[3. 2. 1. 2. 2. 0. 5. 2. 3. 1. 0. 0. 0. 0. 0. 0.]
[3. 2. 1. 2. 2. 5. 0. 2. 3. 1. 0. 0. 0. 0. 0. 0.]
[3. 2. 1. 2. 2. 2. 2. 0. 2. 1. 0. 0. 0. 0. 0. 0.]
[2. 1. 0. 1. 1. 3. 3. 2. 0. 1. 0. 0. 0. 0. 0. 0.]
[3. 0. 0. 0. 4. 1. 1. 1. 1. 0. 1. 0. 3. 1. 1. 0.]
[0. 1. 1. 1. 0. 0. 0. 0. 0. 1. 0. 0. 1. 3. 2. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[2. 0. 0. 0. 2. 0. 0. 0. 0. 3. 1. 0. 0. 1. 1. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 3. 0. 1. 0. 2. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 2. 0. 1. 2. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]
It's strange because from my predictions, my data shows that the centralities towards the top of the outputs should be larger than the ones towards the bottom. I think I am implementing Katz centrality incorrectly and would appreciate any help.