comparison env/lib/python3.9/site-packages/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.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 import networkx as nx
4 from networkx.algorithms.bipartite import spectral_bipartivity as sb
5 from networkx.testing import almost_equal
6
7 # Examples from Figure 1
8 # E. Estrada and J. A. Rodríguez-Velázquez, "Spectral measures of
9 # bipartivity in complex networks", PhysRev E 72, 046105 (2005)
10
11
12 class TestSpectralBipartivity:
13 @classmethod
14 def setup_class(cls):
15 global scipy
16 scipy = pytest.importorskip("scipy")
17
18 def test_star_like(self):
19 # star-like
20
21 G = nx.star_graph(2)
22 G.add_edge(1, 2)
23 assert almost_equal(sb(G), 0.843, places=3)
24
25 G = nx.star_graph(3)
26 G.add_edge(1, 2)
27 assert almost_equal(sb(G), 0.871, places=3)
28
29 G = nx.star_graph(4)
30 G.add_edge(1, 2)
31 assert almost_equal(sb(G), 0.890, places=3)
32
33 def test_k23_like(self):
34 # K2,3-like
35 G = nx.complete_bipartite_graph(2, 3)
36 G.add_edge(0, 1)
37 assert almost_equal(sb(G), 0.769, places=3)
38
39 G = nx.complete_bipartite_graph(2, 3)
40 G.add_edge(2, 4)
41 assert almost_equal(sb(G), 0.829, places=3)
42
43 G = nx.complete_bipartite_graph(2, 3)
44 G.add_edge(2, 4)
45 G.add_edge(3, 4)
46 assert almost_equal(sb(G), 0.731, places=3)
47
48 G = nx.complete_bipartite_graph(2, 3)
49 G.add_edge(0, 1)
50 G.add_edge(2, 4)
51 assert almost_equal(sb(G), 0.692, places=3)
52
53 G = nx.complete_bipartite_graph(2, 3)
54 G.add_edge(2, 4)
55 G.add_edge(3, 4)
56 G.add_edge(0, 1)
57 assert almost_equal(sb(G), 0.645, places=3)
58
59 G = nx.complete_bipartite_graph(2, 3)
60 G.add_edge(2, 4)
61 G.add_edge(3, 4)
62 G.add_edge(2, 3)
63 assert almost_equal(sb(G), 0.645, places=3)
64
65 G = nx.complete_bipartite_graph(2, 3)
66 G.add_edge(2, 4)
67 G.add_edge(3, 4)
68 G.add_edge(2, 3)
69 G.add_edge(0, 1)
70 assert almost_equal(sb(G), 0.597, places=3)
71
72 def test_single_nodes(self):
73
74 # single nodes
75 G = nx.complete_bipartite_graph(2, 3)
76 G.add_edge(2, 4)
77 sbn = sb(G, nodes=[1, 2])
78 assert almost_equal(sbn[1], 0.85, places=2)
79 assert almost_equal(sbn[2], 0.77, places=2)
80
81 G = nx.complete_bipartite_graph(2, 3)
82 G.add_edge(0, 1)
83 sbn = sb(G, nodes=[1, 2])
84 assert almost_equal(sbn[1], 0.73, places=2)
85 assert almost_equal(sbn[2], 0.82, places=2)