Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bct/algorithms/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def agreement_weighted(ci, wts):

Parameters
----------
ci : MxN np.ndarray
ci : NxM np.ndarray
set of M (possibly degenerate) partitions of N nodes
wts : Mx1 np.ndarray
relative weight of each partition
Expand All @@ -84,12 +84,12 @@ def agreement_weighted(ci, wts):
weighted agreement matrix
'''
ci = np.array(ci)
m, n = ci.shape
n, m = ci.shape
wts = np.array(wts) / np.sum(wts)

D = np.zeros((n, n))
for i in range(m):
d = dummyvar(ci[i, :].reshape(1, n))
d = dummyvar(ci[:, i].reshape(n, 1))
D += np.dot(d, d.T) * wts[i]
return D

Expand Down
22 changes: 20 additions & 2 deletions test/clustering_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,26 @@ def test_transitivity_bd():


def test_agreement_weighted():
# this function is very hard to use or interpret results from
pass
# Test whether agreement gives the same results as
# agreement_weighted when the weights are all the same
ci = np.array([[1, 1, 2, 2, 3],
[1, 2, 2, 3, 3],
[1, 1, 2, 3, 3]]).T
wts = np.ones(ci.shape[1])

D_agreement = bct.agreement(ci)
D_weighted = bct.agreement_weighted(ci, wts)

# Undo the normalization and fill the diagonal with zeros
# in D_weighted to get the same result as D_agreement
D_weighted = D_weighted * ci.shape[1]
np.fill_diagonal(D_weighted, 0)

print('agreement matrix:')
print(D_agreement)
print('weighted agreement matrix:')
print(D_weighted)
assert (D_agreement == D_weighted).all()

def test_agreement():
# Case 1: nodes > partitions
Expand Down
Loading