當前位置: 首頁>>代碼示例>>Python>>正文


Python networkx.balanced_tree方法代碼示例

本文整理匯總了Python中networkx.balanced_tree方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.balanced_tree方法的具體用法?Python networkx.balanced_tree怎麽用?Python networkx.balanced_tree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在networkx的用法示例。


在下文中一共展示了networkx.balanced_tree方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: tree

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def tree(start, height, r=2, role_start=0):
    """Builds a balanced r-tree of height h
    INPUT:
    -------------
    start       :    starting index for the shape
    height      :    int height of the tree 
    r           :    int number of branches per node 
    role_start  :    starting index for the roles
    OUTPUT:
    -------------
    graph       :    a tree shape graph, with ids beginning at start
    roles       :    list of the roles of the nodes (indexed starting at role_start)
    """
    graph = nx.balanced_tree(r, height)
    roles = [0] * graph.number_of_nodes()
    return graph, roles 
開發者ID:RexYing,項目名稱:gnn-model-explainer,代碼行數:18,代碼來源:synthetic_structsim.py

示例2: test_graphs

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def test_graphs(self):

        H = nx.complete_graph(2)
        H.add_edge(2, 3)

        graphs = [nx.complete_graph(7),
                  dnx.chimera_graph(2, 1, 3),
                  nx.balanced_tree(5, 3),
                  nx.barbell_graph(8, 11),
                  nx.cycle_graph(5),
                  H]

        for G in graphs:
            tw, order = dnx.treewidth_branch_and_bound(G)
            self.assertEqual(dnx.elimination_order_width(G, order), tw)

            tw, order = dnx.min_width_heuristic(G)
            self.assertEqual(dnx.elimination_order_width(G, order), tw)

            tw, order = dnx.min_fill_heuristic(G)
            self.assertEqual(dnx.elimination_order_width(G, order), tw)

            tw, order = dnx.max_cardinality_heuristic(G)
            self.assertEqual(dnx.elimination_order_width(G, order), tw) 
開發者ID:dwavesystems,項目名稱:dwave_networkx,代碼行數:26,代碼來源:test_elimination_ordering.py

示例3: setUp

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def setUp(self):

        self.K = nx.krackhardt_kite_graph()
        self.P3 = nx.path_graph(3)
        self.P4 = nx.path_graph(4)
        self.K5 = nx.complete_graph(5)

        self.C4=nx.cycle_graph(4)
        self.T=nx.balanced_tree(r=2, h=2)
        self.Gb = nx.Graph()
        self.Gb.add_edges_from([(0,1), (0,2), (1,3), (2,3), 
                                (2,4), (4,5), (3,5)])


        F = nx.florentine_families_graph()
        self.F = F 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:18,代碼來源:test_closeness_centrality.py

示例4: setUp

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def setUp(self):
        self.K = nx.krackhardt_kite_graph()
        self.P3 = nx.path_graph(3)
        self.P4 = nx.path_graph(4)
        self.K5 = nx.complete_graph(5)

        self.C4 = nx.cycle_graph(4)
        self.T = nx.balanced_tree(r=2, h=2)
        self.Gb = nx.Graph()
        self.Gb.add_edges_from([(0, 1), (0, 2), (1, 3), (2, 3),
                                (2, 4), (4, 5), (3, 5)])

        F = nx.florentine_families_graph()
        self.F = F

        self.LM = nx.les_miserables_graph() 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:18,代碼來源:test_closeness_centrality.py

示例5: test_real_degenerate

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def test_real_degenerate(self):
        """Verify that the Takagi decomposition returns a matrix that is unitary and results in a
        correct decomposition when input a real but highly degenerate matrix. This test uses the
        adjacency matrix of a balanced tree graph."""
        g = nx.balanced_tree(2, 4)
        a = nx.to_numpy_array(g)
        rl, U = dec.takagi(a)
        assert np.allclose(U @ U.conj().T, np.eye(len(a)))
        assert np.allclose(U @ np.diag(rl) @ U.T, a) 
開發者ID:XanaduAI,項目名稱:strawberryfields,代碼行數:11,代碼來源:test_decompositions.py

示例6: make_complete_rary_tree

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def make_complete_rary_tree(self, h=2, r=2):
        self.add_edges_from(nx.balanced_tree(h=h, r=r,
                            create_using=nx.DiGraph()).edges)
        self.linkage_dist = {n: d for n, (d, _) in
                             self.maxdist_from_roots().items()} 
開發者ID:Hoosier-Clusters,項目名稱:clusim,代碼行數:7,代碼來源:dag.py

示例7: test_richclub2

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def test_richclub2():
    T = nx.balanced_tree(2,10)
    rc = nx.richclub.rich_club_coefficient(T,normalized=False)
    assert_equal(rc,{0:4092/(2047*2046.0),
                     1:(2044.0/(1023*1022)),
                     2:(2040.0/(1022*1021))})

#def test_richclub2_normalized():
#    T = nx.balanced_tree(2,10)
#    rcNorm = nx.richclub.rich_club_coefficient(T,Q=2)
#    assert_true(rcNorm[0] ==1.0 and rcNorm[1] < 0.9 and rcNorm[2] < 0.9) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:13,代碼來源:test_richclub.py

示例8: setUp

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def setUp(self):
        self.P3 = nx.path_graph(3)
        self.P4 = nx.path_graph(4)
        self.K5 = nx.complete_graph(5)

        self.C4 = nx.cycle_graph(4)
        self.C5 = nx.cycle_graph(5)


        self.T = nx.balanced_tree(r=2, h=2)

        self.Gb = nx.DiGraph()
        self.Gb.add_edges_from([(0, 1), (0, 2), (0, 4), (2, 1),
                                (2, 3), (4, 3)]) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:16,代碼來源:test_harmonic_centrality.py

示例9: test_balanced_tree

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def test_balanced_tree(self):
        """Edge betweenness centrality: balanced tree"""
        G=nx.balanced_tree(r=2,h=2)
        b=nx.edge_betweenness_centrality(G, weight=None, normalized=False)
        b_answer={(0, 1):12,(0, 2):12,
                  (1, 3):6,(1, 4):6,(2, 5):6,(2,6):6}
        for n in sorted(G.edges()):
            assert_almost_equal(b[n],b_answer[n]) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:10,代碼來源:test_betweenness_centrality.py

示例10: test_already_arborescence

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def test_already_arborescence(self):
        """Tests that a directed acyclic graph that is already an
        arborescence produces an isomorphic arborescence as output.

        """
        A = nx.balanced_tree(2, 2, create_using=nx.DiGraph())
        B = nx.dag_to_branching(A)
        assert_true(nx.is_isomorphic(A, B)) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:10,代碼來源:test_dag.py

示例11: test_already_branching

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def test_already_branching(self):
        """Tests that a directed acyclic graph that is already a
        branching produces an isomorphic branching as output.

        """
        T1 = nx.balanced_tree(2, 2, create_using=nx.DiGraph())
        T2 = nx.balanced_tree(2, 2, create_using=nx.DiGraph())
        G = nx.disjoint_union(T1, T2)
        B = nx.dag_to_branching(G)
        assert_true(nx.is_isomorphic(G, B)) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:12,代碼來源:test_dag.py

示例12: test_richclub2

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def test_richclub2():
    T = nx.balanced_tree(2, 10)
    rc = nx.richclub.rich_club_coefficient(T, normalized=False)
    assert_equal(rc, {0: 4092 / (2047 * 2046.0),
                      1: (2044.0 / (1023 * 1022)),
                      2: (2040.0 / (1022 * 1021))}) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:8,代碼來源:test_richclub.py

示例13: test_rich_club_exception2

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def test_rich_club_exception2():
    G = nx.MultiGraph()
    nx.rich_club_coefficient(G)


# def test_richclub2_normalized():
#    T = nx.balanced_tree(2,10)
#    rcNorm = nx.richclub.rich_club_coefficient(T,Q=2)
#    assert_true(rcNorm[0] ==1.0 and rcNorm[1] < 0.9 and rcNorm[2] < 0.9) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:11,代碼來源:test_richclub.py

示例14: test_tree_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def test_tree_graph(self):
        tg = nx.balanced_tree(3, 3)
        assert_false(minimum_cycle_basis(tg)) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:5,代碼來源:test_cycles.py

示例15: test_balanced_tree

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import balanced_tree [as 別名]
def test_balanced_tree(self):
        """Edge betweenness centrality: balanced tree"""
        G = nx.balanced_tree(r=2, h=2)
        b = nx.edge_betweenness_centrality(G, weight=None, normalized=False)
        b_answer = {(0, 1): 12, (0, 2): 12,
                    (1, 3): 6, (1, 4): 6, (2, 5): 6, (2, 6): 6}
        for n in sorted(G.edges()):
            assert_almost_equal(b[n], b_answer[n]) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:10,代碼來源:test_betweenness_centrality.py


注:本文中的networkx.balanced_tree方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。