Skip to content

Commit e6f3590

Browse files
author
Katelyn Begany
committed
NF: added check_integrity method to GraphPartition, check no empty partitions
1 parent 5966f92 commit e6f3590

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

brainx/modularity.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,12 @@ def store_best(self):
662662
#Store references to the original graph and label dict
663663
self.bestindex = copy.deepcopy(self.index)
664664

665-
665+
def check_integrity(self, partition):
666+
""" Raises error if partition structure is invalid """
667+
668+
# Raise error if any partition is empty
669+
if [partition[key] == set([]) for key in partition.keys()]:
670+
raise ValueError("Partition index %s is empty" % (key))
666671

667672
#-----------------------------------------------------------------------------
668673
# Functions
@@ -1298,6 +1303,8 @@ def simulated_annealing(g, p0=None, temperature = 50, temp_scaling = 0.995, tmin
12981303

12991304
if np.abs(finalmodval - (-energy_best)) > 0.000001: #to account for float error
13001305
raise ValueError('mismatch in energy and modularity')
1306+
1307+
check_integrity(graph_part_final)
13011308

13021309
return graph_part_final,graph_part_final.modularity()
13031310

0 commit comments

Comments
 (0)