From 690000fafc98b7b28cda3ff64dca73c2726cf810 Mon Sep 17 00:00:00 2001 From: Harry Dempsey <101311642+H-Dempsey@users.noreply.github.com> Date: Tue, 25 Nov 2025 13:52:46 +1100 Subject: [PATCH 1/3] Fix issues with agreement_weighted --- bct/algorithms/clustering.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bct/algorithms/clustering.py b/bct/algorithms/clustering.py index 9b06b03..968802b 100644 --- a/bct/algorithms/clustering.py +++ b/bct/algorithms/clustering.py @@ -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 @@ -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 From fb85f56f7ad8089e752f7c5a85941f1197d7c101 Mon Sep 17 00:00:00 2001 From: Harry Dempsey <101311642+H-Dempsey@users.noreply.github.com> Date: Tue, 25 Nov 2025 14:08:33 +1100 Subject: [PATCH 2/3] Add a test for agreement_weighted This tests whether agreement_weighted gives the same results as agreement when the weights are all the same. --- test/clustering_test.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test/clustering_test.py b/test/clustering_test.py index 26dda21..6e3d7d4 100644 --- a/test/clustering_test.py +++ b/test/clustering_test.py @@ -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 = agreement(ci) + D_weighted = 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 From 84950902a5903b4ec2d1e8ff6033697406f88e81 Mon Sep 17 00:00:00 2001 From: Harry Dempsey <101311642+H-Dempsey@users.noreply.github.com> Date: Tue, 25 Nov 2025 14:24:50 +1100 Subject: [PATCH 3/3] Update clustering_test.py --- test/clustering_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/clustering_test.py b/test/clustering_test.py index 6e3d7d4..36a241c 100644 --- a/test/clustering_test.py +++ b/test/clustering_test.py @@ -112,8 +112,8 @@ def test_agreement_weighted(): [1, 1, 2, 3, 3]]).T wts = np.ones(ci.shape[1]) - D_agreement = agreement(ci) - D_weighted = agreement_weighted(ci, wts) + 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