Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/algorithms/centrality/tests/test_subgraph.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 numpy = pytest.importorskip("numpy") | |
4 scipy = pytest.importorskip("scipy") | |
5 | |
6 import networkx as nx | |
7 from networkx.algorithms.centrality.subgraph_alg import ( | |
8 estrada_index, | |
9 communicability_betweenness_centrality, | |
10 subgraph_centrality, | |
11 subgraph_centrality_exp, | |
12 ) | |
13 from networkx.testing import almost_equal | |
14 | |
15 | |
16 class TestSubgraph: | |
17 def test_subgraph_centrality(self): | |
18 answer = {0: 1.5430806348152433, 1: 1.5430806348152433} | |
19 result = subgraph_centrality(nx.path_graph(2)) | |
20 for k, v in result.items(): | |
21 assert almost_equal(answer[k], result[k], places=7) | |
22 | |
23 answer1 = { | |
24 "1": 1.6445956054135658, | |
25 "Albert": 2.4368257358712189, | |
26 "Aric": 2.4368257358712193, | |
27 "Dan": 3.1306328496328168, | |
28 "Franck": 2.3876142275231915, | |
29 } | |
30 G1 = nx.Graph( | |
31 [ | |
32 ("Franck", "Aric"), | |
33 ("Aric", "Dan"), | |
34 ("Dan", "Albert"), | |
35 ("Albert", "Franck"), | |
36 ("Dan", "1"), | |
37 ("Franck", "Albert"), | |
38 ] | |
39 ) | |
40 result1 = subgraph_centrality(G1) | |
41 for k, v in result1.items(): | |
42 assert almost_equal(answer1[k], result1[k], places=7) | |
43 result1 = subgraph_centrality_exp(G1) | |
44 for k, v in result1.items(): | |
45 assert almost_equal(answer1[k], result1[k], places=7) | |
46 | |
47 def test_subgraph_centrality_big_graph(self): | |
48 g199 = nx.complete_graph(199) | |
49 g200 = nx.complete_graph(200) | |
50 | |
51 comm199 = nx.subgraph_centrality(g199) | |
52 comm199_exp = nx.subgraph_centrality_exp(g199) | |
53 | |
54 comm200 = nx.subgraph_centrality(g200) | |
55 comm200_exp = nx.subgraph_centrality_exp(g200) | |
56 | |
57 def test_communicability_betweenness_centrality(self): | |
58 answer = { | |
59 0: 0.07017447951484615, | |
60 1: 0.71565598701107991, | |
61 2: 0.71565598701107991, | |
62 3: 0.07017447951484615, | |
63 } | |
64 result = communicability_betweenness_centrality(nx.path_graph(4)) | |
65 for k, v in result.items(): | |
66 assert almost_equal(answer[k], result[k], places=7) | |
67 | |
68 answer1 = { | |
69 "1": 0.060039074193949521, | |
70 "Albert": 0.315470761661372, | |
71 "Aric": 0.31547076166137211, | |
72 "Dan": 0.68297778678316201, | |
73 "Franck": 0.21977926617449497, | |
74 } | |
75 G1 = nx.Graph( | |
76 [ | |
77 ("Franck", "Aric"), | |
78 ("Aric", "Dan"), | |
79 ("Dan", "Albert"), | |
80 ("Albert", "Franck"), | |
81 ("Dan", "1"), | |
82 ("Franck", "Albert"), | |
83 ] | |
84 ) | |
85 result1 = communicability_betweenness_centrality(G1) | |
86 for k, v in result1.items(): | |
87 assert almost_equal(answer1[k], result1[k], places=7) | |
88 | |
89 def test_estrada_index(self): | |
90 answer = 1041.2470334195475 | |
91 result = estrada_index(nx.karate_club_graph()) | |
92 assert almost_equal(answer, result, places=7) |