I have a large graph with 250,000 nodes and 1 million edges to calculate its vertice betweenness (without any weight). I aim to use python-igraph to complete this work because it supports parallel computation with some other packages. When I compare the results from python-igarph and networkx on a relative small latttice with 100 vertices (see the figure). I find they are completely different. Even for a lattice with 9 nodes, the results of igraph are all 0 while the those of networkx seems to be right. Who can help me with this problem of python-igraph?
Here is the code:
from igraph import *
import networkx as nx
print("\tUse python-igraph with Vertices=100 ")
ig = Graph.Lattice([10, 10], 4, False, False, False)
bt1 = ig.betweenness(directed=False, cutoff=None,nobigint=False)
print("\tBetweenness of python-igraph:")
print(bt1)
print("\tUse networkx with Vertices=100")
G_la= nx.grid_2d_graph(10,10,periodic=False)
bt2 = nx.betweenness_centrality(G_la)
print("\tBetweenness of networkx:")
print (bt2)
enter image description here enter image description hereenter image description here
Based on my reading of the documentation for the igraph Lattice, function, the number 4 you have as its argument means that a node will be connected to any node which is at most 4 steps away on the lattice. The networkx graph will only connect to the 4 nearest neighbors. So igraph has a lot more connections. In the 9-node example, igraph has all nodes connected.
To be clear, networkx would connect the node (1,1) with (1,0), (0,1), (1,2), and (2,1), while your igraph command connects it with all of those, but also (1,3), (1,4), (1,5), (0,4), and many others. (I haven't explicitly checked as igraph isn't on my computer, but I'm fairly certain this is the correct understanding of the documentation).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With