當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。