generate_shell

Contents

generate_shell#

graph_tool.generation.generate_shell(shells)[git][source]#

Generate a random shell graph.

Parameters:
shellsiterable of tuples (n, m, d)

For every shell, its number of vertices \(n\), its number of edges \(m\), and the fraction \(d\) of these edges that lie inside the shell.

Returns:
gGraph

The generated undirected graph.

bVertexPropertyMap

Shell of every vertex.

See also

generate_erdos_renyi

Uniformly random graphs

generate_sbm

Stochastic block model

Notes

Every shell is a uniformly random simple graph with \(n\) vertices and \(\lfloor md\rfloor\) edges, and \(m - \lfloor md\rfloor\) distinct edges are placed uniformly at random between it and the next shell (and none for the last shell). This is the microcanonical stochastic block model, without degree correction, with the shells as groups and the numbers of edges \(e_{rs}\) between them fixed (and nonzero only for \(|r - s| \le 1\)), restricted to simple graphs: generate_sbm() with micro_ers=True samples the same model without this restriction, i.e. with parallel edges and self-loops, whose rejection would make the sampling inefficient for dense shells. The algorithm runs in time \(O(N + E)\).

Examples

>>> g, b = gt.generate_shell([(10, 20, 0.8), (20, 40, 0.8),
...                           (50, 200, 1)])
>>> print(g.num_vertices(), g.num_edges())
80 260

The graph is drawn as follows:

>>> cmap = matplotlib.colors.ListedColormap(
...     ["#9bbedc", "#f28c8e", "#a6d7a4"])
>>> gt.graph_draw(g, pos=gt.sfdp_layout(g), vertex_fill_color=b, vcmap=cmap,
...               output="generate_shell-example.pdf")
<...>
../_images/generate_shell-example.png

Random shell graph with three shells of 10, 20, and 50 vertices, in blue, red, and green.#