1
$\begingroup$

I am using the following code to try implement eigen-vector centrality for a weighted graph G. The nodes represent search terms and the is an edge from node A to node B if someone searches for A and then B. The edge weight is the number of times this happens i.e. the number of time someone searches for A and then searches for B.

import networkx as nx

G = nx.DiGraph()
G.add_node(1)
G.add_node(2)


G.add_edge(1,2, weight = 100)
G.add_edge(2,1, weight = 1)


centrality = nx.eigenvector_centrality(G,weight = 'weights', max_iter= 1000) 
print(centrality)

However I am getting identical scores for each node, the output of the above program is: {1: 0.7071067811865476, 2: 0.7071067811865476}

I suspect that the algorithm is not taking the weights into account, otherwise the scores would be different (?)

How can I can I make the program look at weights?

$\endgroup$

1 Answer 1

1
$\begingroup$

Although this is several years old, if someone has the same question: You have a typo, use weight='weight' (since that is what you called your edge weights), and it works perfectly.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.