Skip to content

Commit 91f17f7

Browse files
author
CindeeM
committed
RF: fix GraphPartition to calc find_unconnected_nodes no find_solitary based on suggestion by @kbegany
1 parent cc487e7 commit 91f17f7

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

brainx/modularity.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ def modularity_newman(self):
177177
modularity = modularity_newman
178178

179179

180-
def find_solitary(self):
180+
def find_unconnected_nodes(self):
181181
""" checks for nodes in graph with no edges """
182182
graph = nx.from_numpy_matrix(self.graph_adj_matrix)
183-
solitary=[ n for n,d in graph.degree_iter() if d==0 ]
184-
return solitary
183+
unconnected = [ n for n,d in graph.degree_iter() if d==0 ]
184+
return unconnected
185185

186186
def compute_module_merge(self, m1, m2):
187187
"""Merges two modules in a given partition.
@@ -1382,9 +1382,9 @@ def _divide_partition(p, max_div=np.inf):
13821382
Bc = (B_ * Bc_mask).sum(axis=0)
13831383
Bc = B_ - Bc
13841384
q = s[None, :].dot(Bc).dot(s) / (4.0 * graph_A_.number_of_edges())
1385-
q2 = s[None, :].dot(B_).dot(s) / (4.0 * graph_A_.number_of_edges())
1385+
q2 = s[None, :].dot(B_).dot(s) #/ (4.0 * graph_A_.number_of_edges())
13861386
print 'orig delta q', q2, 'new delta q', q
1387-
if q <= 0:
1387+
if q2 <= 0:
13881388
return [p]
13891389

13901390
# Make the partitioning, and subdivide each

brainx/tests/test_modularity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ def test_graphpartition():
6262
graph = nx.from_numpy_matrix(jnk, nx.Graph(weighted=False))
6363
npt.assert_raises(ValueError, mod.GraphPartition, graph, index)
6464

65-
def test_find_solitary():
65+
def test_find_unconnected_nodes():
6666
jnk = np.zeros((10,10))
6767
jnk[:6,:6] = 1
6868
jnk = np.triu(jnk,1)
6969
graph = nx.from_numpy_matrix(jnk>0, nx.Graph(weighted=False))
7070
index = {0:set([0,1,2,3,4,5,6,7,8,9])}
7171
graph_partition = mod.GraphPartition(graph, index)
72-
solitary_nodes = graph_partition.find_solitary()
72+
solitary_nodes = graph_partition.find_unconnected_nodes()
7373
npt.assert_equal(solitary_nodes, [6,7,8,9])
7474

7575
def test_index_as_node_names():

0 commit comments

Comments
 (0)