How to use the igraph.Graph.Erdos_Renyi function in igraph

To help you get started, we’ve selected a few igraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vtraag / leidenalg / tests / test_VertexPartition.py View on Github external
'Zachary'),

    ###########################################################################
    # ER Networks
    # Undirected no loop
    name_object(ig.Graph.Erdos_Renyi(100, p=1./100, directed=False, loops=False),
                'ER_k1_undirected_no_loops'),
    name_object(ig.Graph.Erdos_Renyi(100, p=5./100, directed=False, loops=False),
                'ER_k5_undirected_no_loops'),
    # Directed no loop
    name_object(ig.Graph.Erdos_Renyi(100, p=1./100, directed=True, loops=False),
                'ER_k1_directed_no_loops'),
    name_object(ig.Graph.Erdos_Renyi(100, p=5./100, directed=True, loops=False),
                'ER_k5_directed_no_loops'),
    # Undirected loops
    name_object(ig.Graph.Erdos_Renyi(100, p=1./100, directed=False, loops=True),
                'ER_k1_undirected_loops'),
    name_object(ig.Graph.Erdos_Renyi(100, p=5./100, directed=False, loops=True),
                'ER_k5_undirected_loops'),
    # Directed loops
    name_object(ig.Graph.Erdos_Renyi(100, p=1./100, directed=True, loops=True),
                'ER_k1_directed_loops'),
    name_object(ig.Graph.Erdos_Renyi(100, p=5./100, directed=True, loops=True),
                'ER_k5_directed_loops'),

    ###########################################################################
    # Tree
    name_object(ig.Graph.Tree(100, 3, type=ig.TREE_UNDIRECTED),
                'Tree_undirected'),
    name_object(ig.Graph.Tree(100, 3, type=ig.TREE_OUT),
                'Tree_directed_out'),
    name_object(ig.Graph.Tree(100, 3, type=ig.TREE_IN),
github vtraag / leidenalg / tests / test_VertexPartition.py View on Github external
name_object(ig.Graph.Erdos_Renyi(100, p=1./100, directed=False, loops=False),
                'ER_k1_undirected_no_loops'),
    name_object(ig.Graph.Erdos_Renyi(100, p=5./100, directed=False, loops=False),
                'ER_k5_undirected_no_loops'),
    # Directed no loop
    name_object(ig.Graph.Erdos_Renyi(100, p=1./100, directed=True, loops=False),
                'ER_k1_directed_no_loops'),
    name_object(ig.Graph.Erdos_Renyi(100, p=5./100, directed=True, loops=False),
                'ER_k5_directed_no_loops'),
    # Undirected loops
    name_object(ig.Graph.Erdos_Renyi(100, p=1./100, directed=False, loops=True),
                'ER_k1_undirected_loops'),
    name_object(ig.Graph.Erdos_Renyi(100, p=5./100, directed=False, loops=True),
                'ER_k5_undirected_loops'),
    # Directed loops
    name_object(ig.Graph.Erdos_Renyi(100, p=1./100, directed=True, loops=True),
                'ER_k1_directed_loops'),
    name_object(ig.Graph.Erdos_Renyi(100, p=5./100, directed=True, loops=True),
                'ER_k5_directed_loops'),

    ###########################################################################
    # Tree
    name_object(ig.Graph.Tree(100, 3, type=ig.TREE_UNDIRECTED),
                'Tree_undirected'),
    name_object(ig.Graph.Tree(100, 3, type=ig.TREE_OUT),
                'Tree_directed_out'),
    name_object(ig.Graph.Tree(100, 3, type=ig.TREE_IN),
                'Tree_directed_in'),

    ###########################################################################
    # Lattice
    name_object(ig.Graph.Lattice([100], nei=3, directed=False, mutual=True, circular=True),
github vtraag / leidenalg / tests / test_Optimiser.py View on Github external
def test_diff_move_node_optimality(self):
    G = ig.Graph.Erdos_Renyi(100, p=5./100, directed=False, loops=False);
    partition = leidenalg.CPMVertexPartition(G, resolution_parameter=0.1);
    while 0 < self.optimiser.move_nodes(partition, consider_comms=leidenalg.ALL_NEIGH_COMMS):
      pass;
    for v in G.vs:
      neigh_comms = set(partition.membership[u.index] for u in v.neighbors());
      for c in neigh_comms:
        self.assertLessEqual(
          partition.diff_move(v.index, c), 1e-10, # Allow for a small difference up to rounding error.
          msg="Was able to move a node to a better community, violating node optimality.");
github neurodata / m2g / MR-OCP / MROCPdjango / computation / utils / igraph_to_csc.py View on Github external
def test():
  """
  Test function ran with -t flag
  """
  print "Running 5 node test ...."
  g = igraph.Graph.Erdos_Renyi(n=5, p=0.3)
  g = igraph_to_csc(g)
  print "Test complete ..."
  print g.todense()
github charanpald / APGL / exp / influence2 / profile / MaxInfluenceProfile.py View on Github external
def profileGreedyMethod2(self):
         
        n = 1000 
        p = 0.1
        graph = igraph.Graph.Erdos_Renyi(n, p)
        print(graph.summary())
            
        k = 5
        numpy.random.seed(21) 
        ProfileUtils.profile('MaxInfluence.greedyMethod2(graph, k, p=0.5, numRuns=1000)', globals(), locals())
github charanpald / APGL / exp / influence2 / profile / MaxInfluenceProfile.py View on Github external
def profileCelf(self):
         
        n = 100 
        p = 0.1
        graph = igraph.Graph.Erdos_Renyi(n, p)
        print(graph.summary())
            
        k = 5
        numpy.random.seed(21) 
        ProfileUtils.profile('MaxInfluence.celf(graph, k, p=0.5, numRuns=100)', globals(), locals())
github xunzheng / notears / notears / utils.py View on Github external
B (np.ndarray): [d, d] binary adj matrix of DAG
    """
    def _random_permutation(M):
        # np.random.permutation permutes first axis only
        P = np.random.permutation(np.eye(M.shape[0]))
        return P.T @ M @ P

    def _random_acyclic_orientation(B_und):
        return np.tril(_random_permutation(B_und), k=-1)

    def _graph_to_adjmat(G):
        return np.array(G.get_adjacency().data)

    if graph_type == 'ER':
        # Erdos-Renyi
        G_und = ig.Graph.Erdos_Renyi(n=d, m=s0)
        B_und = _graph_to_adjmat(G_und)
        B = _random_acyclic_orientation(B_und)
    elif graph_type == 'SF':
        # Scale-free, Barabasi-Albert
        G = ig.Graph.Barabasi(n=d, m=int(round(s0 / d)), directed=True)
        B = _graph_to_adjmat(G)
    elif graph_type == 'BP':
        # Bipartite, Sec 4.1 of (Gu, Fu, Zhou, 2018)
        top = int(0.2 * d)
        G = ig.Graph.Random_Bipartite(top, d - top, m=s0, directed=True, neimode=ig.OUT)
        B = _graph_to_adjmat(G)
    else:
        raise ValueError('unknown graph type')
    B_perm = _random_permutation(B)
    assert ig.Graph.Adjacency(B_perm.tolist()).is_dag()
    return B_perm
github Lab41 / Circulo / circulo / algorithms / snap_coda.py View on Github external
def main():

    G = igraph.Graph.Erdos_Renyi(n=30, m=100)
    snap_home, filename = setup(G)

    vc = coda(G)
    print(vc)
github telmomenezes / synthetic / synthetic / distances.py View on Github external
def __compute_norm_values(self, net, norm_samples):
        vcount = net.vcount()
        ecount = net.ecount()
        directed = net.is_directed()

        norm_values = [.0] * self.nstats
        dists2net = DistancesToNet(net, self.stat_dist_types, self.bins,
                                   self.max_dist, norm=Norm.NONE)

        for i in range(norm_samples):
            # noinspection PyArgumentList
            sample_net = igraph.Graph.Erdos_Renyi(n=vcount, m=ecount,
                                                  directed=directed)
            dists = dists2net.compute(sample_net)
            for j in range(self.nstats):
                norm_values[j] += dists[j]

        norm_values = [max(x / norm_samples, SMALL_VALUE) for x in norm_values]
        return norm_values