Python networkx.square_clustering() Examples

The following are 16 code examples of networkx.square_clustering(). 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: graph.py    From momepy with MIT License 5 votes vote down vote up
def clustering(graph, name="cluster"):
    """
    Calculates the squares clustering coefficient for nodes.

    Wrapper around ``networkx.square_clustering``.


    Parameters
    ----------
    graph : networkx.Graph
        Graph representing street network.
        Ideally generated from GeoDataFrame using :func:`momepy.gdf_to_nx`
    name : str, optional
        calculated attribute name

    Returns
    -------
    Graph
        networkx.Graph

    Examples
    --------
    >>> network_graph = mm.clustering(network_graph)
    """
    netx = graph.copy()

    vals = nx.square_clustering(netx)
    nx.set_node_attributes(netx, vals, name)

    return netx 
Example #2
Source File: test_cluster.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 5 votes vote down vote up
def test_clustering(self):
        G = nx.Graph()
        assert_equal(list(nx.square_clustering(G).values()),[])
        assert_equal(nx.square_clustering(G),{}) 
Example #3
Source File: test_cluster.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 5 votes vote down vote up
def test_path(self):
        G = nx.path_graph(10)
        assert_equal(list(nx.square_clustering(G).values()),
                     [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
        assert_equal(nx.square_clustering(G),
                     {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 
                      5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}) 
Example #4
Source File: test_cluster.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 5 votes vote down vote up
def test_cubical(self):
        G = nx.cubical_graph()
        assert_equal(list(nx.square_clustering(G).values()),
                     [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5])
        assert_equal(list(nx.square_clustering(G,[1,2]).values()),[0.5, 0.5])
        assert_equal(nx.square_clustering(G,[1])[1],0.5)
        assert_equal(nx.square_clustering(G,[1,2]),{1: 0.5, 2: 0.5}) 
Example #5
Source File: test_cluster.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 5 votes vote down vote up
def test_k5(self):
        G = nx.complete_graph(5)
        assert_equal(list(nx.square_clustering(G).values()),[1, 1, 1, 1, 1]) 
Example #6
Source File: test_cluster.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 5 votes vote down vote up
def test_bipartite_k5(self):
        G = nx.complete_bipartite_graph(5,5)
        assert_equal(list(nx.square_clustering(G).values()),
                        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) 
Example #7
Source File: test_cluster.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_clustering(self):
        G = nx.Graph()
        assert_equal(list(nx.square_clustering(G).values()), [])
        assert_equal(nx.square_clustering(G), {}) 
Example #8
Source File: test_cluster.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_path(self):
        G = nx.path_graph(10)
        assert_equal(list(nx.square_clustering(G).values()),
                     [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
        assert_equal(nx.square_clustering(G),
                     {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0,
                      5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}) 
Example #9
Source File: test_cluster.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_cubical(self):
        G = nx.cubical_graph()
        assert_equal(list(nx.square_clustering(G).values()),
                     [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5])
        assert_equal(list(nx.square_clustering(G, [1, 2]).values()), [0.5, 0.5])
        assert_equal(nx.square_clustering(G, [1])[1], 0.5)
        assert_equal(nx.square_clustering(G, [1, 2]), {1: 0.5, 2: 0.5}) 
Example #10
Source File: test_cluster.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_k5(self):
        G = nx.complete_graph(5)
        assert_equal(list(nx.square_clustering(G).values()), [1, 1, 1, 1, 1]) 
Example #11
Source File: test_cluster.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_bipartite_k5(self):
        G = nx.complete_bipartite_graph(5, 5)
        assert_equal(list(nx.square_clustering(G).values()),
                     [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) 
Example #12
Source File: test_cluster.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def test_clustering(self):
        G = nx.Graph()
        assert_equal(list(nx.square_clustering(G).values()), [])
        assert_equal(nx.square_clustering(G), {}) 
Example #13
Source File: test_cluster.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def test_path(self):
        G = nx.path_graph(10)
        assert_equal(list(nx.square_clustering(G).values()),
                     [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
        assert_equal(nx.square_clustering(G),
                     {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0,
                      5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}) 
Example #14
Source File: test_cluster.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def test_cubical(self):
        G = nx.cubical_graph()
        assert_equal(list(nx.square_clustering(G).values()),
                     [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5])
        assert_equal(list(nx.square_clustering(G, [1, 2]).values()), [0.5, 0.5])
        assert_equal(nx.square_clustering(G, [1])[1], 0.5)
        assert_equal(nx.square_clustering(G, [1, 2]), {1: 0.5, 2: 0.5}) 
Example #15
Source File: test_cluster.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def test_k5(self):
        G = nx.complete_graph(5)
        assert_equal(list(nx.square_clustering(G).values()), [1, 1, 1, 1, 1]) 
Example #16
Source File: test_cluster.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def test_bipartite_k5(self):
        G = nx.complete_bipartite_graph(5, 5)
        assert_equal(list(nx.square_clustering(G).values()),
                     [1, 1, 1, 1, 1, 1, 1, 1, 1, 1])