comparison env/lib/python3.9/site-packages/networkx/algorithms/tests/test_communicability.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 from collections import defaultdict
2
3 import pytest
4
5 numpy = pytest.importorskip("numpy")
6 scipy = pytest.importorskip("scipy")
7
8 import networkx as nx
9 from networkx.testing import almost_equal
10 from networkx.algorithms.communicability_alg import communicability, communicability_exp
11
12
13 class TestCommunicability:
14 def test_communicability(self):
15 answer = {
16 0: {0: 1.5430806348152435, 1: 1.1752011936438012},
17 1: {0: 1.1752011936438012, 1: 1.5430806348152435},
18 }
19 # answer={(0, 0): 1.5430806348152435,
20 # (0, 1): 1.1752011936438012,
21 # (1, 0): 1.1752011936438012,
22 # (1, 1): 1.5430806348152435}
23
24 result = communicability(nx.path_graph(2))
25 for k1, val in result.items():
26 for k2 in val:
27 assert almost_equal(answer[k1][k2], result[k1][k2], places=7)
28
29 def test_communicability2(self):
30
31 answer_orig = {
32 ("1", "1"): 1.6445956054135658,
33 ("1", "Albert"): 0.7430186221096251,
34 ("1", "Aric"): 0.7430186221096251,
35 ("1", "Dan"): 1.6208126320442937,
36 ("1", "Franck"): 0.42639707170035257,
37 ("Albert", "1"): 0.7430186221096251,
38 ("Albert", "Albert"): 2.4368257358712189,
39 ("Albert", "Aric"): 1.4368257358712191,
40 ("Albert", "Dan"): 2.0472097037446453,
41 ("Albert", "Franck"): 1.8340111678944691,
42 ("Aric", "1"): 0.7430186221096251,
43 ("Aric", "Albert"): 1.4368257358712191,
44 ("Aric", "Aric"): 2.4368257358712193,
45 ("Aric", "Dan"): 2.0472097037446457,
46 ("Aric", "Franck"): 1.8340111678944691,
47 ("Dan", "1"): 1.6208126320442937,
48 ("Dan", "Albert"): 2.0472097037446453,
49 ("Dan", "Aric"): 2.0472097037446457,
50 ("Dan", "Dan"): 3.1306328496328168,
51 ("Dan", "Franck"): 1.4860372442192515,
52 ("Franck", "1"): 0.42639707170035257,
53 ("Franck", "Albert"): 1.8340111678944691,
54 ("Franck", "Aric"): 1.8340111678944691,
55 ("Franck", "Dan"): 1.4860372442192515,
56 ("Franck", "Franck"): 2.3876142275231915,
57 }
58
59 answer = defaultdict(dict)
60 for (k1, k2), v in answer_orig.items():
61 answer[k1][k2] = v
62
63 G1 = nx.Graph(
64 [
65 ("Franck", "Aric"),
66 ("Aric", "Dan"),
67 ("Dan", "Albert"),
68 ("Albert", "Franck"),
69 ("Dan", "1"),
70 ("Franck", "Albert"),
71 ]
72 )
73
74 result = communicability(G1)
75 for k1, val in result.items():
76 for k2 in val:
77 assert almost_equal(answer[k1][k2], result[k1][k2], places=7)
78
79 result = communicability_exp(G1)
80 for k1, val in result.items():
81 for k2 in val:
82 assert almost_equal(answer[k1][k2], result[k1][k2], places=7)