纽曼图的模块化聚类

机器算法验证 聚类 网络 分区 图形 模块化
2022-04-05 14:11:35

我有兴趣在大图上运行 Newman 的模块化聚类算法。如果您可以将我指向实现它的库(或 R 包等),我将不胜感激。

2个回答

igraph库基于 Newman 的模块化优化实现了一些社区结构算法您可以查阅参考手册以获取详细信息和引用。

使用 R 的 igraph 包:http: //igraph.sourceforge.net/doc/R/fastgreedy.community.html 这使用 newman-girvan 模块化最大化方法实现了社区查找的快速算法。

您的代码将如下所示:

library(igraph)
# read graph from csv file
G<-read.graph("unipartite_edgelist.txt", format="ncol")
fgreedy<-fastgreedy.community(G,merges=TRUE, modularity=TRUE)
memberships <-community.to.membership(G, fgreedy$merges, steps=which.max(fgreedy$modularity)-1)
print(paste('Number of detected communities=',length(memberships$csize)))
    # Community sizes:
    print(memberships$csize)
# modularity:
max(fgreedy$modularity)