summaryrefslogtreecommitdiff
path: root/networkx/linalg/tests
diff options
context:
space:
mode:
authorMridul Seth <seth.mridul@gmail.com>2023-02-14 08:10:38 +0100
committerGitHub <noreply@github.com>2023-02-13 23:10:38 -0800
commit44f0794f00a9fcba33a62f9d626ff882bee040ee (patch)
tree8ce789a8addf6ebe8544a76925d2d7c42c64e288 /networkx/linalg/tests
parentf798e8abd98fffe6209c101b9ae750d07cd5cb01 (diff)
downloadnetworkx-44f0794f00a9fcba33a62f9d626ff882bee040ee.tar.gz
spectral bisection for graphs using fiedler vector (#6404)
Add spectral_bisection function to bisect node sets based on the Fiedler vector Co-authored-by: Benjamin Edwards <bedwards@cs.unm.edu> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Diffstat (limited to 'networkx/linalg/tests')
-rw-r--r--networkx/linalg/tests/test_algebraic_connectivity.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/networkx/linalg/tests/test_algebraic_connectivity.py b/networkx/linalg/tests/test_algebraic_connectivity.py
index 7a86bd0a..16ee09c1 100644
--- a/networkx/linalg/tests/test_algebraic_connectivity.py
+++ b/networkx/linalg/tests/test_algebraic_connectivity.py
@@ -46,6 +46,21 @@ def test_fiedler_vector_tracemin_unknown():
)
+def test_spectral_bisection():
+ pytest.importorskip("scipy")
+ G = nx.barbell_graph(3, 0)
+ C = nx.spectral_bisection(G)
+ assert C == ({0, 1, 2}, {3, 4, 5})
+
+ mapping = dict(enumerate("badfec"))
+ G = nx.relabel_nodes(G, mapping)
+ C = nx.spectral_bisection(G)
+ assert C == (
+ {mapping[0], mapping[1], mapping[2]},
+ {mapping[3], mapping[4], mapping[5]},
+ )
+
+
def check_eigenvector(A, l, x):
nx = np.linalg.norm(x)
# Check zeroness.