Random graph generation in graph-tool

Dear all,

This must be a quite studip question. I am slightly confused about the
random graph generation in graph-tool. So I tried generating an ER network:

def deg_samp(k0 = 3):
     return np.random.poisson(k0)

G = gt.random_graph(500, lambda : deg_samp(3), directed = False)

This gives reasonable result:

<Graph object, undirected, with 500 vertices and 780 edges at
0x7f516e897f98>

However, I think that the following call is equivalent:

G = gt.random_graph(500, deg_samp, directed = False)

But this results into an extremely dense graph:

<Graph object, undirected, with 500 vertices and 62252 edges at
0x7f516e8b59b0>

What am I missing exactly?

Thank you
Snehal

attachment.html (1.36 KB)

Impossible to say, without a minimal, complete and self-contained example.

Hello Tiago,

Thanks for the reply. I have included all the commands in the previous
email. My degree_sampler is a function:

def deg_samp(k0 = 3):
     return np.random.poisson(k0)

Then I use it in two different (and in my opinion, equivalent) ways:

G = gt.random_graph(500, lambda : deg_samp(3), directed = False)
G = gt.random_graph(500, deg_samp, directed = False)

I expect both these graphs to be similar. However, I find that the second
one is extremely dense and its average degree far exceeds 3. I am quite
confused about this.

Thank you
Snehal

attachment.html (2.37 KB)

The function random_graph() will look at how many parameters the deg_sampler
takes, and this will trigger different behaviors. From the documentation:

    A degree sampler function which is called without arguments, and
    returns a tuple of ints representing the in and out-degree of a given
    vertex (or a single int for undirected graphs, representing the
    out-degree). This function is called once per vertex, but may be called
    more times, if the degree sequence cannot be used to build a graph.

    Optionally, you can also pass a function which receives one or two
    arguments. If block_membership is None, the single argument passed will
    be the index of the vertex which will receive the degree. If
    block_membership is not None, the first value passed will be the vertex
    index, and the second will be the block value of the vertex.

Your first example will trigger the behavior in the first paragraph, while
the second will trigger the behavior in the second paragraph.

Although it is in fact documented, I agree this is confusing and unexpected.
Please open an issue in the website, and this will be improved in the future.

Best,
Tiago