Exact#
Exact enumeration of the peak statistic on small graphs.
The third source of the companion checks, next to the closed forms of
tinto.theory and the Monte Carlo of tinto.oracle. Everything
here is exact integer counting, no sampling: all n! labelings, all
k^n colorings, all labeled trees or all graphs on n nodes. It is
meant for n <= 7.
The colorings are enumerated up to a permutation of the colors, which leaves the peak count unchanged: one restricted growth string per class, weighted by the size of the class.
Independence: this module imports from tinto only tinto.graphs, and
counts the peaks with its own code (see tests/test_independence.py).
- tinto.exact.all_graphs(n)[source]#
All labeled graphs on n nodes.
Examples
>>> sorted(len(g.ind) // 2 for g in all_graphs(3)) [0, 1, 1, 1, 2, 2, 2, 3]
- tinto.exact.all_trees(n)[source]#
All labeled trees on n nodes, by Prüfer decoding.
Examples
>>> trees = list(all_trees(4)) >>> len(trees), {len(t.ind) // 2 for t in trees} (16, {3})
- tinto.exact.colorings(n, k)[source]#
Colorings of n nodes with k colors, up to a permutation of the colors.
- Parameters:
- Yields:
tuple–(coloring, weight): the coloring uses the colors in order of first appearance (a restricted growth string), and weight is the number of colorings inrange(k)^nequivalent to it,k (k-1) ... (k-m+1)for m colors used.
Examples
>>> list(colorings(3, 2)) [((0, 0, 0), 2), ((0, 0, 1), 2), ((0, 1, 0), 2), ((0, 1, 1), 2)] >>> sum(w for _, w in colorings(4, 3)) == 3**4 True >>> list(colorings(0, 2)) []
- tinto.exact.factorial_moments(hist)[source]#
Exact \(E S\) and \(E S(S-1)\) from a histogram of the peak count.
- Parameters:
hist (
ndarrayofint) – Counts, as returned bypeaks_distribution().- Return type:
Examples
>>> factorial_moments(np.array([0, 4, 2, 0])) (Fraction(4, 3), Fraction(2, 3))
- tinto.exact.law_size(n, k=1)[source]#
Number of (labeling, coloring) pairs,
n! k^n.Examples
>>> law_size(4, 3) 1944
- tinto.exact.peaks_distribution(graph, k=1, split=None, labels=None)[source]#
Exact law of the peak count, by enumeration of labelings and colorings.
- Parameters:
graph (
Graph) – Undirected graph,n <= 7or so (n!labelings).k (
int, default=1) – Number of colors.split (
tupleorNone, default=``None``) – A pair of nodes(u, v): return two histograms, for the colorings where u and v share their color and for the others.labels (array_like or
None, default=``None``) – A fixed labeling (pairwise distinct values): enumerate the colorings only. On a uniform random labeled graph, such as a uniform labeled tree, the labeling can be fixed to the node indices without changing the law.
- Returns:
N[j]is the number of (labeling, coloring) pairs with exactly j peaks, out ofn! k^n(k^ncolorings with labels). With split, a pair of such arrays.- Return type:
ndarrayofint64, shape (n + 1,)
Examples
On the path with three nodes, monochrome, one peak in 4 labelings of 6:
>>> from tinto.graphs import line >>> peaks_distribution(line(3)).tolist() [0, 4, 2, 0]
A complete graph always has one peak per color class:
>>> from tinto.graphs import edges_to_graph >>> K3 = edges_to_graph(3, np.array([[0, 1], [0, 2], [1, 2]])) >>> peaks_distribution(K3, 2).tolist() [0, 12, 36, 0]
The path on two nodes, split by whether its ends share their color, and with the labeling fixed:
>>> [h.tolist() for h in peaks_distribution(line(2), 2, split=(0, 1))] [[0, 4, 0], [0, 0, 4]] >>> peaks_distribution(line(3), 2, labels=[0, 1, 2]).tolist() [0, 2, 4, 2] >>> peaks_distribution(line(3), 2, labels=[2, 1, 0]).tolist() [0, 2, 4, 2]