generate_planted_partition

generate_planted_partition#

graph_tool.generation.generate_planted_partition(sizes, p_in, p_out, directed=False)[git][source]#

Generate a simple graph from the planted partition model.

Parameters:
sizesiterable of int

Sizes of the groups.

p_infloat

Probability of an edge between vertices of the same group.

p_outfloat

Probability of an edge between vertices of different groups.

directedbool (optional, default: False)

If True, a directed graph is generated.

Returns:
gGraph

The generated graph.

bVertexPropertyMap

Group membership of the vertices, which are numbered consecutively by group.

See also

generate_maxent_sbm

Maximum-entropy stochastic block model

generate_lfr

LFR benchmark

Notes

Every pair of vertices is connected independently, with probability p_in inside the groups and p_out between them [condon-algorithms-2001] (with \(l\) groups of \(k\) vertices for sizes=[k] * l). This is the special case of the maximum-entropy stochastic block model for simple graphs with vertex fugacities \(\theta_i = 1\) and edge fugacities \(\mu_{rs} = p_{rs}/(1 - p_{rs})\), so that the probability of an edge is \(\mu_{rs}/(1 + \mu_{rs}) = p_{rs}\), and the graph is generated with generate_maxent_sbm(), in time \(O(N\log N + BN + E)\).

References

[condon-algorithms-2001]

Anne Condon and Richard M. Karp, “Algorithms for graph partitioning on the planted partition model”, Random Structures & Algorithms 18, 116-140 (2001), DOI: 10.1002/1098-2418(200103)18:2<116::AID-RSA1001>3.0.CO;2-2 [sci-hub, @tor]

Examples

>>> g, b = gt.generate_planted_partition([100] * 10, 0.1, 0.001)
>>> print(g.num_edges())
5524

A smaller instance is drawn as follows:

>>> g, b = gt.generate_planted_partition([25] * 4, 0.3, 0.01)
>>> cmap = matplotlib.colors.ListedColormap(
...     ["#9bbedc", "#f28c8e", "#a6d7a4", "#cba6d1"])
>>> gt.graph_draw(g, pos=gt.sfdp_layout(g), vertex_fill_color=b, vcmap=cmap,
...               output="generate_planted_partition-small.pdf")
<...>
../_images/generate_planted_partition-small.png

Planted partition graph with four groups of 25 vertices, \(p_\text{in}=0.3\), and \(p_\text{out}=0.01\). The vertex colors indicate the groups.#