generate_erdos_renyi

generate_erdos_renyi#

graph_tool.generation.generate_erdos_renyi(N, p=None, M=None, directed=False, self_loops=False)[git][source]#

Generate a random graph with the Erdős-Rényi model.

Parameters:
Nint

Number of vertices.

pfloat (optional, default: None)

Probability of every edge (the \(G(N, p)\) model).

Mint (optional, default: None)

Number of edges (the \(G(N, M)\) model). Exactly one of p and M must be given.

directedbool (optional, default: False)

If True, a directed graph is generated.

self_loopsbool (optional, default: False)

If True, self-loops are allowed.

Returns:
gGraph

The generated simple graph.

See also

generate_bipartite_erdos_renyi

Bipartite version

generate_maxent_sbm

Maximum-entropy stochastic block model

generate_chung_lu

Graphs with given expected degrees

add_random_edges

Addition of uniformly random edges

Notes

In the \(G(N, p)\) version of the Erdős–Rényi model [erdos-random-1959] [gilbert-random-1959], every one of the \(P\) admissible pairs of vertices is connected independently with probability \(p\), where \(P = N(N-1)/2\) for unordered pairs of distinct vertices, \(P = N(N-1)\) for ordered pairs if directed == True, and \(N\) more pairs \((i, i)\) if self_loops == True. It is sampled by drawing the number of edges \(M\) from the binomial distribution with parameters \(P\) and \(p\), and then choosing \(M\) distinct admissible pairs uniformly at random with add_random_edges(), in time \(O(N + M)\) (for not too dense graphs). In the \(G(N, M)\) model, the graph is chosen uniformly among the simple graphs with exactly \(M\) edges, by placing them in the same way.

References

[erdos-random-1959]

P. Erdős and A. Rényi, “On random graphs I”, Publicationes Mathematicae Debrecen 6, 290-297 (1959), DOI: 10.5486/PMD.1959.6.3-4.12 [sci-hub, @tor]

[gilbert-random-1959]

E. N. Gilbert, “Random graphs”, The Annals of Mathematical Statistics 30, 1141-1144 (1959), DOI: 10.1214/aoms/1177706098 [sci-hub, @tor]

Examples

>>> g = gt.generate_erdos_renyi(1000, p=0.01)
>>> print(g.num_edges())
4878

A smaller instance is drawn as follows:

>>> g = gt.generate_erdos_renyi(100, p=0.03)
>>> gt.graph_draw(g, pos=gt.sfdp_layout(g),
...               output="generate_erdos_renyi-small.pdf")
<...>
../_images/generate_erdos_renyi-small.png

\(G(N, p)\) random graph with \(N=100\) and \(p=0.03\).#