Skip to content

Commit 44d4d1d

Browse files
author
CindeeM
committed
BF: fix modularity test passing index as improper type (list), and removed some cruft
1 parent 80d411c commit 44d4d1d

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

brainx/modularity.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,18 @@ def _edge_info(self, mod_e=None, mod_a=None, index=None):
143143
if mod_a is None: mod_a = [0] * num_mod
144144
if index is None: index = self.index
145145

146-
norm_factor = 1.0/(2.0*self.num_edges)
146+
norm_factor = 1.0 / (2.0 * self.num_edges)
147147
mat = self.graph_adj_matrix
148-
set_nodes = self._node_set
149-
for m,modnodes in index.iteritems():
150-
#set_modnodes=set(modnodes)
151-
#btwnnodes = list(set_nodes - modnodes)
152-
btwnnodes = list(set_nodes - set(index[m]))
148+
node_set = self._node_set
149+
for m, modnodes in index.iteritems():
150+
btwnnodes = list(node_set - modnodes)
153151
modnodes = list(modnodes)
154-
#why isnt' self.index a set already? graph_partition.index[m]
155-
#looks like a set when we read it in ipython
156152
mat_within = mat[modnodes,:][:,modnodes]
157153
mat_between = mat[modnodes,:][:,btwnnodes]
158154
perc_within = mat_within.sum() * norm_factor
159155
perc_btwn = mat_between.sum() * norm_factor
160156
mod_e[m] = perc_within #all of the E's
161157
mod_a[m] = perc_btwn+perc_within #all of the A's
162-
#mod_e.append(perc_within)
163-
#mod_a.append(perc_btwn+perc_within)
164158
if np.isnan(mod_e[m]) or np.isnan(mod_a[m]):
165159
1/0
166160

brainx/tests/test_modularity.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,9 @@ def test_mutual_information():
425425
#split modules and check that mutual information comes out
426426
#correclty/lower
427427
graph_partition3 = mod.GraphPartition(g,ppart)
428-
n1 = list(graph_partition3.index[0])[::2]
429-
n2 = list(graph_partition3.index[0])[1::2]
428+
n1 = set(list(graph_partition3.index[0])[::2])
429+
n2 = set(list(graph_partition3.index[0])[1::2])
430+
430431
split_modules,e_new,a_new,d,t,m,n1,n2 = graph_partition3.compute_module_split(0,n1,n2)
431432
graph_partition3.apply_module_split(m,n1,n2,split_modules,e_new,a_new)
432433
mi3 = mod.mutual_information(ppart,graph_partition3.index)

0 commit comments

Comments
 (0)