Oracle#

Peak oracle: samples of the stabilization time drawn without running the dynamics.

The reduction lemma of the exact stabilization-time paper reads as follows. Run the conflict-guard rule (a node sharing its color with a neighbor recolors itself with a color absent from its neighborhood) under the random central daemon, from a uniform random coloring with k colors and a palette of at least Delta + 1 colors. Then the number of moves until stabilization is T = n - S, where S counts the peaks of a uniform random labeling of the nodes: a node is a peak when its label exceeds the labels of all its neighbors that share its initial color.

Sampling T therefore needs no dynamics. Draw the colors and the labels, then count the nodes that are beaten by a same-colored neighbor with a larger label. The samplers below return samples of T (the number of beaten nodes), for a fixed graph or for a random graph drawn afresh at each trial. The peak statistic is defined for every k; the palette condition only matters for the dynamics, which the oracle does not run.

shuffled() gives the same law as the random central daemon for this rule: a disabled node never becomes enabled again, so each node moves at most once, at its first visit, exactly when a same-colored neighbor is still unvisited.

The samplers run in parallel over a fixed number of chunks, each seeded with seed + chunk, so the samples depend on the seed only, not on the number of threads. Without a seed, the base seed is drawn from the generator that set_seed() controls.

This module belongs to the simulation side of tinto: it imports neither tinto.exact nor tinto.theory, the two other sources of the companion checks.

tinto.oracle.CHUNKS = 64#

Number of independently seeded chunks a sampling run is split into.

tinto.oracle.count_peaks(graph, colors, labels)[source]#

Number of peaks of a colored and labeled graph.

Parameters:
  • graph (Graph) – Undirected graph (each edge stored in both directions).

  • colors (ndarray of int, shape (n,)) – Initial color of each node.

  • labels (ndarray, shape (n,)) – Label of each node; labels are pairwise distinct.

Returns:

Number of nodes whose label exceeds the labels of all their same-colored neighbors.

Return type:

int

Examples

On a monochrome path 0 - 1 - 2, only the node with the largest label among its neighbors survives:

>>> from tinto.graphs import line
>>> count_peaks(line(3), np.zeros(3, dtype=np.int64), np.array([0.1, 0.5, 0.3]))
1

Two colors split the path into a single edge and an isolated node:

>>> count_peaks(line(3), np.array([0, 0, 1]), np.array([0.1, 0.5, 0.3]))
2
tinto.oracle.sample_bipartite(n1, n2, p, k=1, trials=1000, seed=None)[source]#

Sample the stabilization time on \(G(n_1, n_2, p)\), a fresh graph per trial.

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

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

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

  • k (int, default=1) – Number of colors of the uniform random initial coloring.

  • trials (int, default=1000) – Number of samples.

  • seed (int or None, default=``None``) – Base seed (see sample_graph()).

Returns:

Samples of T = n1 + n2 - S.

Return type:

ndarray of int64, shape (trials,)

Examples

On the monochrome star \(K_{1, 3}\), the three leaves are beaten when the center has the largest label; otherwise the center is beaten, with the leaves below it, so T takes the values 1, 2 and 3:

>>> sorted(set(sample_bipartite(1, 3, 1.0, trials=50, seed=0).tolist()))
[1, 2, 3]
tinto.oracle.sample_cayley(n, k=1, trials=1000, seed=None)[source]#

Sample the stabilization time on a uniform labeled tree, a fresh tree per trial.

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

  • k (int, default=1) – Number of colors of the uniform random initial coloring.

  • trials (int, default=1000) – Number of samples.

  • seed (int or None, default=``None``) – Base seed (see sample_graph()).

Returns:

Samples of T = n - S.

Return type:

ndarray of int64, shape (trials,)

Examples

A tree on two nodes is a single edge:

>>> sample_cayley(2, trials=5, seed=0).tolist()
[1, 1, 1, 1, 1]
tinto.oracle.sample_erdos_renyi(n, p, k=1, trials=1000, seed=None)[source]#

Sample the stabilization time on \(G(n, p)\), a fresh graph per trial.

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

  • p (float) – Edge probability.

  • k (int, default=1) – Number of colors of the uniform random initial coloring.

  • trials (int, default=1000) – Number of samples.

  • seed (int or None, default=``None``) – Base seed (see sample_graph()).

Returns:

Samples of T = n - S over the joint law of the graph, the coloring and the labeling.

Return type:

ndarray of int64, shape (trials,)

Examples

With p = 1 the graph is complete:

>>> sample_erdos_renyi(6, 1.0, trials=5, seed=0).tolist()
[5, 5, 5, 5, 5]
tinto.oracle.sample_graph(graph, k=1, trials=1000, seed=None)[source]#

Sample the stabilization time on a fixed graph.

Parameters:
  • graph (Graph) – Undirected graph.

  • k (int, default=1) – Number of colors of the uniform random initial coloring.

  • trials (int, default=1000) – Number of samples.

  • seed (int or None, default=``None``) – Base seed of the chunks; None draws it from the generator that set_seed() controls.

Returns:

Samples of T = n - S.

Return type:

ndarray of int64, shape (trials,)

Examples

On a monochrome complete graph, only the largest label is a peak:

>>> from tinto.graphs import adja_to_graph
>>> K5 = adja_to_graph(~np.eye(5, dtype=np.bool_))
>>> sample_graph(K5, trials=10, seed=0).tolist()
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4]

The samples depend on the seed only:

>>> from tinto.graphs import line
>>> a = sample_graph(line(20), k=3, trials=200, seed=7)
>>> bool((a == sample_graph(line(20), k=3, trials=200, seed=7)).all())
True