cfpq_data.graphs.generators.fast_labeled_binomial_graph#

fast_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 = fast_labeled_binomial_graph(42, 0.42, seed=42)
>>> g.number_of_nodes()
42
>>> g.number_of_edges()
711
Returns:

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

Return type:

MultiDiGraph

Notes

The \(G_{n,p}\) graph algorithm chooses each of the \((n (n - 1)) / 2\) (undirected) or \(n (n - 1)\) (directed) possible edges with probability \(p\).

This algorithm [4] runs in \(O(n + m)\) time, where \(m\) is the expected number of edges, which equals \(p n (n - 1) / 2\). This should be faster than labeled_binomial_graph() when \(p\) is small and the expected number of edges is small (that is, the graph is sparse).

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).

[4]

Vladimir Batagelj and Ulrik Brandes, "Efficient generation of large random networks", Phys. Rev. E, 71, 036113, 2005.