Esempio n. 1
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. 2
0
 def test_P3(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)
     for n in sorted(G):
         assert almost_equal(b[n], b_answer[n], places=4)
     b = nx.eigenvector_centrality(G)
     for n in sorted(G):
         assert almost_equal(b[n], b_answer[n], places=4)
Esempio n. 3
0
 def test_maxiter(self):
     with pytest.raises(nx.PowerIterationFailedConvergence):
         G = nx.path_graph(3)
         b = nx.eigenvector_centrality(G, max_iter=0)
Esempio n. 4
0
 def test_empty(self):
     with pytest.raises(nx.NetworkXException):
         e = nx.eigenvector_centrality(nx.Graph())
Esempio n. 5
0
 def test_multigraph(self):
     with pytest.raises(nx.NetworkXException):
         e = nx.eigenvector_centrality(nx.MultiGraph())
Esempio n. 6
0
 def test_eigenvector_centrality_unweighted(self):
     G = self.H
     p = nx.eigenvector_centrality(G)
     for (a, b) in zip(list(p.values()), self.G.evc):
         assert almost_equal(a, b, places=4)