Skip to content

Commit

Permalink
fix small modularity_und modularity_dir bug. these functions still di…
Browse files Browse the repository at this point in the history
…ffer considerably from MATLAB due to intractable linear algebra implementation differences
  • Loading branch information
aestrivex committed Feb 24, 2016
1 parent d7e9868 commit e1da26b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions bct/algorithms/modularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,11 @@ def recur(module):
q_iter = qmax - 4 * mod_asgn_iter * \
(np.dot(modmat, mod_asgn_iter))
qmax = np.max(q_iter * it)
imax, = np.where(q_iter == qmax)
if len(imax) > 0:
imax = imax[0]
imax = np.argmax(q_iter * it)
#imax, = np.where(q_iter == qmax)
#if len(imax) > 0:
# imax = imax[0]
# print(imax)
# does switching increase modularity?
mod_asgn_iter[imax] *= -1
it[imax] = np.ma.masked
Expand Down Expand Up @@ -1514,9 +1516,10 @@ def recur(module):
q_iter = qmax - 4 * mod_asgn_iter * \
(np.dot(modmat, mod_asgn_iter))
qmax = np.max(q_iter * it)
imax, = np.where(q_iter == qmax)
if len(imax) > 1:
imax = imax[0]
imax = np.argmax(q_iter * it)
#imax, = np.where(q_iter == qmax)
#if len(imax) > 1:
# imax = imax[0]
# does switching increase modularity?
mod_asgn_iter[imax] *= -1
it[imax] = np.ma.masked
Expand Down
3 changes: 2 additions & 1 deletion test/modularity_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ def test_modularity_louvain_dir_low_modularity():
def test_modularity_dir():
x = load_directed_sample()
_, q = bct.modularity_dir(x)
assert np.allclose(q, .31446049)
print q, .32742787
assert np.allclose(q, .32742787)


def test_modularity_louvain_dir():
Expand Down

0 comments on commit e1da26b

Please sign in to comment.