当前位置: 首页>>代码示例>>Python>>正文


Python networkx.transitivity方法代码示例

本文整理汇总了Python中networkx.transitivity方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.transitivity方法的具体用法?Python networkx.transitivity怎么用?Python networkx.transitivity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx的用法示例。


在下文中一共展示了networkx.transitivity方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_k5

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import transitivity [as 别名]
def test_k5(self):
        G = nx.complete_graph(5)
        assert_equal(nx.transitivity(G),1.0)
        G.remove_edge(1,2)
        assert_equal(nx.transitivity(G),0.875)

    # def test_clustering_transitivity(self):
    #     # check that weighted average of clustering is transitivity
    #     G = nx.complete_graph(5)
    #     G.remove_edge(1,2)
    #     t1=nx.transitivity(G)
    #     (cluster_d2,weights)=nx.clustering(G,weights=True)
    #     trans=[]
    #     for v in G.nodes():
    #         trans.append(cluster_d2[v]*weights[v])
    #     t2=sum(trans)
    #     assert_almost_equal(abs(t1-t2),0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:19,代码来源:test_cluster.py

示例2: test_k5

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import transitivity [as 别名]
def test_k5(self):
        G = nx.complete_graph(5)
        assert_equal(nx.transitivity(G), 1.0)
        G.remove_edge(1, 2)
        assert_equal(nx.transitivity(G), 0.875)

    # def test_clustering_transitivity(self):
    #     # check that weighted average of clustering is transitivity
    #     G = nx.complete_graph(5)
    #     G.remove_edge(1,2)
    #     t1=nx.transitivity(G)
    #     (cluster_d2,weights)=nx.clustering(G,weights=True)
    #     trans=[]
    #     for v in G.nodes():
    #         trans.append(cluster_d2[v]*weights[v])
    #     t2=sum(trans)
    #     assert_almost_equal(abs(t1-t2),0) 
开发者ID:holzschu,项目名称:Carnets,代码行数:19,代码来源:test_cluster.py

示例3: _set_omega

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import transitivity [as 别名]
def _set_omega(self):
        """
        Calculating the graph level clustering coefficient.
        """
        self._omega = nx.transitivity(self._graph) 
开发者ID:benedekrozemberczki,项目名称:karateclub,代码行数:7,代码来源:scd.py

示例4: transitivity

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import transitivity [as 别名]
def transitivity(G):
    r"""Compute graph transitivity, the fraction of all possible triangles 
    present in G.

    Possible triangles are identified by the number of "triads" 
    (two edges with a shared vertex).

    The transitivity is

    .. math::

        T = 3\frac{\#triangles}{\#triads}.

    Parameters
    ----------
    G : graph

    Returns
    -------
    out : float
       Transitivity

    Examples
    --------
    >>> G = nx.complete_graph(5)
    >>> print(nx.transitivity(G))
    1.0
    """
    triangles=0 # 6 times number of triangles
    contri=0  # 2 times number of connected triples
    for v,d,t in _triangles_and_degree_iter(G):
        contri += d*(d-1)
        triangles += t
    if triangles==0: # we had no triangles or possible triangles
        return 0.0
    else:
        return triangles/float(contri) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:39,代码来源:cluster.py

示例5: test_transitivity

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import transitivity [as 别名]
def test_transitivity(self):
        G = nx.Graph()
        assert_equal(nx.transitivity(G),0.0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:5,代码来源:test_cluster.py

示例6: test_path

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import transitivity [as 别名]
def test_path(self):
        G = nx.path_graph(10)
        assert_equal(nx.transitivity(G),0.0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:5,代码来源:test_cluster.py

示例7: test_cubical

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import transitivity [as 别名]
def test_cubical(self):
        G = nx.cubical_graph()
        assert_equal(nx.transitivity(G),0.0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:5,代码来源:test_cluster.py

示例8: transitivity

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import transitivity [as 别名]
def transitivity(G):
    r"""Compute graph transitivity, the fraction of all possible triangles
    present in G.

    Possible triangles are identified by the number of "triads"
    (two edges with a shared vertex).

    The transitivity is

    .. math::

        T = 3\frac{\#triangles}{\#triads}.

    Parameters
    ----------
    G : graph

    Returns
    -------
    out : float
       Transitivity

    Examples
    --------
    >>> G = nx.complete_graph(5)
    >>> print(nx.transitivity(G))
    1.0
    """
    triangles = sum(t for v, d, t, _ in _triangles_and_degree_iter(G))
    contri = sum(d * (d - 1) for v, d, t, _ in _triangles_and_degree_iter(G))
    return 0 if triangles == 0 else triangles / contri 
开发者ID:holzschu,项目名称:Carnets,代码行数:33,代码来源:cluster.py

示例9: test_transitivity

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import transitivity [as 别名]
def test_transitivity(self):
        G = nx.Graph()
        assert_equal(nx.transitivity(G), 0.0) 
开发者ID:holzschu,项目名称:Carnets,代码行数:5,代码来源:test_cluster.py

示例10: test_path

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import transitivity [as 别名]
def test_path(self):
        G = nx.path_graph(10)
        assert_equal(nx.transitivity(G), 0.0) 
开发者ID:holzschu,项目名称:Carnets,代码行数:5,代码来源:test_cluster.py

示例11: test_cubical

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import transitivity [as 别名]
def test_cubical(self):
        G = nx.cubical_graph()
        assert_equal(nx.transitivity(G), 0.0) 
开发者ID:holzschu,项目名称:Carnets,代码行数:5,代码来源:test_cluster.py


注:本文中的networkx.transitivity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。