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:
- N
int Number of vertices.
- p
float(optional, default:None) Probability of every edge (the \(G(N, p)\) model).
- M
int(optional, default:None) Number of edges (the \(G(N, M)\) model). Exactly one of
pandMmust be given.- directed
bool(optional, default:False) If
True, a directed graph is generated.- self_loops
bool(optional, default:False) If
True, self-loops are allowed.
- N
- Returns:
- g
Graph The generated simple graph.
- g
See also
generate_bipartite_erdos_renyiBipartite version
generate_maxent_sbmMaximum-entropy stochastic block model
generate_chung_luGraphs with given expected degrees
add_random_edgesAddition 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)\) ifself_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 withadd_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") <...>
\(G(N, p)\) random graph with \(N=100\) and \(p=0.03\).#