about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/networkx/linalg/tests/test_bethehessian.py
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/networkx/linalg/tests/test_bethehessian.py
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are here HEAD master
Diffstat (limited to '.venv/lib/python3.12/site-packages/networkx/linalg/tests/test_bethehessian.py')
-rw-r--r--.venv/lib/python3.12/site-packages/networkx/linalg/tests/test_bethehessian.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/networkx/linalg/tests/test_bethehessian.py b/.venv/lib/python3.12/site-packages/networkx/linalg/tests/test_bethehessian.py
new file mode 100644
index 00000000..339fe1be
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/networkx/linalg/tests/test_bethehessian.py
@@ -0,0 +1,41 @@
+import pytest
+
+np = pytest.importorskip("numpy")
+pytest.importorskip("scipy")
+
+import networkx as nx
+from networkx.generators.degree_seq import havel_hakimi_graph
+
+
+class TestBetheHessian:
+    @classmethod
+    def setup_class(cls):
+        deg = [3, 2, 2, 1, 0]
+        cls.G = havel_hakimi_graph(deg)
+        cls.P = nx.path_graph(3)
+
+    def test_bethe_hessian(self):
+        "Bethe Hessian matrix"
+        # fmt: off
+        H = np.array([[4, -2, 0],
+                      [-2, 5, -2],
+                      [0, -2, 4]])
+        # fmt: on
+        permutation = [2, 0, 1]
+        # Bethe Hessian gives expected form
+        np.testing.assert_equal(nx.bethe_hessian_matrix(self.P, r=2).todense(), H)
+        # nodelist is correctly implemented
+        np.testing.assert_equal(
+            nx.bethe_hessian_matrix(self.P, r=2, nodelist=permutation).todense(),
+            H[np.ix_(permutation, permutation)],
+        )
+        # Equal to Laplacian matrix when r=1
+        np.testing.assert_equal(
+            nx.bethe_hessian_matrix(self.G, r=1).todense(),
+            nx.laplacian_matrix(self.G).todense(),
+        )
+        # Correct default for the regularizer r
+        np.testing.assert_equal(
+            nx.bethe_hessian_matrix(self.G).todense(),
+            nx.bethe_hessian_matrix(self.G, r=1.25).todense(),
+        )