I am using python and networkx to model which speaker mentions which item in a conversation. To this end, I want to build a bipartite graph, where one set of nodes represents the speakers and the other represents the items. From this graph, I want to calculate some centrality measures for example betweenness centrality. I also want to pass the weight of each edge as an argument, where the weight represents how often the speaker has mentioned an item. However, the bipartite implementation doesn't allow me to pass weight as an argument.
What is the difference between the implementations and which one should I use to model my problem?
import networkx as nx
from networkx.algorithms import bipartite
speakers = ['Pink', 'Green']
items = ['Knife', 'Rope']
B = nx.Graph()
B.add_nodes_from(items, bipartite = 0)
B.add_nodes_from(speakers, bipartite = 1)
B.add_edge('Pink', 'Knife', weight = 10)
B.add_edge('Pink', 'Rope', weight = 4)
B.add_edge('Green', 'Rope', weight = 2)
B.add_edge('Green', 'Knife', weight = 7)
bottom_nodes, top_nodes = bipartite.sets(B)
print(nx.is_bipartite(B))
print(bipartite.betweenness_centrality(B, bottom_nodes))
print(nx.betweenness_centrality(B))
print(nx.betweenness_centrality(B, weight = 'weight'))
I get the following output:
True
{'Knife': 0.25, 'Rope': 0.25, 'Pink': 0.25, 'Green': 0.25}
{'Knife': 0.16666666666666666, 'Rope': 0.16666666666666666, 'Pink': 0.16666666666666666, 'Green': 0.16666666666666666}
{'Knife': 0.0, 'Rope': 0.3333333333333333, 'Pink': 0.0, 'Green': 0.3333333333333333}
I expect the results to be the same; so what is the difference in the implementation?
bipartite.betweenness_centralitycome from (what package, is it also networkx?)? Also, what sort of values does'weight'have, and what do you get if you ignore it? It may help if you check minimal reproducible example. - Joel