Erdős-Rényi graphs#

\(G(n, p)\) Erdős-Rényi graphs.

tinto.theory.erdos_renyi.factorial_moments(n, p, k=1)[source]#

Exact \(\mathbb E S\) and \(\mathbb E S(S-1)\) on \(G(n, p)\).

The closed form of the second factorial moment, with \(s = 1 - p/k\), \(t_1 = 1 - (2p - p^2)/k\), \(t_2 = 1 - 2p/k\) and \(F(g) = \frac kp \left(\frac{1 - g^n}{1 - g} - \frac{s^n - g^n}{s - g}\right)\), is

\[\mathbb E S(S-1) = 2\left(\frac{1-p}{k} F(t_1) + \frac{k-1}{k} F(t_2)\right).\]

With a Fraction p the result is exact.

Parameters:
  • n (int) – Number of nodes.

  • p (float or Fraction) – Edge probability, 0 < p < 1.

  • k (int, default=1) – Number of colors.

Returns:

(E S, E S(S-1)).

Return type:

tuple

Examples

>>> from fractions import Fraction
>>> factorial_moments(3, Fraction(1, 2))
(Fraction(7, 4), Fraction(7, 4))
tinto.theory.erdos_renyi.integrals(m, p, k=1)[source]#

The two double integrals of the \(G(n, p)\) second factorial moment.

For a pair of nodes, m other nodes can be neighbors of either; the integrals average the probability that both are peaks over their labels, for distinct colors (\(I_{dist}\)) and for the same color without an edge between them (\(I_{same}\)). They also serve the same-side pairs of bipartite.

Parameters:
  • m (int) – Number of other nodes.

  • p (float) – Edge probability.

  • k (int, default=1) – Number of colors.

Returns:

(I_dist, I_same), with I_dist = 0 when k = 1.

Return type:

tuple of float

tinto.theory.erdos_renyi.limit_law(p, k=1, smax=60)[source]#

Limit law of the number of peaks on \(G(n, p)\) at fixed p, as \(n \to \infty\).

Monochrome, \(S_\infty = \sum_{i \ge 0} B_i\) with independent \(B_i \sim \mathrm{Bernoulli}((1-p)^i)\) (the node of rank i from the top is a peak iff it has no edge to the i larger ones). With k colors, the color classes are independent \(G(n/k, p)\): the law is the k-fold convolution.

Parameters:
  • p (float) – Edge probability, 0 < p <= 1.

  • k (int, default=1) – Number of colors.

  • smax (int, default=60) – Largest value kept; the mass above is dropped.

Returns:

\(P(S_\infty = s)\) for s = 0, ..., smax.

Return type:

ndarray, shape (smax + 1,)

Examples

With p = 1 there is one peak per color class:

>>> limit_law(1.0, 2, smax=3).tolist()
[0.0, 0.0, 1.0, 0.0]
tinto.theory.erdos_renyi.mean(n, p, k=1)[source]#

Mean stabilization time on \(G(n, p)\) under k colors.

The node of rank r from the top is a peak iff none of the r - 1 larger nodes is a same-colored neighbor, which has probability \((1 - p/k)^{r-1}\); summing over the ranks, \(\mathbb E S = (k/p)(1 - (1 - p/k)^n)\).

Parameters:
  • n (int) – Number of nodes.

  • p (float) – Edge probability, 0 < p <= 1.

  • k (int, default=1) – Number of colors.

Return type:

float

Examples

>>> round(mean(200, 0.1), 6)
190.0
tinto.theory.erdos_renyi.variance(n, p, k=1)[source]#

Variance of the stabilization time on \(G(n, p)\) under k colors.

\(\mathbb E S(S-1) = n(n-1)(I_{dist} + (1-p) I_{same})\) with the integrals of integrals() at m = n - 2 (a same-colored pair can only be two peaks when it is not an edge), then \(\mathrm{Var}\, S = \mathbb E S(S-1) + \mathbb E S - (\mathbb E S)^2\).

Parameters:
  • n (int) – Number of nodes, n >= 2.

  • p (float) – Edge probability, 0 < p <= 1.

  • k (int, default=1) – Number of colors.

Return type:

float

Examples

>>> round(variance(200, 0.1), 4)
4.7368
>>> round(variance(200, 0.1, 3), 6)
14.176553