@@ -1107,6 +1107,10 @@ def simulated_annealing(g,temperature = 50, temp_scaling = 0.995, tmin=1e-5,
1107
1107
debug_partition = GraphPartition (g , graph_partition .index )
1108
1108
npt .assert_almost_equal (debug_partition .modularity (),
1109
1109
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
+
1110
1114
1111
1115
#maybe store the best one here too?
1112
1116
#graph_partition.store_best()
@@ -1171,6 +1175,12 @@ def simulated_annealing(g,temperature = 50, temp_scaling = 0.995, tmin=1e-5,
1171
1175
graph_partition .index )
1172
1176
npt .assert_almost_equal (debug_partition .modularity (),
1173
1177
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
+
1174
1184
1175
1185
#else:
1176
1186
#graph_partition = GraphPartition(g,graph_partition.index)
@@ -1211,14 +1221,26 @@ def simulated_annealing(g,temperature = 50, temp_scaling = 0.995, tmin=1e-5,
1211
1221
'energy: %.2e' % energy , 'best: %.2e' % energy_best
1212
1222
temperature *= temp_scaling
1213
1223
1224
+
1225
+
1214
1226
#NEED TO APPLY THE BEST PARTITION JUST IN CASE...
1215
1227
#make a new graph object, apply the best partition
1216
1228
#graph_partition.index = graph_partition.bestindex
1217
1229
print graph_partition .modularity ()
1218
1230
graph_part_final = GraphPartition (g ,graph_partition .bestindex )
1219
1231
print graph_partition .modularity ()
1220
1232
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
+
1222
1244
if extra_info :
1223
1245
extra_dict = dict (energy = energy_array , temp = temp_array )
1224
1246
#return graph_partition, extra_dict
0 commit comments