2014-10-27 66 views
1

我在大型网络中检测到社区,并且在igraph Python中的模块化程度较低。我怀疑结果。所以我在igraph R中再次尝试。模块化要高得多。我不知道原因。在下面,我将写一个示例网络和我使用的代码。igraph R和Python中社区检测功能的不同结果

图表:(NcoI位格式是无向图的第三列是重量。)

1 2 123 
1 3 32 
2 3 523 
3 6 3 
6 5 11 
6 8 234 
5 8 324 
3 9 234 
9 11 32 
9 12 5534 
9 13 32 
11 12 322 
11 13 3 
12 13 32 

R代码里面:

library(igraph) 
g=read.graph('graph.ncol',format='ncol',directed=F) 
c=multilevel.community(g) 
modularity(c) 
[1] 0.2845496 

Python代码:

import igraph 
g=igraph.Graph.Read_Ncol('graph.ncol',directed=False) 
c=g.community_multilevel() 
c.modularity 
0.4974489795918367 

在我的原始网络中,使用R和Python的社区数量大不相同。它不仅是多层次的方法。我也尝试了fastgreedy方法。使用R和Python的结果也不同。

回答

2

R接口在计算社区结构和模块性时会自动使用来自weight属性的权重,而Python接口不会。例如,在Python中:

>>> g=load("test.ncol", directed=False) 
>>> g.multilevel_community().q 
0.4974489795918367 
>>> g.multilevel_community(weights=g.es["weight"]).q 
0.2845496103894415 
+0

谢谢!我应该小心使用igraph Python。 – Ben 2014-10-27 13:06:54