Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pylouvain.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ def compute_modularity(self, partition):
q = 0
m2 = self.m * 2
for i in range(len(partition)):
q += self.s_in[i] / m2 - (self.s_tot[i] / m2) ** 2
try:
q += self.s_in[i] / m2 - (self.s_tot[i] / m2) ** 2
except:
q += 0
return q

'''
Expand All @@ -150,7 +153,10 @@ def compute_modularity(self, partition):
_k_i_in: the sum of the weights of the links from _node to nodes in _c
'''
def compute_modularity_gain(self, node, c, k_i_in):
return 2 * k_i_in - self.s_tot[c] * self.k_i[node] / self.m
try:
return 2 * k_i_in - self.s_tot[c] * self.k_i[node] / self.m
except:
return 0

'''
Performs the first phase of the method.
Expand Down