generate_lobster

generate_lobster#

graph_tool.generation.generate_lobster(N, p1, p2)[git][source]#

Generate a random lobster graph.

Parameters:
Nfloat

Expected number of vertices of the backbone.

p1float

Probability of adding another edge to the backbone vertices.

p2float

Probability of adding another edge to the vertices one level beyond the backbone.

Returns:
gGraph

The generated undirected tree.

See also

generate_random_tree

Uniformly random trees

generate_power_law_tree

Random trees with power-law degrees

Notes

A lobster is a tree that becomes a path (the backbone) when the leaves are removed twice. The backbone is a path with \(L = \lfloor 2UN + 1/2\rfloor\) vertices, for \(U\) uniform in \([0, 1)\); every backbone vertex receives a number \(a\) of legs, i.e. new vertices adjacent to it, and every leg a number \(b\) of leaves adjacent to it, all sampled independently from the geometric distributions

\[P(a) = (1-p_1)p_1^a, \qquad P(b) = (1-p_2)p_2^b,\]

with means \(p_1/(1-p_1)\) and \(p_2/(1-p_2)\). The backbone vertices have the indices \(0,\dots,L-1\) in the order of the path, and every leg is followed by its leaves. The algorithm runs in time \(O(N)\) on average.

Examples

>>> g = gt.generate_lobster(100, 0.5, 0.5)
>>> print(g.num_vertices(), g.num_edges())
445 444

A smaller instance is drawn as follows:

>>> g = gt.generate_lobster(10, 0.5, 0.5)
>>> gt.graph_draw(g, pos=gt.sfdp_layout(g),
...               output="generate_lobster-small.pdf")
<...>
../_images/generate_lobster-small.png

Random lobster with \(N=10\) and \(p_1=p_2=0.5\).#