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:
  • n (int) -- The number of nodes.

  • p (float) -- 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.

  • seed (integer, random_state, or None (default)) -- Indicator of random number generation state.

Examples

>>> from cfpq_data import *
>>> g = labeled_binomial_graph(42, 0.84, seed=42)
>>> g.number_of_nodes()
42
>>> g.number_of_edges()
1453
Returns:

g -- An Erdős-Rényi graph random graph.

Return type:

MultiDiGraph

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]
  1. Erdős and A. Rényi, On Random Graphs, Publ. Math. 6, 290 (1959).

[2]
    1. Gilbert, Random Graphs, Ann. Math. Stat., 30, 1141 (1959).