Skip to content

Commit 8fc3293

Browse files
author
CindeeM
committed
NF: working find correct stopping rate for Newman Spectral partition
1 parent 7a5a48a commit 8fc3293

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

brainx/modularity.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(self, graph, index):
7474
self._check_index_contains_sets()
7575

7676
# We'll need the graph's adjacency matrix often, so store it once
77-
self.graph_adj_matrix = np.triu(nx.adj_matrix(graph))
77+
self.graph_adj_matrix = nx.adj_matrix(graph)
7878
#make sure adj_matrix is binary otherwise raise exception
7979
if not self.graph_adj_matrix.sum() == \
8080
self.graph_adj_matrix.astype(bool).sum():
@@ -1376,7 +1376,14 @@ def _divide_partition(p, max_div=np.inf):
13761376

13771377
# Compute the increase in modularity due to this partitioning.
13781378
# If it is less than zero, we should rather not have partitioned.
1379-
q = s[None, :].dot(B_).dot(s)
1379+
Bc_mask = np.ones_like(B_)
1380+
Bc_mask[s==1, :] = 0
1381+
Bc_mask[:, s==1] = 0
1382+
Bc = (B_ * Bc_mask).sum(axis=0)
1383+
Bc = B_ - np.diag(Bc)
1384+
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())
1386+
print p, q, q2
13801387
if q <= 0:
13811388
return [p]
13821389

0 commit comments

Comments
 (0)