【问题标题】:Modularity calculation for weighted graphs in igraphigraph中加权图的模块化计算
【发布时间】:2014-10-06 20:44:31
【问题描述】:

我使用 igraph 中的 fastgreedy 算法在加权无向图中进行社区检测。之后我想看看模块化,我得到了不同方法的不同值,我想知道为什么。我包含了一个简短的示例,它演示了我的问题:

library(igraph)
d<-matrix(c(1, 0.2, 0.3, 0.9, 0.9,   
            0.2, 1, 0.6, 0.4, 0.5,  
            0.3, 0.6, 1, 0.1, 0.8,  
            0.9, 0.4, 0.1, 1, 0.5,  
            0.9, 0.5, 0.8, 0.5, 1), byrow=T, nrow=5)    

g<-graph.adjacency(d, weighted=T, mode="lower",diag=FALSE, add.colnames=NA)
fc<-fastgreedy.community(g)

fc$modularity[3]
#[1] -0.05011095
modularity(g,membership=cutat(fc,steps=2),weights=get.adjacency(g,attr="weight"))
#[1] 0.07193047

我希望这两个值是相同的,如果我尝试对未加权图进行相同操作,我会得到相同的值。

d2<-round(d,digits=0)
g2<- graph.adjacency(d2, weighted=NULL, mode="lower",diag=FALSE, add.colnames=NA)
fc2<-fastgreedy.community(g2)
plot(fc2,g2)

fc2$modularity[3]
#[1] 0.15625
modularity(g2,membership=cutat(fc2,steps=2))
#[1] 0.15625

另一个用户有一个similar problem,但我有当前版本的 igraph,所以这应该不是问题。有人可以向我解释为什么存在差异或我的代码有问题吗?

【问题讨论】:

    标签: igraph modularity weighted


    【解决方案1】:

    线

    modularity(g,membership=cutat(fc,steps=2),weights=get.adjacency(g,attr="weight"))
    

    错了。如果您想将边的权重传递给modularity(),请使用E(g)$weight

    modularity(g, membership = cutat(fc, steps = 2), weights = E(g)$weight)
    # [1] -0.05011095
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多