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_in
float Probability of an edge between vertices of the same group.
- p_out
float Probability of an edge between vertices of different groups.
- directed
bool(optional, default:False) If
True, a directed graph is generated.
- sizesiterable of
- Returns:
- g
Graph The generated graph.
- b
VertexPropertyMap Group membership of the vertices, which are numbered consecutively by group.
- g
See also
generate_maxent_sbmMaximum-entropy stochastic block model
generate_lfrLFR benchmark
Notes
Every pair of vertices is connected independently, with probability
p_ininside the groups andp_outbetween them [condon-algorithms-2001] (with \(l\) groups of \(k\) vertices forsizes=[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 withgenerate_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") <...>
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.#