Esempio n. 1
0
 def test_eigenvector_v_katz_random(self):
     G = nx.gnp_random_graph(10, 0.5, seed=1234)
     l = float(max(eigvals(nx.adjacency_matrix(G).todense())))
     e = nx.eigenvector_centrality_numpy(G)
     k = nx.katz_centrality_numpy(G, 1.0 / l)
     for n in G:
         assert almost_equal(e[n], k[n])
Esempio n. 2
0
 def test_P3_unweighted(self):
     """Eigenvector centrality: P3"""
     G = nx.path_graph(3)
     b_answer = {0: 0.5, 1: 0.7071, 2: 0.5}
     b = nx.eigenvector_centrality_numpy(G, weight=None)
     for n in sorted(G):
         assert almost_equal(b[n], b_answer[n], places=4)
Esempio n. 3
0
 def test_K5_unweighted(self):
     """Katz centrality: K5"""
     G = nx.complete_graph(5)
     alpha = 0.1
     b = nx.katz_centrality(G, alpha, weight=None)
     v = math.sqrt(1 / 5.0)
     b_answer = dict.fromkeys(G, v)
     for n in sorted(G):
         assert almost_equal(b[n], b_answer[n])
     nstart = dict([(n, 1) for n in G])
     b = nx.eigenvector_centrality_numpy(G, weight=None)
     for n in sorted(G):
         assert almost_equal(b[n], b_answer[n], places=3)
Esempio n. 4
0
    def test_K5(self):
        """Eigenvector centrality: K5"""
        G = nx.complete_graph(5)
        b = nx.eigenvector_centrality(G)
        v = math.sqrt(1 / 5.0)
        b_answer = dict.fromkeys(G, v)
        for n in sorted(G):
            assert almost_equal(b[n], b_answer[n])
        nstart = dict([(n, 1) for n in G])
        b = nx.eigenvector_centrality(G, nstart=nstart)
        for n in sorted(G):
            assert almost_equal(b[n], b_answer[n])

        b = nx.eigenvector_centrality_numpy(G)
        for n in sorted(G):
            assert almost_equal(b[n], b_answer[n], places=3)
Esempio n. 5
0
 def test_empty_numpy(self):
     with pytest.raises(nx.NetworkXException):
         e = nx.eigenvector_centrality_numpy(nx.Graph())
Esempio n. 6
0
 def test_eigenvector_centrality_unweighted_numpy(self):
     G = self.H
     p = nx.eigenvector_centrality_numpy(G)
     for (a, b) in zip(list(p.values()), self.G.evc):
         assert almost_equal(a, b)