【发布时间】:2020-03-29 12:29:57
【问题描述】:
我有一个图表,我想根据图表的 Louvain split 估计模块性 (Q)。
在 python 中,我使用 igraph 并进行比较,我还在 Matlab 中估计了 Q。 基于 igraph,Q 为负(奇怪),而基于 Matlab 估计的 Q 为正。
我预计值会有所不同,但到目前为止还没有(+ 表示模块化,- 表示反模块化)。 知道为什么会这样吗?
我的代码和数据(https://gofile.io/?c=h24mcU):
Python
import numpy as np
import scipy.io
from igraph import *
A = scipy.io.loadmat('A.mat')['A']
graph = Graph.Weighted_Adjacency(A.tolist(), mode=ADJ_UNDIRECTED, attr="weight", loops=False)
Louvain = graph.community_multilevel(weights=graph.es['weight'], return_levels=False)
Q = graph.modularity(Louvain)
print(Q)
-0.001847596203445795
MATLAB(大脑连接工具箱) 使用 community_louvain.m:Louvain 社区检测算法
clear all
load('A.mat')
[M,Q]=community_louvain(A);
Q =
0.1466
PYTHON 版本的 community_louvain.m: https://github.com/aestrivex/bctpy/blob/f9526a693a9af57051762442d8490dcdf2ebf4e3/bct/algorithms/modularity.py#L71,
import bct
split, Q = bct.community_louvain(A)
Q
0.14659657544165258
我再次得到大约。 0.1466 与基于 Matlab 和 Python BCT 的结果相匹配,但与igraph 输出相距甚远。
【问题讨论】:
标签: python networkx igraph modularity