/usr/lib/python3/dist-packages/networkx/algorithms/link_analysis/tests/test_hits.py is in python3-networkx 1.8.1-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #!/usr/bin/env python
from nose.tools import *
from nose import SkipTest
from nose.plugins.attrib import attr
import networkx
# Example from
# A. Langville and C. Meyer, "A survey of eigenvector methods of web
# information retrieval." http://citeseer.ist.psu.edu/713792.html
class TestHITS:
def setUp(self):
G=networkx.DiGraph()
edges=[(1,3),(1,5),\
(2,1),\
(3,5),\
(5,4),(5,3),\
(6,5)]
G.add_edges_from(edges,weight=1)
self.G=G
self.G.a=dict(zip(G,[0.000000, 0.000000, 0.366025,
0.133975, 0.500000, 0.000000]))
self.G.h=dict(zip(G,[ 0.366025, 0.000000, 0.211325,
0.000000, 0.211325, 0.211325]))
def test_hits(self):
G=self.G
h,a=networkx.hits(G,tol=1.e-08)
for n in G:
assert_almost_equal(h[n],G.h[n],places=4)
for n in G:
assert_almost_equal(a[n],G.a[n],places=4)
def test_hits_nstart(self):
G = self.G
nstart = dict([(i, 1./2) for i in G])
h, a = networkx.hits(G, nstart = nstart)
@attr('numpy')
def test_hits_numpy(self):
try:
import numpy as np
except ImportError:
raise SkipTest('NumPy not available.')
G=self.G
h,a=networkx.hits_numpy(G)
for n in G:
assert_almost_equal(h[n],G.h[n],places=4)
for n in G:
assert_almost_equal(a[n],G.a[n],places=4)
def test_hits_scipy(self):
try:
import scipy as sp
except ImportError:
raise SkipTest('SciPy not available.')
G=self.G
h,a=networkx.hits_scipy(G,tol=1.e-08)
for n in G:
assert_almost_equal(h[n],G.h[n],places=4)
for n in G:
assert_almost_equal(a[n],G.a[n],places=4)
@attr('numpy')
def test_empty(self):
try:
import numpy
except ImportError:
raise SkipTest('numpy not available.')
G=networkx.Graph()
assert_equal(networkx.hits(G),({},{}))
assert_equal(networkx.hits_numpy(G),({},{}))
assert_equal(networkx.authority_matrix(G).shape,(0,0))
assert_equal(networkx.hub_matrix(G).shape,(0,0))
def test_empty_scipy(self):
try:
import scipy
except ImportError:
raise SkipTest('scipy not available.')
G=networkx.Graph()
assert_equal(networkx.hits_scipy(G),({},{}))
|