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


Python networkx.barabasi_albert_graph方法代碼示例

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


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

示例1: test_eva

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

        l1 = ['one', 'two', 'three', 'four']
        l2 = ["A", "B", "C"]
        g = nx.barabasi_albert_graph(100, 5)
        labels = dict()

        for node in g.nodes():
            labels[node] = {"l1": random.choice(l1), "l2": random.choice(l2)}

        coms = algorithms.eva(g, labels, alpha=0.5)

        self.assertEqual(type(coms.communities), list)
        if len(coms.communities) > 0:
            self.assertEqual(type(coms.communities[0]), list)
            self.assertEqual(type(coms.communities[0][0]), int) 
開發者ID:GiulioRossetti,項目名稱:cdlib,代碼行數:18,代碼來源:test_attributeclustering.py

示例2: generate_scalefree_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import barabasi_albert_graph [as 別名]
def generate_scalefree_graph(variables_count, m_edge, allow_subgraph):
    if not allow_subgraph:
        graph = nx.barabasi_albert_graph(variables_count, m_edge)
        is_connected = nx.is_connected(graph)
        while not is_connected:
            graph = nx.barabasi_albert_graph(variables_count, m_edge)
            is_connected = nx.is_connected(graph)
    else:
        graph = nx.barabasi_albert_graph(variables_count, m_edge)

    # In the obtained graph, low rank nodes will have a much higher edge count
    # than high rank nodes. We shuffle the nodes names to avoid this effect:
    new_nodes = list(range(variables_count))
    random.shuffle(new_nodes)
    node_mapping = {n: nn for n, nn in zip(graph.nodes, new_nodes)}

    new_graph = nx.Graph((node_mapping[e1], node_mapping[e2]) for e1, e2 in graph.edges)
    return new_graph 
開發者ID:Orange-OpenSource,項目名稱:pyDcop,代碼行數:20,代碼來源:graphcoloring.py

示例3: ba

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import barabasi_albert_graph [as 別名]
def ba(start, width, role_start=0, m=5):
    """Builds a BA preferential attachment graph, with index of nodes starting at start
    and role_ids at role_start
    INPUT:
    -------------
    start       :    starting index for the shape
    width       :    int size of the graph
    role_start  :    starting index for the roles
    OUTPUT:
    -------------
    graph       :    a house shape graph, with ids beginning at start
    roles       :    list of the roles of the nodes (indexed starting at
                     role_start)
    """
    graph = nx.barabasi_albert_graph(width, m)
    graph.add_nodes_from(range(start, start + width))
    nids = sorted(graph)
    mapping = {nid: start + i for i, nid in enumerate(nids)}
    graph = nx.relabel_nodes(graph, mapping)
    roles = [role_start for i in range(width)]
    return graph, roles 
開發者ID:RexYing,項目名稱:gnn-model-explainer,代碼行數:23,代碼來源:synthetic_structsim.py

示例4: test_quantum_jsd

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import barabasi_albert_graph [as 別名]
def test_quantum_jsd():
    """Run the above tests again using the collision entropy instead of the
    Von Neumann entropy to ensure that all the logic of the JSD implementation
    is tested.
    """

    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", message="JSD is only a metric for 0 ≤ q < 2.")
        JSD = distance.QuantumJSD()
        G = nx.karate_club_graph()
        dist = JSD.dist(G, G, beta=0.1, q=2)
        assert np.isclose(dist, 0.0)

        G1 = nx.fast_gnp_random_graph(100, 0.3)
        G2 = nx.barabasi_albert_graph(100, 5)
        dist = JSD.dist(G1, G2, beta=0.1, q=2)
        assert dist > 0.0

        G1 = nx.barabasi_albert_graph(100, 4)
        G2 = nx.fast_gnp_random_graph(100, 0.3)
        dist1 = JSD.dist(G1, G2, beta=0.1, q=2)
        dist2 = JSD.dist(G2, G1, beta=0.1, q=2)
        assert np.isclose(dist1, dist2) 
開發者ID:netsiphd,項目名稱:netrd,代碼行數:25,代碼來源:test_distance.py

示例5: test_purity

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

        l1 = ['one', 'two', 'three', 'four']
        l2 = ["A", "B", "C"]
        g_attr = nx.barabasi_albert_graph(100, 5)
        labels = dict()

        for node in g_attr.nodes():
            labels[node] = {"l1": random.choice(l1), "l2": random.choice(l2)}

        coms = eva(g_attr, labels, alpha=0.8)

        pur = evaluation.purity(coms)

        self.assertGreaterEqual(pur.score, 0)
        self.assertLessEqual(pur.score, 1) 
開發者ID:GiulioRossetti,項目名稱:cdlib,代碼行數:18,代碼來源:test_fitness_functions.py

示例6: test_ilouvain

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

        l1 = [0.1, 0.4, 0.5]
        l2 = [34, 3, 112]
        g = nx.barabasi_albert_graph(100, 5)
        labels = dict()

        for node in g.nodes():
            labels[node] = {"l1": random.choice(l1), "l2": random.choice(l2)}

        id = dict()
        for n in g.nodes():
            id[n] = n

        coms = algorithms.ilouvain(g, labels, id)

        self.assertEqual(type(coms.communities), list) 
開發者ID:GiulioRossetti,項目名稱:cdlib,代碼行數:19,代碼來源:test_attributeclustering.py

示例7: powerlaw_cluster_generator

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import barabasi_albert_graph [as 別名]
def powerlaw_cluster_generator(_n, _edge_factor):
    edges = nx.barabasi_albert_graph(_n, _edge_factor, seed=0).edges()  # Undirected edges

    # Swap the direction of half edges to diffuse degree
    di_edges = [(edges[i][0], edges[i][1]) if i % 2 == 0 else (edges[i][1], edges[i][0]) for i in range(len(edges))]
    _g = nx.DiGraph()
    _g.add_edges_from(di_edges)  # Create a directed graph
    return _g 
開發者ID:IBM,項目名稱:AMLSim,代碼行數:10,代碼來源:generate_scalefree.py

示例8: test_perturbed

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import barabasi_albert_graph [as 別名]
def test_perturbed():
    
    graphs = []
    for i in range(100,101):
        for j in range(4,5):
            for k in range(500):
                graphs.append(nx.barabasi_albert_graph(i,j))
    g_perturbed = perturb(graphs, 0.9)
    print([g.number_of_edges() for g in graphs])
    print([g.number_of_edges() for g in g_perturbed]) 
開發者ID:JiaxuanYou,項目名稱:graph-generation,代碼行數:12,代碼來源:utils.py

示例9: gen_ba

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import barabasi_albert_graph [as 別名]
def gen_ba(n_range, m_range, num_graphs, feature_generator=None):
    graphs = []
    for i in np.random.choice(n_range, num_graphs):
        for j in np.random.choice(m_range, 1):
            graphs.append(nx.barabasi_albert_graph(i,j))

    if feature_generator is None:
        feature_generator = ConstFeatureGen(0)
    for G in graphs:
        feature_generator.gen_node_features(G)
    return graphs 
開發者ID:RexYing,項目名稱:diffpool,代碼行數:13,代碼來源:data.py

示例10: test_different_graphs

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import barabasi_albert_graph [as 別名]
def test_different_graphs():
    """ The distance between two different graphs must be nonzero."""
    ## NOTE: This test is not totally rigorous. For example, two different
    ## networks may have the same eigenvalues, thus a method that compares
    ## their eigenvalues would result in distance 0. However, this is very
    ## unlikely in the constructed case, so we rely on it for now.
    G1 = nx.fast_gnp_random_graph(100, 0.3)
    G2 = nx.barabasi_albert_graph(100, 5)

    for obj in distance.__dict__.values():
        if isinstance(obj, type) and BaseDistance in obj.__bases__:
            dist = obj().dist(G1, G2)
            assert dist > 0.0 
開發者ID:netsiphd,項目名稱:netrd,代碼行數:15,代碼來源:test_distance.py

示例11: test_symmetry

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import barabasi_albert_graph [as 別名]
def test_symmetry():
    """The distance between two graphs must be symmetric."""
    G1 = nx.barabasi_albert_graph(100, 4)
    G2 = nx.fast_gnp_random_graph(100, 0.3)

    for label, obj in distance.__dict__.items():
        if isinstance(obj, type) and BaseDistance in obj.__bases__:
            dist1 = obj().dist(G1, G2)
            dist2 = obj().dist(G2, G1)
            assert np.isclose(dist1, dist2) 
開發者ID:netsiphd,項目名稱:netrd,代碼行數:12,代碼來源:test_distance.py

示例12: purity

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import barabasi_albert_graph [as 別名]
def purity(communities):
    """Purity is the product of the frequencies of the most frequent labels carried by the nodes within the communities

        :param communities: AttrNodeClustering object
        :return: FitnessResult object

        Example:

        >>> from cdlib.algorithms import eva
        >>> from cdlib import evaluation
        >>> import random
        >>> l1 = ['A', 'B', 'C', 'D']
        >>> l2 = ["E", "F", "G"]
        >>> g = nx.barabasi_albert_graph(100, 5)
        >>> labels=dict()
        >>> for node in g.nodes():
        >>>    labels[node]={"l1":random.choice(l1), "l2":random.choice(l2)}
        >>> communities = eva(g_attr, labels, alpha=0.5)
        >>> pur = evaluation.purity(communities)

        :References:

        1. Citraro, Salvatore, and Giulio Rossetti. "Eva: Attribute-Aware Network Segmentation." International Conference on Complex Networks and Their Applications. Springer, Cham, 2019.
        """

    pur = Eva.purity(communities.coms_labels)
    return FitnessResult(score=pur) 
開發者ID:GiulioRossetti,項目名稱:cdlib,代碼行數:29,代碼來源:fitness.py

示例13: test_valid_degree_sequence2

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import barabasi_albert_graph [as 別名]
def test_valid_degree_sequence2():
    n = 100
    for i in range(10):
        G = nx.barabasi_albert_graph(n,1)
        deg = list(G.degree().values())
        assert_true( nx.is_valid_degree_sequence(deg, method='eg') )
        assert_true( nx.is_valid_degree_sequence(deg, method='hh') ) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:9,代碼來源:test_graphical.py

示例14: test_valid_degree_sequence2

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import barabasi_albert_graph [as 別名]
def test_valid_degree_sequence2():
    n = 100
    for i in range(10):
        G = nx.barabasi_albert_graph(n, 1)
        deg = (d for n, d in G.degree())
        assert_true(nx.is_graphical(deg, method='eg'))
        assert_true(nx.is_graphical(deg, method='hh')) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:9,代碼來源:test_graphical.py

示例15: generate_powerlaw_var_constraints

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import barabasi_albert_graph [as 別名]
def generate_powerlaw_var_constraints(
    num_var: int, domain_size: int, constraint_range: int
) -> Tuple[Dict[str, Variable], Dict[str, Constraint], Domain]:
    """
    Generate variables and constraints for a power-law based constraints
    graph.

    All constraints are binary and the graph is generated using the Barabasi
    Albert method.

    Parameters
    ----------
    num_var: int
        number of variables
    domain_size:  int
        size of the domain of the variables
    constraint_range: int
        range in which constraints take their value (uniform random value of
        ech possible assignment).

    Returns
    -------
    A tuple with variables, constraints and domain.
    """

    # Use a barabasi powerlaw based constraints graph
    graph = nx.barabasi_albert_graph(num_var, 2)

    # import matplotlib.pyplot as plt
    # plt.subplot(121)
    # nx.draw(graph)  # default spring_layout
    # plt.show()

    domain = Domain("d", "d", range(domain_size))
    variables = {}
    for n in graph.nodes:
        v = Variable(var_name(n), domain)
        variables[v.name] = v
        logger.debug("Create var for node %s : %s", n, v)

    constraints = {}
    for i, (n1, n2) in enumerate(graph.edges):
        v1 = variables[var_name(n1)]
        v2 = variables[var_name(n2)]
        values = random_assignment_matrix([v1, v2], range(constraint_range))
        c = NAryMatrixRelation([v1, v2], values, name=c_name(n1, n2))
        logger.debug("Create constraints for edge (%s, %s) : %s", v1, v2, c)
        constraints[c.name] = c

    logger.info(
        "Generates %s variables and %s constraints in a powerlaw" "network",
        len(variables),
        len(constraints),
    )

    return variables, constraints, domain 
開發者ID:Orange-OpenSource,項目名稱:pyDcop,代碼行數:58,代碼來源:iot.py


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