Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/algorithms/link_analysis/tests/test_hits.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 | |
4 import networkx | |
5 from networkx.testing import almost_equal | |
6 | |
7 # Example from | |
8 # A. Langville and C. Meyer, "A survey of eigenvector methods of web | |
9 # information retrieval." http://citeseer.ist.psu.edu/713792.html | |
10 | |
11 | |
12 class TestHITS: | |
13 @classmethod | |
14 def setup_class(cls): | |
15 | |
16 G = networkx.DiGraph() | |
17 | |
18 edges = [(1, 3), (1, 5), (2, 1), (3, 5), (5, 4), (5, 3), (6, 5)] | |
19 | |
20 G.add_edges_from(edges, weight=1) | |
21 cls.G = G | |
22 cls.G.a = dict( | |
23 zip(sorted(G), [0.000000, 0.000000, 0.366025, 0.133975, 0.500000, 0.000000]) | |
24 ) | |
25 cls.G.h = dict( | |
26 zip(sorted(G), [0.366025, 0.000000, 0.211325, 0.000000, 0.211325, 0.211325]) | |
27 ) | |
28 | |
29 def test_hits(self): | |
30 G = self.G | |
31 h, a = networkx.hits(G, tol=1.0e-08) | |
32 for n in G: | |
33 assert almost_equal(h[n], G.h[n], places=4) | |
34 for n in G: | |
35 assert almost_equal(a[n], G.a[n], places=4) | |
36 | |
37 def test_hits_nstart(self): | |
38 G = self.G | |
39 nstart = {i: 1.0 / 2 for i in G} | |
40 h, a = networkx.hits(G, nstart=nstart) | |
41 | |
42 def test_hits_numpy(self): | |
43 numpy = pytest.importorskip("numpy") | |
44 G = self.G | |
45 h, a = networkx.hits_numpy(G) | |
46 for n in G: | |
47 assert almost_equal(h[n], G.h[n], places=4) | |
48 for n in G: | |
49 assert almost_equal(a[n], G.a[n], places=4) | |
50 | |
51 def test_hits_scipy(self): | |
52 sp = pytest.importorskip("scipy") | |
53 G = self.G | |
54 h, a = networkx.hits_scipy(G, tol=1.0e-08) | |
55 for n in G: | |
56 assert almost_equal(h[n], G.h[n], places=4) | |
57 for n in G: | |
58 assert almost_equal(a[n], G.a[n], places=4) | |
59 | |
60 def test_empty(self): | |
61 numpy = pytest.importorskip("numpy") | |
62 G = networkx.Graph() | |
63 assert networkx.hits(G) == ({}, {}) | |
64 assert networkx.hits_numpy(G) == ({}, {}) | |
65 assert networkx.authority_matrix(G).shape == (0, 0) | |
66 assert networkx.hub_matrix(G).shape == (0, 0) | |
67 | |
68 def test_empty_scipy(self): | |
69 scipy = pytest.importorskip("scipy") | |
70 G = networkx.Graph() | |
71 assert networkx.hits_scipy(G) == ({}, {}) | |
72 | |
73 def test_hits_not_convergent(self): | |
74 with pytest.raises(networkx.PowerIterationFailedConvergence): | |
75 G = self.G | |
76 networkx.hits(G, max_iter=0) |