我在大型网络中检测到社区,但在igraph Python中模块化程度较低。我怀疑结果。因此,我在igraph R中再次尝试。模块性更高。我不知道原因。在下面,我将编写一个示例网络和所使用的代码。
图:(ncol格式。图是无向的。第三列是权重。)
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的结果也不同。
最佳答案
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