@@ -1228,14 +1228,12 @@ def simulated_annealing(g,temperature = 50, temp_scaling = 0.995, tmin=1e-5,
1228
1228
#graph_partition.index = graph_partition.bestindex
1229
1229
print graph_partition .modularity ()
1230
1230
graph_part_final = GraphPartition (g ,graph_partition .bestindex )
1231
- print graph_partition .modularity ()
1232
- print graph_part_final .modularity ()
1233
1231
1234
1232
1235
1233
if debug :
1236
- debug_partition = GraphPartition (g , graph_partition_final .index )
1234
+ debug_partition = GraphPartition (g , graph_part_final .index )
1237
1235
npt .assert_almost_equal (debug_partition .modularity (),
1238
- graph_partition_final .modularity (), 11 )
1236
+ graph_part_final .modularity (), 11 )
1239
1237
1240
1238
for mod in graph_partition_final .index :
1241
1239
if len (graph_partition_final .index [mod ]) < 1 :
@@ -1247,5 +1245,15 @@ def simulated_annealing(g,temperature = 50, temp_scaling = 0.995, tmin=1e-5,
1247
1245
return graph_part_final , extra_dict
1248
1246
else :
1249
1247
#return graph_partition
1250
- print graph_part_final .modularity ()
1251
- return graph_part_final
1248
+ #print graph_part_final.modularity()
1249
+
1250
+ #check that the energy matches the computed modularity value of the partition
1251
+ finalmodval = graph_part_final .modularity ()
1252
+ print finalmodval
1253
+ print - energy_best
1254
+ print np .abs (finalmodval - (- energy_best ))
1255
+
1256
+ if np .abs (finalmodval - (- energy_best )) > 0.000001 : #to account for float error
1257
+ raise ValueError ('mismatch in energy and modularity' )
1258
+
1259
+ return graph_part_final ,graph_part_final .modularity ()
0 commit comments