|
29 | 29 | # Our own modules
|
30 | 30 | import util
|
31 | 31 |
|
| 32 | +#----------------------------------------------------------------------------- |
| 33 | +# Functions |
| 34 | +#----------------------------------------------------------------------------- |
| 35 | +def empty_module(msg='Empty module'): |
| 36 | + """Raise an exception if an empty module is found""" |
| 37 | + |
| 38 | + raise ValueError(msg) |
| 39 | + |
| 40 | + |
32 | 41 | #-----------------------------------------------------------------------------
|
33 | 42 | # Class declarations
|
34 | 43 | #-----------------------------------------------------------------------------
|
@@ -348,9 +357,9 @@ def apply_module_split(self, m, n1, n2, split_modules, e_new, a_new):
|
348 | 357 |
|
349 | 358 | # For now, rather than renumbering, just check if this ever happens
|
350 | 359 | if len(self.index[m1])<1:
|
351 |
| - raise ValueError('Empty module after module split, old mod') |
| 360 | + empty_module('Empty module after module split, old mod') |
352 | 361 | if len(self.index[m2])<1:
|
353 |
| - raise ValueError('Empty module after module split, new mod') |
| 362 | + empty_module('Empty module after module split, new mod') |
354 | 363 |
|
355 | 364 | def node_update(self, n, m1, m2):
|
356 | 365 | """Moves a single node within or between modules
|
@@ -452,7 +461,7 @@ def apply_node_update(self, n, m1, m2, node_moved_mods, e_new, a_new):
|
452 | 461 |
|
453 | 462 | # This checks whether there is an empty module. If so, renames the keys.
|
454 | 463 | if len(self.index[m1])<1:
|
455 |
| - raise ValueError('Empty module after node move') |
| 464 | + empty_module('Empty module after node move') |
456 | 465 | #self.index.pop(m1)
|
457 | 466 | #rename_keys(self.index,m1)
|
458 | 467 | #if m1 < m2:
|
@@ -1005,9 +1014,9 @@ def mutual_information(d1, d2):
|
1005 | 1014 | # the entire partitions, we look for this problem at this stage, and bail
|
1006 | 1015 | # if there was an empty module.
|
1007 | 1016 | ## if (nsum_row==0).any():
|
1008 |
| -## raise ValueError("Empty module in second partition.") |
| 1017 | +## empty_module("Empty module in second partition.") |
1009 | 1018 | ## if (nsum_col==0).any():
|
1010 |
| -## raise ValueError("Empty module in first partition.") |
| 1019 | +## empty_module("Empty module in first partition.") |
1011 | 1020 |
|
1012 | 1021 | # nn is the total number of nodes
|
1013 | 1022 | nn = nsum_row.sum()
|
@@ -1136,7 +1145,7 @@ def simulated_annealing(g, p0=None, temperature = 50, temp_scaling = 0.995, tmin
|
1136 | 1145 | graph_partition.modularity(), 11)
|
1137 | 1146 | for mod in graph_partition.index:
|
1138 | 1147 | if len(graph_partition.index[mod]) < 1:
|
1139 |
| - raise ValueError('Empty module after module %s,SA' % (movetype)) |
| 1148 | + empty_module('Empty module after module %s,SA' % (movetype)) |
1140 | 1149 |
|
1141 | 1150 |
|
1142 | 1151 | #maybe store the best one here too?
|
@@ -1206,7 +1215,7 @@ def simulated_annealing(g, p0=None, temperature = 50, temp_scaling = 0.995, tmin
|
1206 | 1215 |
|
1207 | 1216 | for mod in graph_partition.index:
|
1208 | 1217 | if len(graph_partition.index[mod]) < 1:
|
1209 |
| - raise ValueError('Empty module after ndoe move,SA') |
| 1218 | + empty_module('Empty module after ndoe move,SA') |
1210 | 1219 |
|
1211 | 1220 |
|
1212 | 1221 | #else:
|
@@ -1264,7 +1273,7 @@ def simulated_annealing(g, p0=None, temperature = 50, temp_scaling = 0.995, tmin
|
1264 | 1273 |
|
1265 | 1274 | for mod in graph_part_final.index:
|
1266 | 1275 | if len(graph_part_final.index[mod]) < 1:
|
1267 |
| - raise ValueError('LAST CHECK: Empty module after module %s,SA' % (movetype)) |
| 1276 | + empty_module('LAST CHECK: Empty module after module %s,SA' % (movetype)) |
1268 | 1277 |
|
1269 | 1278 | if extra_info:
|
1270 | 1279 | extra_dict = dict(energy = energy_array, temp = temp_array)
|
|
0 commit comments