【问题标题】:betweenness with python-igraph and networkxpython-igraph 和 networkx 的介数
【发布时间】:2019-05-09 21:37:24
【问题描述】:

我有一个包含 250,000 个节点和 100 万条边的大图来计算它的顶点介数(没有任何权重)。我的目标是使用 python-igraph 来完成这项工作,因为它支持与其他一些包的并行计算。当我在具有 100 个顶点的相对较小的格子上比较 python-igarph 和 networkx 的结果时(见图)。我发现它们完全不同。即使对于一个有 9 个节点的 lattice,igraph 的结果都是 0,而 networkx 的结果似乎是正确的。谁能帮我解决python-igraph的这个问题?

代码如下:

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 hereenter image description here

【问题讨论】:

  • 能否直接提供代码(以便我们复制和粘贴)而不是图片?
  • 好的,谢谢您的回复。下面是一个 10*10 格子的测试代码。
  • 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=假) bt2 = nx.betweenness_centrality(G_la) print("\tBetweenness of networkx:") print (bt2)
  • 对不起。我只是不知道如何在评论中格式化这些代码。这是我第一次使用 Stackoverflow。
  • 您可以直接编辑您的帖子。我刚刚编辑了它。你能检查我做的一切正确吗?特别是,请确保我的缩进没有任何问题。另外,您可以编辑它并添加导入语句吗?

标签: python-2.7 networkx igraph


【解决方案1】:

根据我对 igraph Lattice 函数的 documentation 的阅读,作为参数的数字 4 意味着一个节点将连接到格子上最多 4 步远的任何节点。 networkx 图只会连接到 4 个最近的邻居。所以 igraph 有更多的连接。在 9 节点示例中,igraph 连接了所有节点。

需要明确的是,networkx 会将节点 (1,1)(1,0)(0,1)(1,2)(2,1) 连接起来,而您的 igraph 命令将它与所有这些连接起来,而且还连接到 (1,3)(1,4)(1,5)(0,4) 等等。 (我没有明确检查,因为 igraph 不在我的计算机上,但我相当确定这是对文档的正确理解)。

【讨论】:

  • 非常感谢。你说的对。我只是真的误解了 igraph 功能。非常感谢您为我解释这个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-07
  • 1970-01-01
  • 1970-01-01
  • 2021-04-27
  • 1970-01-01
相关资源
最近更新 更多