Skip to content

Commit cb3a44b

Browse files
author
Emi Nomura
committed
Fixed the debug mode of modularity call
1 parent 1f19978 commit cb3a44b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

brainx/modularity.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def _edge_info(self, mod_e=None, mod_a=None, index=None):
114114
mod_a[m] = perc_btwn+perc_within #all of the A's
115115
#mod_e.append(perc_within)
116116
#mod_a.append(perc_btwn+perc_within)
117-
117+
if np.isnan(mod_e[m]) or np.isnan(mod_a[m]):
118+
1/0
118119

119120
return mod_e, mod_a
120121

@@ -129,6 +130,8 @@ def modularity_newman(self):
129130
Returns:
130131
mod = modularity
131132
"""
133+
if np.isnan((np.array(self.mod_e) - (np.array(self.mod_a)**2)).sum()):
134+
1/0
132135
return (np.array(self.mod_e) - (np.array(self.mod_a)**2)).sum()
133136

134137
modularity = modularity_newman
@@ -853,6 +856,7 @@ def plot_partition(g,part,title,fname='figure',nod_labels = None, pos = None,
853856
for v in val:
854857
if les_dam != 'none':
855858
plt.scatter(pos[v][0],pos[v][1],s=100*les_dam[v],c='orange',marker=(10,1,0))
859+
856860
nx.draw_networkx_nodes(g,pos,nodelist=list(val),node_color=col[niter],node_size=50)
857861
else:
858862
for v in val:
@@ -870,6 +874,7 @@ def plot_partition(g,part,title,fname='figure',nod_labels = None, pos = None,
870874
for v in val:
871875
if les_dam != 'none':
872876
plt.scatter(pos[v][0],pos[v][1],s=100*les_dam[v],c='orange',marker=(10,1,0))
877+
873878
nx.draw_networkx_nodes(g,pos,nodelist=list(val),node_color=col2[niter],node_size=50)
874879
else:
875880
for v in val:
@@ -918,8 +923,8 @@ def plot_partition(g,part,title,fname='figure',nod_labels = None, pos = None,
918923
for m,val in part.iteritems():
919924
for v in val:
920925
if les_dam[v] > 0:
921-
plt.scatter(pos[v][0],pos[v][1],s=500*les_dam[v]+100,c='orange',marker=(4,1,0))
922-
926+
plt.scatter(pos[v][0],pos[v][1],s=500*les_dam[v]+100,c='orange',marker=(10,1,0))
927+
923928
plt.title(title)
924929
#plt.savefig(fname)
925930
#plt.close()
@@ -1071,7 +1076,7 @@ def simulated_annealing(g,temperature = 50, temp_scaling = 0.995, tmin=1e-5,
10711076

10721077
energy = -graph_partition.modularity()
10731078
energy_array.append(energy)
1074-
1079+
10751080
while temperature > tmin:
10761081
# Initialize counters
10771082
bad_accept_mod = 0
@@ -1249,8 +1254,8 @@ def simulated_annealing(g,temperature = 50, temp_scaling = 0.995, tmin=1e-5,
12491254
npt.assert_almost_equal(debug_partition.modularity(),
12501255
graph_part_final.modularity(), 11)
12511256

1252-
for mod in graph_partition_final.index:
1253-
if len(graph_partition_final.index[mod]) < 1:
1257+
for mod in graph_part_final.index:
1258+
if len(graph_part_final.index[mod]) < 1:
12541259
raise ValueError('LAST CHECK: Empty module after module %s,SA' % (movetype))
12551260

12561261
if extra_info:

0 commit comments

Comments
 (0)