cfpq_data.graphs.generators.labeled_binomial_graph#
- labeled_binomial_graph(n: int, p: float, *, labels: ~typing.List[str] = 'a', choice: ~typing.Callable[[~typing.List[str]], str] = <bound method Random.choice of <random.Random object>>, seed: int | None = None) MultiDiGraph[source]#
Returns a \(G_{n,p}\) random graph, also known as an Erdős-Rényi graph or a binomial graph. With labeled edges.
The \(G_{n,p}\) model chooses each of the possible edges with probability \(p\).
- Parameters:
- nint
The number of nodes.
- pfloat
Probability for edge creation.
- labels: Iterable[str]
Labels that will be used to mark the edges of the graph.
- choice: Callable[[Iterable[str]], str]
Function for marking edges.
- seedinteger, random_state, or None (default)
Indicator of random number generation state.
- Returns:
- gMultiDiGraph
An Erdős-Rényi graph random graph.
Notes
This algorithm runs in \(O(n^2)\) time. For sparse graphs (that is, for small values of \(p\)),
fast_labeled_binomial_graph()is faster.References
[1]Erdős and A. Rényi, On Random Graphs, Publ. Math. 6, 290 (1959).
[2]Gilbert, Random Graphs, Ann. Math. Stat., 30, 1141 (1959).
Examples
>>> from cfpq_data import * >>> g = labeled_binomial_graph(42, 0.84, seed=42) >>> g.number_of_nodes() 42 >>> g.number_of_edges() 1453