Skip to content

Commit a85b1f6

Browse files
author
Caterina Gratton
committed
Added another check for empty modules.
1 parent ccdab2f commit a85b1f6

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

brainx/modularity.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,10 @@ def simulated_annealing(g,temperature = 50, temp_scaling = 0.995, tmin=1e-5,
11071107
debug_partition = GraphPartition(g, graph_partition.index)
11081108
npt.assert_almost_equal(debug_partition.modularity(),
11091109
graph_partition.modularity(), 11)
1110+
for mod in graph_partition.index:
1111+
if len(graph_partition.index[mod]) < 1:
1112+
raise ValueError('Empty module after module %s,SA' % (movetype))
1113+
11101114

11111115
#maybe store the best one here too?
11121116
#graph_partition.store_best()
@@ -1171,6 +1175,12 @@ def simulated_annealing(g,temperature = 50, temp_scaling = 0.995, tmin=1e-5,
11711175
graph_partition.index)
11721176
npt.assert_almost_equal(debug_partition.modularity(),
11731177
graph_partition.modularity(), 11)
1178+
1179+
1180+
for mod in graph_partition.index:
1181+
if len(graph_partition.index[mod]) < 1:
1182+
raise ValueError('Empty module after ndoe move,SA')
1183+
11741184

11751185
#else:
11761186
#graph_partition = GraphPartition(g,graph_partition.index)
@@ -1211,14 +1221,26 @@ def simulated_annealing(g,temperature = 50, temp_scaling = 0.995, tmin=1e-5,
12111221
'energy: %.2e' %energy, 'best: %.2e' %energy_best
12121222
temperature *= temp_scaling
12131223

1224+
1225+
12141226
#NEED TO APPLY THE BEST PARTITION JUST IN CASE...
12151227
#make a new graph object, apply the best partition
12161228
#graph_partition.index = graph_partition.bestindex
12171229
print graph_partition.modularity()
12181230
graph_part_final = GraphPartition(g,graph_partition.bestindex)
12191231
print graph_partition.modularity()
12201232
print graph_part_final.modularity()
1221-
1233+
1234+
1235+
if debug:
1236+
debug_partition = GraphPartition(g, graph_partition_final.index)
1237+
npt.assert_almost_equal(debug_partition.modularity(),
1238+
graph_partition_final.modularity(), 11)
1239+
1240+
for mod in graph_partition_final.index:
1241+
if len(graph_partition_final.index[mod]) < 1:
1242+
raise ValueError('LAST CHECK: Empty module after module %s,SA' % (movetype))
1243+
12221244
if extra_info:
12231245
extra_dict = dict(energy = energy_array, temp = temp_array)
12241246
#return graph_partition, extra_dict

0 commit comments

Comments
 (0)