generate_static_fitness

generate_static_fitness#

graph_tool.generation.generate_static_fitness(M, out_fitness, in_fitness=None, self_loops=False, parallel_edges=False)[git][source]#

Generate a random graph with a given number of edges, whose endpoints are chosen with probabilities proportional to vertex fitnesses.

Parameters:
Mint

Number of edges.

out_fitnessiterable of float

Fitness of every vertex (its out-fitness, if in_fitness is given).

in_fitnessiterable of float (optional, default: None)

In-fitness of every vertex. If given, a directed graph is generated.

self_loopsbool (optional, default: False)

If True, self-loops are allowed.

parallel_edgesbool (optional, default: False)

If True, parallel edges are allowed.

Returns:
gGraph

The generated graph.

See also

generate_static_power_law

Static model with power-law fitnesses

generate_chung_lu

Graphs with given expected degrees

generate_sbm

Poisson and microcanonical stochastic block models

Notes

In the static model of Goh, Kahng, and Kim [goh-universal-2001], the edges are placed one at a time, between a source \(i\) and a target \(j\) chosen independently with probabilities

\[P(i) = \frac{f^+_i}{\sum_kf^+_k}, \qquad P(j) = \frac{f^-_j}{\sum_kf^-_k},\]

where \(f^+_i\) and \(f^-_j\) are the out- and in-fitnesses (both equal to the fitness \(f_i\) for undirected graphs). A pair that would form a forbidden self-loop or parallel edge (for undirected graphs, a pair already connected in either orientation) is rejected, and pairs are drawn until \(M\) edges are placed. The expected degrees are proportional to the fitnesses exactly if both are allowed, and approximately otherwise. The algorithm runs in time \(O(N + M)\), plus the time spent in rejections, which grows as the graph approaches the maximum number of edges.

If both self-loops and parallel edges are allowed, there are no rejections, and the model is the microcanonical degree-corrected stochastic block model with a single group, \(M\) edges, and vertex propensities \(\theta_i = f_i\) (or \(\theta^+_i = f^+_i\) and \(\theta^-_i = f^-_i\)), so that the graph is generated with generate_sbm() with micro_ers=True.

References

[goh-universal-2001]

K.-I. Goh, B. Kahng and D. Kim, “Universal behavior of load distribution in scale-free networks”, Physical Review Letters 87, 278701 (2001), DOI: 10.1103/PhysRevLett.87.278701 [sci-hub, @tor], arXiv: cond-mat/0106565

Examples

>>> f = np.arange(1, 1001) ** -.5
>>> g = gt.generate_static_fitness(5000, f)
>>> print(g.num_edges(), g.degree_property_map("total").a[:3])
5000 [128 109  82]

A smaller instance is drawn as follows:

>>> f = np.arange(1, 201) ** -.5
>>> g = gt.generate_static_fitness(300, f)
>>> gt.graph_draw(g, pos=gt.sfdp_layout(g),
...               output="generate_static_fitness-small.pdf")
<...>
../_images/generate_static_fitness-small.png

Static fitness graph with \(N=200\) vertices, \(M=300\) edges, and fitnesses \(f_i = i^{-1/2}\).#