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


Python networkx.average_clustering方法代码示例

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


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

示例1: avg_transitivity

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def avg_transitivity(graph, communities, **kwargs):
    """Average transitivity.

    The average transitivity of a community is defined the as the average clustering coefficient of its nodes w.r.t. their connection within the community itself.

    :param graph: a networkx/igraph object
    :param communities: NodeClustering object
    :param summary: boolean. If **True** it is returned an aggregated score for the partition is returned, otherwise individual-community ones. Default **True**.
    :return: If **summary==True** a FitnessResult object, otherwise a list of floats.

    Example:

    >>> from cdlib.algorithms import louvain
    >>> from cdlib import evaluation
    >>> g = nx.karate_club_graph()
    >>> communities = louvain(g)
    >>> scd = evaluation.avg_transitivity(g,communities)
    """

    return __quality_indexes(graph, communities,
                             lambda graph, coms: nx.average_clustering(nx.subgraph(graph, coms)),
                             **kwargs) 
开发者ID:GiulioRossetti,项目名称:cdlib,代码行数:24,代码来源:fitness.py

示例2: plot_clustering_coefficient

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def plot_clustering_coefficient(_g, _plot_img, interval=30):
    """Plot the clustering coefficient transition
    :param _g: Transaction graph
    :param _plot_img: Output image file
    :param interval: Simulation step interval for plotting
    (it takes too much time to compute clustering coefficient)
    :return:
    """
    date_list = get_date_list(_g)

    gg = nx.Graph()
    edges = defaultdict(list)
    for k, v in nx.get_edge_attributes(_g, "date").items():
        e = (k[0], k[1])
        edges[v].append(e)

    sample_dates = list()
    values = list()
    for i, t in enumerate(date_list):
        gg.add_edges_from(edges[t])
        if i % interval == 0:
            v = nx.average_clustering(gg) if gg.number_of_nodes() else 0.0
            sample_dates.append(t)
            values.append(v)
            print("Clustering coefficient at %s: %f" % (str(t), v))

    plt.figure(figsize=(16, 12))
    plt.clf()
    plt.plot(sample_dates, values, 'bo-')
    plt.title("Clustering Coefficient Transition")
    plt.xlabel("date")
    plt.ylabel("Clustering Coefficient")
    plt.savefig(_plot_img) 
开发者ID:IBM,项目名称:AMLSim,代码行数:35,代码来源:plot_distributions.py

示例3: get_clustering_coeff

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def get_clustering_coeff(edge_list):
    G = nx.from_edgelist(edgelist=edge_list)
    clust_coeff = nx.average_clustering(G)
    # print(nx.number_of_nodes(G), ' : ',clust_coeff)
    return clust_coeff 
开发者ID:palash1992,项目名称:GEM-Benchmark,代码行数:7,代码来源:plot_stats.py

示例4: test_k5

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def test_k5(self):
        G = nx.complete_graph(5)
        assert_equal(list(nx.clustering(G,weight='weight').values()),[1, 1, 1, 1, 1])
        assert_equal(nx.average_clustering(G,weight='weight'),1)
        G.remove_edge(1,2)
        assert_equal(list(nx.clustering(G,weight='weight').values()),
                     [5./6., 1.0, 1.0, 5./6., 5./6.])
        assert_equal(nx.clustering(G,[1,4],weight='weight'),{1: 1.0, 4: 0.83333333333333337}) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:10,代码来源:test_cluster.py

示例5: test_average_clustering

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def test_average_clustering():
    G=nx.cycle_graph(3)
    G.add_edge(2,3)
    assert_equal(nx.average_clustering(G),(1+1+1/3.0)/4.0)
    assert_equal(nx.average_clustering(G,count_zeros=True),(1+1+1/3.0)/4.0)
    assert_equal(nx.average_clustering(G,count_zeros=False),(1+1+1/3.0)/3.0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:8,代码来源:test_cluster.py

示例6: test_petersen

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def test_petersen():
    # Actual coefficient is 0
    G = nx.petersen_graph()
    assert_equal(average_clustering(G, trials=int(len(G)/2)),
                 nx.average_clustering(G)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:7,代码来源:test_approx_clust_coeff.py

示例7: test_dodecahedral

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def test_dodecahedral():
    # Actual coefficient is 0
    G = nx.dodecahedral_graph()
    assert_equal(average_clustering(G, trials=int(len(G)/2)),
                 nx.average_clustering(G)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:7,代码来源:test_approx_clust_coeff.py

示例8: test_empty

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def test_empty():
    G = nx.empty_graph(5)
    assert_equal(average_clustering(G, trials=int(len(G)/2)), 0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:5,代码来源:test_approx_clust_coeff.py

示例9: test_complete

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def test_complete():
    G = nx.complete_graph(5)
    assert_equal(average_clustering(G, trials=int(len(G)/2)), 1)
    G = nx.complete_graph(7)
    assert_equal(average_clustering(G, trials=int(len(G)/2)), 1) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:7,代码来源:test_approx_clust_coeff.py

示例10: test_random_reference

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def test_random_reference():
    G = nx.connected_watts_strogatz_graph(50, 6, 0.1, seed=rng)
    Gr = random_reference(G, niter=1, seed=rng)
    C = nx.average_clustering(G)
    Cr = nx.average_clustering(Gr)
    assert_true(C > Cr)

    assert_raises(nx.NetworkXError, random_reference, nx.Graph())
    assert_raises(nx.NetworkXNotImplemented, random_reference, nx.DiGraph())

    H = nx.Graph(((0, 1), (2, 3)))
    Hl = random_reference(H, niter=1, seed=rng) 
开发者ID:holzschu,项目名称:Carnets,代码行数:14,代码来源:test_smallworld.py

示例11: test_k5

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def test_k5(self):
        G = nx.complete_graph(5, create_using=nx.DiGraph())
        assert_equal(list(nx.clustering(G).values()), [1, 1, 1, 1, 1])
        assert_equal(nx.average_clustering(G), 1)
        G.remove_edge(1, 2)
        assert_equal(list(nx.clustering(G).values()),
                     [11. / 12., 1.0, 1.0, 11. / 12., 11. / 12.])
        assert_equal(nx.clustering(G, [1, 4]), {1: 1.0, 4: 11. /12.})
        G.remove_edge(2, 1)
        assert_equal(list(nx.clustering(G).values()),
                     [5. / 6., 1.0, 1.0, 5. / 6., 5. / 6.])
        assert_equal(nx.clustering(G, [1, 4]), {1: 1.0, 4: 0.83333333333333337}) 
开发者ID:holzschu,项目名称:Carnets,代码行数:14,代码来源:test_cluster.py

示例12: test_average_clustering

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def test_average_clustering():
    G = nx.cycle_graph(3)
    G.add_edge(2, 3)
    assert_equal(nx.average_clustering(G), (1 + 1 + 1 / 3.0) / 4.0)
    assert_equal(nx.average_clustering(G, count_zeros=True), (1 + 1 + 1 / 3.0) / 4.0)
    assert_equal(nx.average_clustering(G, count_zeros=False), (1 + 1 + 1 / 3.0) / 3.0) 
开发者ID:holzschu,项目名称:Carnets,代码行数:8,代码来源:test_cluster.py

示例13: test_petersen

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def test_petersen():
    # Actual coefficient is 0
    G = nx.petersen_graph()
    assert_equal(average_clustering(G, trials=int(len(G) / 2)),
                 nx.average_clustering(G)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:7,代码来源:test_approx_clust_coeff.py

示例14: test_petersen_seed

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def test_petersen_seed():
    # Actual coefficient is 0
    G = nx.petersen_graph()
    assert_equal(average_clustering(G, trials=int(len(G) / 2), seed=1),
                 nx.average_clustering(G)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:7,代码来源:test_approx_clust_coeff.py

示例15: test_tetrahedral

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import average_clustering [as 别名]
def test_tetrahedral():
    # Actual coefficient is 1
    G = nx.tetrahedral_graph()
    assert_equal(average_clustering(G, trials=int(len(G) / 2)),
                 nx.average_clustering(G)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:7,代码来源:test_approx_clust_coeff.py


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