Python networkx.eccentricity() Examples

The following are 12 code examples of networkx.eccentricity(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module networkx , or try the search function .
Example #1
Source File: test_distance_measures.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 6 votes vote down vote up
def test_eccentricity(self):
        assert_equal(networkx.eccentricity(self.G,1),6)
        e=networkx.eccentricity(self.G)
        assert_equal(e[1],6)
        sp=networkx.shortest_path_length(self.G)
        e=networkx.eccentricity(self.G,sp=sp)
        assert_equal(e[1],6)
        e=networkx.eccentricity(self.G,v=1)
        assert_equal(e,6)
        e=networkx.eccentricity(self.G,v=[1,1])  #This behavior changed in version 1.8 (ticket #739)
        assert_equal(e[1],6)
        e=networkx.eccentricity(self.G,v=[1,2])
        assert_equal(e[1],6)
        # test against graph with one node
        G=networkx.path_graph(1)
        e=networkx.eccentricity(G)
        assert_equal(e[0],0)
        e=networkx.eccentricity(G,v=0)
        assert_equal(e,0)
        assert_raises(networkx.NetworkXError, networkx.eccentricity, G, 1)
        # test against empty graph
        G=networkx.empty_graph()
        e=networkx.eccentricity(G)
        assert_equal(e,{}) 
Example #2
Source File: test_distance_measures.py    From Carnets with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_eccentricity(self):
        assert_equal(networkx.eccentricity(self.G, 1), 6)
        e = networkx.eccentricity(self.G)
        assert_equal(e[1], 6)
        sp = dict(networkx.shortest_path_length(self.G))
        e = networkx.eccentricity(self.G, sp=sp)
        assert_equal(e[1], 6)
        e = networkx.eccentricity(self.G, v=1)
        assert_equal(e, 6)
        # This behavior changed in version 1.8 (ticket #739)
        e = networkx.eccentricity(self.G, v=[1, 1])
        assert_equal(e[1], 6)
        e = networkx.eccentricity(self.G, v=[1, 2])
        assert_equal(e[1], 6)
        # test against graph with one node
        G = networkx.path_graph(1)
        e = networkx.eccentricity(G)
        assert_equal(e[0], 0)
        e = networkx.eccentricity(G, v=0)
        assert_equal(e, 0)
        assert_raises(networkx.NetworkXError, networkx.eccentricity, G, 1)
        # test against empty graph
        G = networkx.empty_graph()
        e = networkx.eccentricity(G)
        assert_equal(e, {}) 
Example #3
Source File: test_distance_measures.py    From aws-kube-codesuite with Apache License 2.0 6 votes vote down vote up
def test_eccentricity(self):
        assert_equal(networkx.eccentricity(self.G, 1), 6)
        e = networkx.eccentricity(self.G)
        assert_equal(e[1], 6)
        sp = dict(networkx.shortest_path_length(self.G))
        e = networkx.eccentricity(self.G, sp=sp)
        assert_equal(e[1], 6)
        e = networkx.eccentricity(self.G, v=1)
        assert_equal(e, 6)
        # This behavior changed in version 1.8 (ticket #739)
        e = networkx.eccentricity(self.G, v=[1, 1])
        assert_equal(e[1], 6)
        e = networkx.eccentricity(self.G, v=[1, 2])
        assert_equal(e[1], 6)
        # test against graph with one node
        G = networkx.path_graph(1)
        e = networkx.eccentricity(G)
        assert_equal(e[0], 0)
        e = networkx.eccentricity(G, v=0)
        assert_equal(e, 0)
        assert_raises(networkx.NetworkXError, networkx.eccentricity, G, 1)
        # test against empty graph
        G = networkx.empty_graph()
        e = networkx.eccentricity(G)
        assert_equal(e, {}) 
Example #4
Source File: geoscattering.py    From karateclub with GNU General Public License v3.0 5 votes vote down vote up
def _create_node_feature_matrix(self, graph):
        """
        Calculating the node features.

        Arg types:
            * **graph** *(NetworkX graph)* - The graph of interest.

        Return types:
            * **X** *(NumPy array)* - The node features.
        """
        log_degree = np.array([math.log(graph.degree(node)+1) for node in range(graph.number_of_nodes())]).reshape(-1, 1)
        eccentricity = np.array([nx.eccentricity(graph, node) for node in range(graph.number_of_nodes())]).reshape(-1, 1)
        clustering_coefficient = np.array([nx.clustering(graph, node) for node in range(graph.number_of_nodes())]).reshape(-1, 1)
        X = np.concatenate([log_degree, eccentricity, clustering_coefficient], axis=1)
        return X 
Example #5
Source File: test_distance_measures.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 5 votes vote down vote up
def test_eccentricity_infinite(self):
        G=networkx.Graph([(1,2),(3,4)])
        e = networkx.eccentricity(G) 
Example #6
Source File: test_distance_measures.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 5 votes vote down vote up
def test_eccentricity_invalid(self):
        G=networkx.Graph([(1,2),(3,4)])
        e = networkx.eccentricity(G,sp=1) 
Example #7
Source File: test_distance_measures.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_eccentricity_infinite(self):
        G = networkx.Graph([(1, 2), (3, 4)])
        e = networkx.eccentricity(G) 
Example #8
Source File: test_distance_measures.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_eccentricity_undirected_not_connected(self):
        G = networkx.Graph([(1, 2), (3, 4)])
        e = networkx.eccentricity(G, sp=1) 
Example #9
Source File: test_distance_measures.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_eccentricity_directed_weakly_connected(self):
        DG = networkx.DiGraph([(1, 2), (1, 3)])
        networkx.eccentricity(DG) 
Example #10
Source File: test_distance_measures.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def test_eccentricity_infinite(self):
        G = networkx.Graph([(1, 2), (3, 4)])
        e = networkx.eccentricity(G) 
Example #11
Source File: test_distance_measures.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def test_eccentricity_undirected_not_connected(self):
        G = networkx.Graph([(1, 2), (3, 4)])
        e = networkx.eccentricity(G, sp=1) 
Example #12
Source File: test_distance_measures.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def test_eccentricity_directed_weakly_connected(self):
        DG = networkx.DiGraph([(1, 2), (1, 3)])
        networkx.eccentricity(DG)