Modularity (Q) based on the Louvain split, unexpected values

Indeed that is the case. I expected igraph to understand this since I defined a weighted adjacency matrix but I need to explicitly pass the weights argument in modularity().

import numpy as np
import scipy.io
from igraph import *
import bct

A = scipy.io.loadmat("A.mat")['A']
np.fill_diagonal(A,0.0)

# igraph
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, weights=graph.es['weight'])
print(Q)

#bctpy
com, q = bct.community_louvain(A)
print(q)

0.14133150351832535

0.14133150351832674

1 Like