[graph-tool] Random graph generation in graph-tool

Tiago de Paula Peixoto tiago at skewed.de
Mon Feb 13 18:35:58 CET 2017

On 13.02.2017 17:05, Snehal Shekatkar wrote:
> 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.

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.


Tiago de Paula Peixoto <tiago at skewed.de>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.skewed.de/pipermail/graph-tool/attachments/20170213/2dd3fc03/attachment.asc>

More information about the graph-tool mailing list