当前位置: 首页>>代码示例>>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;未经允许,请勿转载。