generate_power_law_tree

generate_power_law_tree#

graph_tool.generation.generate_power_law_tree(N, gamma=3, tries=100)[git][source]#

Generate a random tree with a power-law degree distribution.

Parameters:
Nint

Number of vertices.

gammafloat (optional, default: 3)

Exponent of the power law.

triesint (optional, default: 100)

Maximum number of attempts to adjust the degree sequence.

Returns:
gGraph

The generated undirected tree.

See also

degree_sequence_tree

Tree with a given degree sequence

generate_random_tree

Uniformly random trees

Notes

The \(N\) degrees are sampled independently as \(\min(\lfloor z\rceil, N)\), where \(z\) follows the Pareto distribution with density \(P(z) = (\gamma-1)z^{-\gamma}\) for \(z \ge 1\), and \(\lfloor z\rceil\) is \(z\) rounded to the nearest integer. Then, while the sum of the degrees differs from \(2(N-1)\), a uniformly chosen entry is replaced by a new sample. The resulting sequence, which is the degree sequence of a tree, is realized with degree_sequence_tree(). A ValueError is raised if this fails after tries replacements.

Examples

>>> g = gt.generate_power_law_tree(10, tries=10000)
>>> print(sorted(g.get_out_degrees(g.get_vertices()).tolist()))
[1, 1, 1, 1, 2, 2, 2, 2, 2, 4]

A larger instance is drawn as follows:

>>> g = gt.generate_power_law_tree(100, tries=10000)
>>> gt.graph_draw(g, pos=gt.sfdp_layout(g),
...               output="generate_power_law_tree-large.pdf")
<...>
../_images/generate_power_law_tree-large.png

Random tree with \(N=100\) vertices and power-law degrees with \(\gamma=3\), which is a caterpillar, as constructed by degree_sequence_tree().#