• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python networkx.erdos_renyi_graph函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_multi

    def test_multi(self):

        vm = MultiPlot()

        g = nx.erdos_renyi_graph(1000, 0.1)
        model = epd.SIRModel(g)
        config = mc.Configuration()
        config.add_model_parameter('beta', 0.001)
        config.add_model_parameter('gamma', 0.01)
        config.add_model_parameter("percentage_infected", 0.05)
        model.set_initial_status(config)
        iterations = model.iteration_bunch(200)
        trends = model.build_trends(iterations)
        viz = DiffusionTrend(model, trends)
        p = viz.plot()

        vm.add_plot(p)

        g = nx.erdos_renyi_graph(1000, 0.1)
        model = epd.SIRModel(g)
        config = mc.Configuration()
        config.add_model_parameter('beta', 0.001)
        config.add_model_parameter('gamma', 0.01)
        config.add_model_parameter("percentage_infected", 0.05)
        model.set_initial_status(config)
        iterations = model.iteration_bunch(200)
        trends = model.build_trends(iterations)
        viz = DiffusionPrevalence(model, trends)
        p1 = viz.plot()

        vm.add_plot(p1)
        m = vm.plot()
        self.assertIsInstance(m, Column)
开发者ID:GiulioRossetti,项目名称:ndlib,代码行数:33,代码来源:test_viz.py


示例2: synthetic_three_level

def synthetic_three_level(n,p1,p2,p3,J_isolates=False,F_isolates=False,D_isolates=False):#,isolate_up=True,isolate_down=True):
    
    k=n

    J=nx.erdos_renyi_graph(n,p1) #The first layer graph
    Jis = nx.isolates(J)
    F=nx.erdos_renyi_graph(n,p2) #The second layer graph
    Fis = nx.isolates(F)
    D=nx.erdos_renyi_graph(n,p3) #The third layer graph
    Dis = nx.isolates(D)

    def translation_graph(J,F,D):
        H1=nx.Graph()
        H2=nx.Graph()
        for i in range(n):
            H1.add_edges_from([(J.nodes()[i],F.nodes()[i])])
            H2.add_edges_from([(F.nodes()[i],D.nodes()[i])])
        return H1, H2

    Jed = set(J.edges())
    Fed = set(F.edges())
    Ded = set(D.edges())
    l=[Jed,Fed,Ded]
    lu = list(set.union(*l))
    JFD=nx.Graph()
    JFD.add_edges_from(lu)

    G=nx.Graph()  #The synthetic two-layer graph
    
    # Relabing nodes maps
    
    mappingF={}
    for i in range(2*n):
        mappingF[i]=n+i
    FF=nx.relabel_nodes(F,mappingF,copy=True)
    
    mappingD={}
    for i in range(2*n):
        if i >n-1:
            mappingD[i]=i-n
        else:
            mappingD[i]=2*n+i
    DD=nx.relabel_nodes(D,mappingD,copy=True)
    
    H1, HH2 = translation_graph(J,FF,DD)
    
    G.add_edges_from(J.edges())
    G.add_edges_from(H1.edges())
    G.add_edges_from(DD.edges())
    G.add_edges_from(HH2.edges())
    G.add_edges_from(FF.edges())

    edgeList = []
    for e in H1.edges():
        edgeList.append(e)
    for e in HH2.edges():
        edgeList.append(e)
    
    return G, J, FF, DD, JFD, edgeList  
开发者ID:mboudour,项目名称:GraphMultilayerity,代码行数:59,代码来源:syntheticThreeLayerGraph_time.py


示例3: test_strong_product

def test_strong_product():
    null=nx.null_graph()
    empty1=nx.empty_graph(1)
    empty10=nx.empty_graph(10)
    K2=nx.complete_graph(2)
    K3=nx.complete_graph(3)
    K5=nx.complete_graph(5)
    K10=nx.complete_graph(10)
    P2=nx.path_graph(2)
    P3=nx.path_graph(3)
    P5=nx.path_graph(5)
    P10=nx.path_graph(10)
    # null graph
    G=strong_product(null,null)
    assert_true(nx.is_isomorphic(G,null))
    # null_graph X anything = null_graph and v.v.
    G=strong_product(null,empty10)
    assert_true(nx.is_isomorphic(G,null))
    G=strong_product(null,K3)
    assert_true(nx.is_isomorphic(G,null))
    G=strong_product(null,K10)
    assert_true(nx.is_isomorphic(G,null))
    G=strong_product(null,P3)
    assert_true(nx.is_isomorphic(G,null))
    G=strong_product(null,P10)
    assert_true(nx.is_isomorphic(G,null))
    G=strong_product(empty10,null)
    assert_true(nx.is_isomorphic(G,null))
    G=strong_product(K3,null)
    assert_true(nx.is_isomorphic(G,null))
    G=strong_product(K10,null)
    assert_true(nx.is_isomorphic(G,null))
    G=strong_product(P3,null)
    assert_true(nx.is_isomorphic(G,null))
    G=strong_product(P10,null)
    assert_true(nx.is_isomorphic(G,null))

    G=strong_product(P5,K3)
    assert_equal(nx.number_of_nodes(G),5*3)
    G=strong_product(K3,K5)
    assert_equal(nx.number_of_nodes(G),3*5)

    #No classic easily found classic results for strong product

    G = nx.erdos_renyi_graph(10,2/10.)
    H = nx.erdos_renyi_graph(10,2/10.)
    GH = strong_product(G,H)

    for (u_G,u_H) in GH.nodes_iter():
        for (v_G,v_H) in GH.nodes_iter():
            if (u_G==v_G and H.has_edge(u_H,v_H)) or \
               (u_H==v_H and G.has_edge(u_G,v_G)) or \
               (G.has_edge(u_G,v_G) and H.has_edge(u_H,v_H)):
                assert_true(GH.has_edge((u_G,u_H),(v_G,v_H)))
            else:
                assert_true(not GH.has_edge((u_G,u_H),(v_G,v_H)))
开发者ID:AhmedPho,项目名称:NetworkX_fork,代码行数:56,代码来源:test_operators.py


示例4: test_tensor_product_random

def test_tensor_product_random():
    G = nx.erdos_renyi_graph(10,2/10.)
    H = nx.erdos_renyi_graph(10,2/10.)
    GH = tensor_product(G,H)

    for (u_G,u_H) in GH.nodes_iter():
        for (v_G,v_H) in GH.nodes_iter():
            if H.has_edge(u_H,v_H) and G.has_edge(u_G,v_G):
                assert_true(GH.has_edge((u_G,u_H),(v_G,v_H)))
            else:
                assert_true(not GH.has_edge((u_G,u_H),(v_G,v_H)))
开发者ID:Bludge0n,项目名称:AREsoft,代码行数:11,代码来源:test_product.py


示例5: create_list_of_adj_mats

def create_list_of_adj_mats(n_runs):
    adj_mats = []
    for i in xrange(n_runs):
        # Creating connected adj matrix
        net = nx.erdos_renyi_graph(N, link_density)
        while len(list(nx.connected_components(net))) > 1:
            print "Network has isolated components. Try again!"
            net = nx.erdos_renyi_graph(N, link_density)
        adj_mats.append(nx.adj_matrix(net).toarray())

    return adj_mats
开发者ID:wbarfuss,项目名称:cyexploit,代码行数:11,代码来源:profiling.py


示例6: test_lexicographic_product_random

def test_lexicographic_product_random():
    G = nx.erdos_renyi_graph(10,2/10.)
    H = nx.erdos_renyi_graph(10,2/10.)
    GH = lexicographic_product(G,H)

    for (u_G,u_H) in GH.nodes_iter():
        for (v_G,v_H) in GH.nodes_iter():
            if G.has_edge(u_G,v_G) or (u_G==v_G and H.has_edge(u_H,v_H)):
                assert_true(GH.has_edge((u_G,u_H),(v_G,v_H)))
            else:
                assert_true(not GH.has_edge((u_G,u_H),(v_G,v_H)))
开发者ID:Bludge0n,项目名称:AREsoft,代码行数:11,代码来源:test_product.py


示例7: test_cartesian_product_random

def test_cartesian_product_random():
    G = nx.erdos_renyi_graph(10,2/10.)
    H = nx.erdos_renyi_graph(10,2/10.)
    GH = cartesian_product(G,H)

    for (u_G,u_H) in GH.nodes_iter():
        for (v_G,v_H) in GH.nodes_iter():
            if (u_G==v_G and H.has_edge(u_H,v_H)) or \
               (u_H==v_H and G.has_edge(u_G,v_G)):
                assert_true(GH.has_edge((u_G,u_H),(v_G,v_H)))
            else:
                assert_true(not GH.has_edge((u_G,u_H),(v_G,v_H)))
开发者ID:Bludge0n,项目名称:AREsoft,代码行数:12,代码来源:test_product.py


示例8: __init__

 def __init__(self, name, para1, para2):
     if name == "PAM":
         # nodes, edges, and nodes > edges
         self.G = nx.barabasi_albert_graph(para1, para2)
         # nodes, prob
     elif name == "ER":
         self.G = nx.erdos_renyi_graph(para1, para2)
开发者ID:jieaozhu,项目名称:alignment_free_network_comparison,代码行数:7,代码来源:generate_feature.py


示例9: generate_graph

def generate_graph(n, expected_degree, model="ba"):
    """
    Generates a graph with a given model and expected_mean
    degree

    :param n: int Number of nodes of the graph
    :param expected_degree: int Expected mean degree
    :param model: string Model (ba, er, or ws)
    :return: networkx graph
    """

    global m
    global ws_p

    g = None
    if model == "ba":
        # BA expected avg. degree? m = ba_mean_degrees()
        if m is None:
            m = ba_mean_degrees(n, expected_degree)
        g = nx.barabasi_albert_graph(n, m, seed=None)
    if model == "er":
        # ER expected avg. degree: d = p*(n-1)
        p = float(expected_degree) / float(n - 1)
        g = nx.erdos_renyi_graph(n, p, seed=None, directed=False)
    if model == "ws":
        # WS expected degree == k
        g = nx.watts_strogatz_graph(n, expected_degree, ws_p)

    return g
开发者ID:cpsola,项目名称:FbAppsCollateralDamage,代码行数:29,代码来源:ifipsec.py


示例10: __init__

    def __init__(self, size, probability):
        self.size = size
        self.probability = probability
        self.network = nx.erdos_renyi_graph(self.size, self.probability, directed=False)

        # Network stats object
        self.networkStats = Networkstats(self.network, self.size)
开发者ID:rajcscw,项目名称:echo-state-networks,代码行数:7,代码来源:ReservoirTopology.py


示例11: test_dyn_node_stochastic

    def test_dyn_node_stochastic(self):

        dg = dn.DynGraph()

        for t in past.builtins.xrange(0, 3):
            g = nx.erdos_renyi_graph(200, 0.05)
            dg.add_interactions_from(g.edges(), t)

        model = gc.DynamicCompositeModel(dg)

        model.add_status("Susceptible")
        model.add_status("Infected")
        model.add_status("Removed")

        c1 = cpm.NodeStochastic(0.02, "Infected")
        c2 = cpm.NodeStochastic(0.01)
        c3 = cpm.NodeStochastic(0.5)

        model.add_rule("Susceptible", "Infected", c1)
        model.add_rule("Infected", "Removed", c2)
        model.add_rule("Infected", "Susceptible", c3)

        config = mc.Configuration()
        config.add_model_parameter('percentage_infected', 0.1)

        model.set_initial_status(config)
        iterations = model.execute_snapshots()
        self.assertEqual(len(iterations), 3)

        iterations = model.execute_iterations()
        trends = model.build_trends(iterations)
        self.assertEqual(len(trends[0]['trends']['status_delta'][1]),
                         len([x for x in dg.stream_interactions() if x[2] == "+"]))
开发者ID:GiulioRossetti,项目名称:ndlib,代码行数:33,代码来源:test_dynamic_compartment.py


示例12: test_directed_havel_hakimi

def test_directed_havel_hakimi():
    # Test range of valid directed degree sequences
    n, r = 100, 10
    p = 1.0 / r
    for i in range(r):
        G1 = nx.erdos_renyi_graph(n, p * (i + 1), None, True)
        din1 = list(d for n, d in G1.in_degree())
        dout1 = list(d for n, d in G1.out_degree())
        G2 = nx.directed_havel_hakimi_graph(din1, dout1)
        din2 = list(d for n, d in G2.in_degree())
        dout2 = list(d for n, d in G2.out_degree())
        assert_equal(sorted(din1), sorted(din2))
        assert_equal(sorted(dout1), sorted(dout2))

    # Test non-graphical sequence
    dout = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1]
    din = [103, 102, 102, 102, 102, 102, 102, 102, 102, 102]
    assert_raises(nx.exception.NetworkXError,
                  nx.directed_havel_hakimi_graph, din, dout)
    # Test valid sequences
    dout = [1, 1, 1, 1, 1, 2, 2, 2, 3, 4]
    din = [2, 2, 2, 2, 2, 2, 2, 2, 0, 2]
    G2 = nx.directed_havel_hakimi_graph(din, dout)
    dout2 = (d for n, d in G2.out_degree())
    din2 = (d for n, d in G2.in_degree())
    assert_equal(sorted(dout), sorted(dout2))
    assert_equal(sorted(din), sorted(din2))
    # Test unequal sums
    din = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
    assert_raises(nx.exception.NetworkXError,
                  nx.directed_havel_hakimi_graph, din, dout)
    # Test for negative values
    din = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -2]
    assert_raises(nx.exception.NetworkXError,
                  nx.directed_havel_hakimi_graph, din, dout)
开发者ID:jianantian,项目名称:networkx,代码行数:35,代码来源:test_degree_seq.py


示例13: spread_size_distribution_vs_probability

def spread_size_distribution_vs_probability():
    probabilities = [float(i) / 100. for i in range(100)]
    t = 1

    graph = sm.SISModel.get_opera_graph()
    seed = sm.SISModel.get_random_seed(graph, 100)
    print(seed)
    o_sizes = []

    for i in xrange(len(probabilities)):
        print(probabilities[i])
        o_sizes.append(sm.SISModel(graph, seed, probabilities[i], t).spread())
    print(o_sizes)

    graph = nx.barabasi_albert_graph(4604, 11)
    seed = sm.SISModel.get_random_seed(graph, 100)
    ba_sizes = []
    for i in xrange(len(probabilities)):
        ba_sizes.append(sm.SISModel(graph, seed, probabilities[i], t).spread())
    print(ba_sizes)

    graph = nx.erdos_renyi_graph(4604, 0.0047)
    seed = sm.SISModel.get_random_seed(graph, 100)
    er_sizes = []
    for i in xrange(len(probabilities)):
        er_sizes.append(sm.SISModel(graph, seed, probabilities[i], t).spread())
    print(er_sizes)

    sm.SISModel.plot_spread_size_distribution(
        probabilities,
        [o_sizes, ba_sizes, er_sizes],
        ['blue', 'black', 'red'],
        sm.SISModel.get_data_dir() + sm.SISModel.RESULT_DIR + 'spread_size_distribution.png',
        'p'
    )
开发者ID:vslovik,项目名称:ARS,代码行数:35,代码来源:sis_model_for_opera.py


示例14: test_bad_graph_input

 def test_bad_graph_input(self) :
     """modularity is only defined with undirected graph"""
     g = nx.erdos_renyi_graph(50, 0.1, directed=True)
     part = dict([])
     for node in g :
         part[node] = 0
     self.assertRaises(TypeError, co.modularity, part, g)
开发者ID:neozhangthe1,项目名称:experimental-code-archive,代码行数:7,代码来源:test_community.py


示例15: __init__

    def __init__(self, num_nodes=10, avg_node_degree=3, initial_outbreak_size=1, virus_spread_chance=0.4,
                virus_check_frequency=0.4, recovery_chance=0.3, gain_resistance_chance=0.5):

        self.num_nodes = num_nodes
        prob = avg_node_degree / self.num_nodes
        self.G = nx.erdos_renyi_graph(n=self.num_nodes, p=prob)
        self.grid = NetworkGrid(self.G)
        self.schedule = RandomActivation(self)
        self.initial_outbreak_size = initial_outbreak_size if initial_outbreak_size <= num_nodes else num_nodes
        self.virus_spread_chance = virus_spread_chance
        self.virus_check_frequency = virus_check_frequency
        self.recovery_chance = recovery_chance
        self.gain_resistance_chance = gain_resistance_chance

        self.datacollector = DataCollector({"Infected": number_infected,
                                            "Susceptible": number_susceptible,
                                            "Resistant": number_resistant})

        # Create agents
        for i, node in enumerate(self.G.nodes()):
            a = VirusAgent(i, self, State.SUSCEPTIBLE, self.virus_spread_chance, self.virus_check_frequency,
                           self.recovery_chance, self.gain_resistance_chance)
            self.schedule.add(a)
            # Add the agent to the node
            self.grid.place_agent(a, node)

        # Infect some nodes
        infected_nodes = self.random.sample(self.G.nodes(), self.initial_outbreak_size)
        for a in self.grid.get_cell_list_contents(infected_nodes):
            a.state = State.INFECTED

        self.running = True
        self.datacollector.collect(self)
开发者ID:bangtree,项目名称:mesa,代码行数:33,代码来源:model.py


示例16: iterated_test

def iterated_test(seed=None, testparams=None, params=None):        
    import algorithms
    print 'Starting iterative replication test...'
    if seed == None:
        seed = npr.randint(1E6)
        print 'Setting random number generator seed: %d'%seed
        random.seed(seed)
        npr.seed(seed)
    if params == None:
        params = {}
    defparams = {'edge_edit_rate':[0.05, 0.05], 'node_edit_rate':[0.05, 0.05], 'verbose':False, }
    defparams.update(params)
    params = defparams
    print 'params'
    print params
    if testparams == None:
        testparams = {}
    if 'G' not in testparams:
        nn = 1000
        p  = 0.01
        G = nx.erdos_renyi_graph(nn, p)
        G.add_edges_from(nx.path_graph(nn).edges())
    else:
        G = testparams['G']
    alg = testparams.get('algorithm', algorithms.generate_graph)

    num_rounds = testparams.get('num_rounds', 10)
    print 'Round: 1. Initial graph ' + getattr(G, 'name', '_')
    for trial in xrange(2, num_rounds+1):
        new_G = alg(original=G, params=params)
        seed = npr.randint(1E6)
        print 'Round: %d. New seed: %d'%(trial,seed)
        random.seed(seed)
        npr.seed(seed)
    print 'PASSED'
开发者ID:sashagutfraind,项目名称:musketeer,代码行数:35,代码来源:simpletesters.py


示例17: get_random_graph

def get_random_graph():
    G = nx.erdos_renyi_graph(100, 0.1)
    H = nx.Graph()
    for u,v in G.edges():
        d = random.uniform(1,10)
        H.add_edge(u, v, weight=d)
    return H
开发者ID:ryanrhymes,项目名称:classic,代码行数:7,代码来源:test_shortest_path.py


示例18: q2

def q2():
  gnutella = read_gdf("../../data/network_analysis/gnutella2.gdf")
  print_stats(gnutella, "Gnutella")
  p = compute_edge_creation_probability(
    gnutella.number_of_nodes(), gnutella.number_of_edges())
  erg = nx.erdos_renyi_graph(gnutella.number_of_nodes(), p)
  print_stats(erg, "Erdos-Renyi Random")
开发者ID:ChrisBg,项目名称:mlia-examples,代码行数:7,代码来源:small_world.py


示例19: q1

def q1():
  lada = nx.read_gml("../../data/network_analysis/LadaFacebookAnon.gml")
  print_stats(lada, "LadaFacebookAnon")
  p = compute_edge_creation_probability(
    lada.number_of_nodes(), lada.number_of_edges())
  erg = nx.erdos_renyi_graph(lada.number_of_nodes(), p)
  print_stats(erg, "Erdos-Renyi Random")
开发者ID:ChrisBg,项目名称:mlia-examples,代码行数:7,代码来源:small_world.py


示例20: sampleroadnet

def sampleroadnet( n=10, p=.3, n_oneway=0 ) :
    # based on Erdos Renyi ; n=# of nodes, p=probability any two nodes are linked
    g = nx.erdos_renyi_graph( n, p )
    # ...then just get the biggest connected component
    g = nx.connected_component_subgraphs( g )[0]
    
    # create a roadnet with such connectivity and random street lengths
    roadnet = nx.MultiDiGraph()
    def roadmaker() :
        for i in itertools.count() : yield 'road%d' % i, np.random.exponential()
    road_iter = roadmaker()
    
    for i, ( u,v,data ) in enumerate( g.edges_iter( data=True ) ) :
        label, length = road_iter.next()
        roadnet.add_edge( u, v, label, length=length )
        
    # add some random one-way roads
    nodes = roadnet.nodes()
    for i in range( n_oneway ) :
        u = random.choice( nodes )
        v = random.choice( nodes )
        label, length = road_iter.next()
        roadnet.add_edge( u, v, label, length=length, oneway=True )
        
    return roadnet
开发者ID:kyletreleaven,项目名称:roadgeometry,代码行数:25,代码来源:probability.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python networkx.eulerian_circuit函数代码示例发布时间:2022-05-27
下一篇:
Python networkx.empty_graph函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap