comparison env/lib/python3.9/site-packages/networkx/linalg/tests/test_bethehessian.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import pytest
2
3 np = pytest.importorskip("numpy")
4 npt = pytest.importorskip("numpy.testing")
5 sp = pytest.importorskip("scipy")
6
7 import networkx as nx
8 from networkx.generators.degree_seq import havel_hakimi_graph
9
10
11 class TestBetheHessian:
12 @classmethod
13 def setup_class(cls):
14 deg = [3, 2, 2, 1, 0]
15 cls.G = havel_hakimi_graph(deg)
16 cls.P = nx.path_graph(3)
17
18 def test_bethe_hessian(self):
19 "Bethe Hessian matrix"
20 # fmt: off
21 H = np.array([[4, -2, 0],
22 [-2, 5, -2],
23 [0, -2, 4]])
24 # fmt: on
25 permutation = [2, 0, 1]
26 # Bethe Hessian gives expected form
27 npt.assert_equal(nx.bethe_hessian_matrix(self.P, r=2).todense(), H)
28 # nodelist is correctly implemented
29 npt.assert_equal(
30 nx.bethe_hessian_matrix(self.P, r=2, nodelist=permutation).todense(),
31 H[np.ix_(permutation, permutation)],
32 )
33 # Equal to Laplacian matrix when r=1
34 npt.assert_equal(
35 nx.bethe_hessian_matrix(self.G, r=1).todense(),
36 nx.laplacian_matrix(self.G).todense(),
37 )
38 # Correct default for the regularizer r
39 npt.assert_equal(
40 nx.bethe_hessian_matrix(self.G).todense(),
41 nx.bethe_hessian_matrix(self.G, r=1.25).todense(),
42 )