Bipartite graphs#

Bipartite \(G(n_1, n_2, p)\) graphs.

tinto.theory.bipartite.law(n1, n2, p)[source]#

Exact law of the number of peaks on the monochrome \(G(n_1, n_2, p)\).

Take the nodes in decreasing label order. Given the interleaving of the two sides in that order, a node is a peak iff it has no edge to the larger nodes of the other side, independently of the others: the conditional generating function is a product \(\prod_u (1 - q^{h_u} + q^{h_u} v)\), \(q = 1 - p\), \(h_u\) the number of larger nodes on the other side. The law averages it over the \(\binom{n_1 + n_2}{n_1}\) equally likely interleavings, here by dynamic programming over the prefixes.

Parameters:
  • n1 (int) – Sizes of the two sides.

  • n2 (int) – Sizes of the two sides.

  • p (float or Fraction) – Probability of an edge across the sides; a Fraction gives an exact law.

Returns:

\(P(S = j)\) for j = 0, ..., n1 + n2.

Return type:

list

Examples

One node on each side: one peak with an edge, two without.

>>> from fractions import Fraction
>>> [str(x) for x in law(1, 1, Fraction(1, 3))]
['0', '1/3', '2/3']
tinto.theory.bipartite.limit_mean(lam, p)[source]#

Limit of \(\mathbb E S\) on the monochrome \(G(\lambda n, (1-\lambda) n, p)\).

\[\lim_{n \to \infty} \mathbb E S = \frac{\lambda}{(1-\lambda) p} + \frac{1-\lambda}{\lambda p}.\]
Parameters:
  • lam (float) – Fraction of the nodes on the first side, 0 < lam < 1.

  • p (float) – Probability of an edge across the sides.

Return type:

float

Examples

>>> round(limit_mean(0.5, 0.25), 6)
8.0
tinto.theory.bipartite.mean(n1, n2, p, k=1)[source]#

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

A node of the first side is a peak iff none of the larger nodes of the other side is a same-colored neighbor; averaging over the interleaving of the two sides gives

\[\mathbb E S = \frac kp \left(\frac{n_1}{n_2+1}\left(1 - q^{n_2+1}\right) + \frac{n_2}{n_1+1}\left(1 - q^{n_1+1}\right)\right), \quad q = 1 - \frac pk.\]
Parameters:
  • n1 (int) – Size of the first side.

  • n2 (int) – Size of the second side.

  • p (float) – Probability of an edge across the sides, 0 < p <= 1.

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

Return type:

float

Examples

>>> round(mean(100, 100, 0.1), 6)
180.198493
tinto.theory.bipartite.variance(n1, n2, p, k=1)[source]#

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

Pairs on the same side are never adjacent and see the other side only: they use integrals() with m the size of the other side. Pairs across the sides are adjacent with probability p (then only distinct colors can make two peaks); their private neighborhoods are independent binomials, which gives two more double integrals.

Parameters:
  • n1 (int) – Size of the first side.

  • n2 (int) – Size of the second side.

  • p (float) – Probability of an edge across the sides, 0 < p <= 1.

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

Return type:

float

Examples

>>> round(variance(100, 100, 0.1), 4)
9.9943
>>> round(variance(100, 100, 0.1, 3), 6)
28.284911