igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] how to properly generate a barabasi graph in Python without


From: Tamas Nepusz
Subject: Re: [igraph] how to properly generate a barabasi graph in Python without multi-edges
Date: Wed, 23 Dec 2009 13:00:13 +0000

Hi,

> I'm using python-igraph and am confused as to how to generate an
> undirected, scale-free barabasi graph of 1000 nodes WITHOUT
> multi-edges and self-loops.  When I use the built-in method, it always
> generates graphs with multi-edges.  If using simplify(), this will
> possibly result in a graph that doesn't follow the power law.
Well, a graph with only a thousand nodes is not likely to follow the power law 
anyway as the finite size effect is not negligible at this scale. (The power 
law holds only in the case when you have an infinite number of nodes, and the 
original model does not specify that there are no multi-edges as far as I know 
-- please correct me if I am wrong).

> In a previous question on the mailing list from more than a year ago,
> it was suggested that one could do this in R:
Something similar in Python:

import random

def barabasi_game2(n, m, directed=True):
    edges = []
    for i in xrange(1, n):
        no_neis = min(i, m)
        neis = random.sample(range(i), no_neis)
        edges.extend(zip([i] * no_neis, neis))
    return Graph(n, edges, directed)

I haven't tested it too much, but it looks OK to me.

-- 
Tamas





reply via email to

[Prev in Thread] Current Thread [Next in Thread]