简体   繁体   English

igraph 中的模块化:2021 年 10 月前后

[英]Modularity in igraph: before and after October 2021

In igraph when I cluster the karate.network ( kar ) with, say, cluster_fast_greedy , to give karfg , using modularity(karfg) gives 0.4345215.在 igraph 中,当我将 karate.network ( kar ) 与cluster_fast_greedy聚类以给出karfg时,使用modularity(karfg)给出 0.4345215。 The deprecated option of including membership包含成员资格的弃用选项
modularity(kar, membership(karfg)) gives 0.399096. modularity(kar, membership(karfg))给出 0.399096。 Is there an explanation for this discrepancy?对这种差异有解释吗? (It is not fastgreedy specific, other community detection methods also give a discrepancy). (不是fastgreedy特有的,其他社区检测方法也给出了出入)。

library(igraph)
library(igraphdata)
data(karate)
kar <- karate
karfg<-cluster_fast_greedy(karate)

modularity(kar, membership(karfg))
0.3990796
modularity(karfg)
0.4345215

This happens because the modularity function does not use edge weights by default, while most community detection functions do.发生这种情况是因为modularity function 默认情况下不使用边权重,而大多数社区检测功能都这样做。 The graph you are working with has a weight edge attribute, which will be used by cluster_fast_greedy() unless you explicitly prevent that.您正在使用的图形具有weight边属性,除非您明确阻止,否则cluster_fast_greedy()将使用该属性。

This is how you can use it in modularity as well:这也是您可以在modularity中使用它的方式:

modularity(karate, membership(karfg), weights=E(karate)$weight)
0.4345215

Note that not all of igraph's community detection functions make use of weights, and those that do may not use it in the same way.请注意,并非所有 igraph 的社区检测功能都使用权重,那些使用权重的人可能不会以相同的方式使用它。 Thus, when you call modularity explicitly, and separately from the community detection function, be careful to specify weights that match with how the community detection was done.因此,当您显式调用modularity时,并且与社区检测 function 分开,请注意指定与社区检测的完成方式相匹配的权重。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM