generate_relaxed_caveman

generate_relaxed_caveman#

graph_tool.generation.generate_relaxed_caveman(l, k, p)[git][source]#

Generate a relaxed caveman graph.

Parameters:
lint

Number of cliques (“caves”).

kint

Size of the cliques.

pfloat

Rewiring probability.

Returns:
gGraph

The generated graph.

bVertexPropertyMap

Clique of every vertex.

See also

generate_planted_partition

Planted partition model

generate_lfr

LFR benchmark

named_graph

Caveman and connected caveman graphs

Notes

The graph starts as \(l\) disjoint cliques of \(k\) vertices [watts-networks-1999], and every edge \((u, v)\) is visited once and, with probability \(p\), has its endpoint \(v\) moved to a vertex \(x\) chosen uniformly at random, unless \(x = u\) or the edge \((u, x)\) already exists, so that the graph remains simple. The algorithm runs in time \(O(lk^2)\).

References

[watts-networks-1999]

Duncan J. Watts, “Networks, dynamics, and the small-world phenomenon”, American Journal of Sociology 105, 493-527 (1999), DOI: 10.1086/210318 [sci-hub, @tor]

Examples

>>> g, b = gt.generate_relaxed_caveman(20, 10, 0.1)
>>> print(g.num_edges(), gt.global_clustering(g)[0])
900 0.73357...

A smaller instance is drawn as follows:

>>> g, b = gt.generate_relaxed_caveman(6, 6, 0.1)
>>> cmap = matplotlib.colors.ListedColormap(
...     ["#9bbedc", "#f28c8e", "#a6d7a4", "#cba6d1", "#ffbf7f",
...      "#ffff99"])
>>> gt.graph_draw(g, pos=gt.sfdp_layout(g), vertex_fill_color=b, vcmap=cmap,
...               output="generate_relaxed_caveman-small.pdf")
<...>
../_images/generate_relaxed_caveman-small.png

Relaxed caveman graph with \(l=6\) cliques of \(k=6\) vertices and \(p=0.1\). The vertex colors indicate the initial cliques.#