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:
- N
int Number of vertices.
- gamma
float(optional, default:3) Exponent of the power law.
- tries
int(optional, default:100) Maximum number of attempts to adjust the degree sequence.
- N
- Returns:
- g
Graph The generated undirected tree.
- g
See also
degree_sequence_treeTree with a given degree sequence
generate_random_treeUniformly 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(). AValueErroris raised if this fails aftertriesreplacements.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") <...>
Random tree with \(N=100\) vertices and power-law degrees with \(\gamma=3\), which is a caterpillar, as constructed by
degree_sequence_tree().#