我正在尝试批处理运行python的网络至少100次的模块化分区。我需要保存分区并在分区后保存模块化分数。有没有办法获得它们?我已经尝试了文档和示例,它只返回分区但没有模块化统计信息。请指出正确的方向,我将非常感谢你的帮助。
答案 0 :(得分:1)
您可以使用igraph.Graph.community()
计算模块化分数:
import igraph
g = igraph.Graph.Erdos_Renyi(n=100, p=0.1)
clusters = g.community_multilevel()
modularity_score = g.modularity(clusters.membership)
答案 1 :(得分:0)
Q
中使用louvain
算法估算模块性igraph
的方法。 重要:如果您已加权邻接矩阵,请不要忘记以下函数中的weights=graph.es['weight']
参数!
import numpy as np
from igraph import *
W = np.random.rand(10,10)
np.fill_diagonal(W,0.0)
graph = Graph.Weighted_Adjacency(W.tolist(), mode=ADJ_UNDIRECTED, attr="weight", loops=False)
louvain_partition = graph.community_multilevel(weights=graph.es['weight'], return_levels=False)
modularity1 = graph.modularity(louvain_partition, weights=graph.es['weight'])
print("The modularity Q based on igraph is {}".format(modularity1))
The modularity Q based on igraph is 0.02543865641866777