dit.example_dists

A selection of generic distributions which could be useful.

Functions

And

[0] and [1] = [2]

ImperfectRdn

Like Rdn() with a small off-term.

Or

[0] or [1] = [2]

Rdn

A distribution with redundant information.

RdnXor

Concatenation of Rdn() and Xor().

Subtle

The Subtle distribution.

Unq

A distribution with unique information.

Xor

A distribution with synergistic information, [0] xor [1] = [2]

bach

The empirical joint distribution of the notes in Bach's chorales.

bernoulli

The Bernoulli distribution:

binomial

The binomial distribution:

blood_types

The common-cause joint distribution of human blood group systems by continent.

car

The empirical joint distribution of the UCI Car Evaluation dataset.

chsh_value

The Clauser-Horne-Shimony-Holt value of a bipartite binary box [CHSH69].

congress

The empirical joint distribution of the 1984 congressional voting records.

corelli

The empirical joint distribution of the notes in Corelli's trio sonatas.

correlated_pr_box

The correlated non-local box eps * PR + (1 - eps) * C, where C is the fully correlated box uniform on a xor b = 0 [BS09].

erasure_channel

A fair bit passed through a binary erasure channel.

genetic_code

The joint distribution of codons and the amino acids they code for.

giant_bit

Return a 'giant bit' distribution of size n and alphabet size k.

hypergeometric

The hypergeometric distribution:

iid_sum

Returns a distribution relating n iid uniform draws to their sum.

is_nonsignalling

Test whether a box is non-signalling [BLM+05]: for every party i, the joint distribution of the other parties' outputs, conditioned on all inputs, does not depend on the input x_i.

jeff

The JEFF distribution, where the conditional probability \(p(y|X)\) is linear in X.

multinomial

The multinomial distribution:

n_mod_m

Constructs a generalized form of the XOR distribution, having an arbitrary alphabet and arbitrary word size.

noisy_copies

n noisy copies of a latent fair bit: the n-variable doubly symmetric binary source.

penguins

The empirical joint distribution of the Palmer Penguins dataset.

pr_box

The Popescu-Rohrlich box, or PR box, is the canonical non-signalling, non-local probability distribution used in the study of superquantum correlations [PR94b].

pr_box_d

The d-output generalization of the PR box [BLM+05].

reverse_erasure_channel

The binary erasure channel run backwards.

student

The empirical joint distribution of the UCI Student Performance dataset.

summed_dice

Two die X and Y are summed to form Z in the following way:

symmetric_common_information_witness

An exchangeable witness separating the entire common-information ordering.

task_assignment

n distinct tasks dealt uniformly at random from k.

titanic

The empirical joint distribution of the Titanic passenger dataset.

tripartite_pr_box

The tripartite extension of the PR box, uniform on outcomes with a xor b xor c = x * y * z [BP05].

uniform

The discrete uniform distribution:

Reference

And(k=2)[source]

[0] and [1] = [2]

ImperfectRdn()[source]

Like Rdn() with a small off-term.

Or(k=2)[source]

[0] or [1] = [2]

Rdn()[source]

A distribution with redundant information.

RdnXor()[source]

Concatenation of Rdn() and Xor(). Distribution has both redundant and synergistic information.

Subtle()[source]

The Subtle distribution.

Unq()[source]

A distribution with unique information.

Xor()[source]

A distribution with synergistic information, [0] xor [1] = [2]

bach(limit=None)[source]

The empirical joint distribution of the notes in Bach’s chorales.

The four random variables are the four voices, in order: Soprano, Alto, Tenor, and Bass. Each takes one of the twelve pitch classes (C, C#, …, B) or R (rest).

The distribution is estimated over the four-part Major-mode chorales in the music21 core corpus (351 of the 371 Riemenschneider chorales), each transposed to C major and sampled on the grid of its smallest note value. The O-information of the result is negative: the chorales are synergy-dominated.

Parameters:

limit (int, None) – If given, only the first limit usable chorales are included. This is primarily useful for keeping tests fast; the default (None) uses all of them.

Returns:

d – The empirical joint distribution over (Soprano, Alto, Tenor, Bass).

Return type:

Distribution

Raises:

ImportError – If music21 is not installed.

bernoulli(p)[source]

The Bernoulli distribution:

x P(x) 0 1-p 1 p

Parameters:

p (float) – A float between 0 and 1, the probability of a 1.

Returns:

d – The Bernoulli distribution with probability p.

Return type:

Distribution

Raises:

ValueError – Raised if not 0 <= p <= 1.

binomial(n, p)[source]

The binomial distribution:

\[f(k;n,p) = P(X = k) = nCk p^k (1-p)^(n-k)\]

describes the number of successes in n i.i.d. draws each with probability of success p.

Parameters:
  • n (int) – A positive integer, the number of trials.

  • p (float) – A float between 0 and 1, the probabilty of success of a trial.

Returns:

d – The binomial distribution describes the number of successes in n trials (identically and independently distributed draws) each with probability of success p.

Return type:

Distribution

Raises:

ValueError – Raised if n is not a positive integer. Raised if not 0 <= p <= 1.

blood_types()[source]

The common-cause joint distribution of human blood group systems by continent.

The seven random variables are, in order:

  • Region – continent: Africa, Americas, Asia, Europe, Oceania (weighted by population).

  • ABO – O, A, B, AB.

  • Rh – + or - (the D antigen).

  • Kell – K+ or K-.

  • Duffy – Fy(a+b-), Fy(a-b+), Fy(a+b+), Fy(a-b-).

  • Kidd – Jk(a+b-), Jk(a-b+), Jk(a+b+).

  • MNS – one of nine M#N#S#s# phenotypes.

Each antigen system is conditionally independent of the others given Region. The global (continent-agnostic) blood type distribution is the Region marginal; a single continent is recovered by conditioning on Region.

Returns:

d – The joint distribution over (Region, ABO, Rh, Kell, Duffy, Kidd, MNS).

Return type:

Distribution

car()[source]

The empirical joint distribution of the UCI Car Evaluation dataset.

The four random variables are, in order:

  • Buying – buying price: VeryHigh, High, Medium, Low.

  • Maintenance – maintenance cost: VeryHigh, High, Medium, Low.

  • Safety – estimated safety: Low, Medium, High.

  • Decision – overall evaluation: Unacceptable, Acceptable, Good, VeryGood.

The distribution is estimated from all 1728 rows of car.data; only these four of the seven columns are used (the two omitted inputs, number of doors and passenger capacity, are marginalized out). Because the evaluation is a deterministic hierarchical function of the inputs, only 82 of the 4 x 4 x 3 x 4 = 192 combinations occur – in particular, Low safety never yields a Good or VeryGood decision. The source data is fetched from the UCI Machine Learning Repository at call time.

Returns:

d – The empirical joint distribution over (Buying, Maintenance, Safety, Decision).

Return type:

Distribution

Raises:

RuntimeError – If the source data cannot be fetched.

chsh_value(dist, inputs=(0, 1), outputs=(2, 3))[source]

The Clauser-Horne-Shimony-Holt value of a bipartite binary box [CHSH69]. With correlators E(x, y) = sum_{a, b} (-1)^(a xor b) p(a, b | x, y), it is

max | E(x, y) + E(x, y’) + E(x’, y) - E(x’, y’) |

over the choice of which input pair is negated. A box is local iff its CHSH value is at most 2; quantum boxes satisfy CHSH <= 2 sqrt(2).

Parameters:
  • dist (Distribution) – A joint distribution over the inputs and outputs.

  • inputs (sequence of two rvs) – The input variables (X, Y), by index or name. Defaults to (0, 1).

  • outputs (sequence of two rvs) – The output variables (A, B), by index or name. Defaults to (2, 3).

Returns:

chsh – The CHSH value, in [0, 4].

Return type:

float

Raises:

ditException – If any variable is not binary or any input pair has zero probability.

congress()[source]

The empirical joint distribution of the 1984 congressional voting records.

The seventeen random variables are, in order:

  • Party – party affiliation: D (democrat) or R (republican).

  • one variable per key vote (sixteen in all), each taking yea, nay, or ? (present / abstained / did not vote). In file order these are HandicappedInfants, WaterProject, BudgetResolution, PhysicianFeeFreeze, ElSalvadorAid, ReligiousGroupsInSchools, AntiSatelliteBan, AidToContras, MXMissile, Immigration, Synfuels, EducationSpending, SuperfundRightToSue, Crime, DutyFreeExports, and SouthAfricaExportAct.

The distribution is estimated from all 435 House members (267 democrats, 168 republicans). The source data is fetched from the UCI Machine Learning Repository at call time.

Returns:

d – The empirical joint distribution over (Party, <16 votes>).

Return type:

Distribution

Raises:

RuntimeError – If the source data cannot be fetched.

corelli(limit=None)[source]

The empirical joint distribution of the notes in Corelli’s trio sonatas.

The four random variables are the four instrumental lines, in order: Violin1, Violin2, Violone, and Organo. Each takes one of the twelve pitch classes (C, C#, …, B) or R (rest).

The distribution is estimated over the four-part Major-mode movements of the Op. 1, Op. 3, and Op. 4 sonatas, each transposed to C major and sampled on the grid of its smallest note value. The source scores are fetched from the CCARH-derived Humdrum **kern mirror at call time. The O-information of the result is positive: the ensemble is redundancy-dominated.

Parameters:

limit (int, None) – If given, only the first limit usable movements are included. This is primarily useful for keeping tests fast; the default (None) uses all of them.

Returns:

d – The empirical joint distribution over (Violin1, Violin2, Violone, Organo).

Return type:

Distribution

Raises:
correlated_pr_box(eps, name=True)[source]

The correlated non-local box eps * PR + (1 - eps) * C, where C is the fully correlated box uniform on a xor b = 0 [BS09]. Its CHSH value is 2 * (1 + eps); it is the family on which the known non-locality distillation protocols operate. Inputs are uniformly distributed.

Parameters:
  • eps (float, 0 <= eps <= 1) – Weight of the PR box.

  • name (bool) – Whether to set rv names (XYAB) or not. Defaults to True.

Returns:

box – The correlated non-local box distribution.

Return type:

Distribution

erasure_channel(p)[source]

A fair bit passed through a binary erasure channel.

The input \(X\) is a fair bit and the output \(Y\) equals \(X\) with probability \(1 - p\), and is the erasure symbol e otherwise. Its Wyner common information is [Cuf13]

\[\begin{split}\operatorname{C}[X : Y] = \begin{cases} 1 & p < 1/2, \\ h(p) & p \ge 1/2, \end{cases}\end{split}\]

where \(h\) is the binary entropy, while \(\I{X : Y} = 1 - p\) and the necessary conditional entropy is \(\H{Y \dagger X} = h(p)\).

Parameters:

p (float) – The erasure probability, in \([0, 1]\).

Returns:

d – The joint distribution of input and output.

Return type:

Distribution

genetic_code(rna=False, bases=False)[source]

The joint distribution of codons and the amino acids they code for.

Codons are drawn uniformly from the 64 nucleotide triplets, and each codon is mapped to its amino acid (or Stop) by the standard nuclear genetic code. The map is deterministic, so conditioning on the full codon (or on all three bases) leaves no residual amino-acid uncertainty, and the mutual information equals the amino-acid entropy (\(H(\mathrm{AminoAcid}) \approx 4.22\) bits).

By default the two random variables are, in order:

  • Codon – one of the 64 triplets (e.g. ATG or AUG).

  • AminoAcid – one of 20 amino acids (three-letter names) or Stop.

With bases=True the codon is expanded into its three nucleotide positions, yielding:

  • Base1, Base2, Base3 – the first, second, and third bases.

  • AminoAcid – as above.

The per-base form makes the classic “wobble” asymmetry visible: the third position carries far less information about the amino acid than the first two.

Parameters:
  • rna (bool) – If False (default), codons use the DNA alphabet {T, C, A, G}. If True, thymine is replaced by uracil and codons use the RNA alphabet {U, C, A, G}.

  • bases (bool) – If False (default), return the joint over (Codon, AminoAcid). If True, expand each codon into three base random variables and return the joint over (Base1, Base2, Base3, AminoAcid).

Returns:

d – The joint distribution over (Codon, AminoAcid), or over (Base1, Base2, Base3, AminoAcid) when bases=True.

Return type:

Distribution

giant_bit(n=3, k=2)[source]

Return a ‘giant bit’ distribution of size n and alphabet size k.

Parameters:
  • n (int) – The number of identical bits. Defaults to 3.

  • k (int) – The number of states for each bit. Defaults to 2.

Returns:

gb – The giant bit distribution.

Return type:

Distribution

hypergeometric(N, K, n)[source]

The hypergeometric distribution:

\[f(k;N,K,n) = P(X = k) = KCk * (N-K)C(n-k) / NCn\]
Parameters:
  • N (int) – A positive integer, the size of the population.

  • K (int) – The number of successes in the population.

  • n (int) – The number of draws to make (without replacement) from the population.

Returns:

d – The hypergeometric distribution of a population of size N with K successes in the population, and n draws are made, without replacement, from that population. P(k) is the probability of k successes among the n draws.

Return type:

Distribution

Raises:

ValueError – Raised if N, K, or n are not positive integers.

iid_sum(n, k=2)[source]

Returns a distribution relating n iid uniform draws to their sum.

is_nonsignalling(dist, inputs, outputs, atol=1e-09)[source]

Test whether a box is non-signalling [BLM+05]: for every party i, the joint distribution of the other parties’ outputs, conditioned on all inputs, does not depend on the input x_i. Party i holds inputs[i] and outputs[i].

Parameters:
  • dist (Distribution) – A joint distribution over the inputs and outputs.

  • inputs (sequence of rvs) – The input variable of each party, by index or name.

  • outputs (sequence of rvs) – The output variable of each party, by index or name.

  • atol (float) – Absolute tolerance for comparing conditional probabilities.

Returns:

nonsignalling – Whether the box is non-signalling.

Return type:

bool

Raises:

ditException – If inputs and outputs differ in length, or any input configuration has zero probability.

jeff(n)[source]

The JEFF distribution, where the conditional probability \(p(y|X)\) is linear in X.

Parameters:

n (int) – The number of inputs

Returns:

dist – The JEFF distribution with n inputs.

Return type:

Distribution

multinomial(n, ps)[source]

The multinomial distribution:

\[f(x_1, \ldots, x_k; n, p_1, \ldots, p_k) = \frac{n!}{x_1! \cdots x_k!} p_1^{x_1} \cdots p_k^{x_k}\]

describes the counts of outcomes in n i.i.d. draws from a categorical distribution with category probabilities ps.

Parameters:
  • n (int) – A non-negative integer, the number of trials.

  • ps (sequence of float) – The probabilities of each category. Must sum to 1 and contain at least two elements.

Returns:

d – The multinomial distribution over count-vector outcomes. Each outcome is a tuple (x_1, ..., x_k) of non-negative integers summing to n.

Return type:

Distribution

Raises:

ValueError – Raised if n is not a non-negative integer. Raised if any element of ps is not a valid probability. Raised if ps does not sum to 1. Raised if ps has fewer than 2 elements.

n_mod_m(n, m)[source]

Constructs a generalized form of the XOR distribution, having an arbitrary alphabet and arbitrary word size.

Parameters:
  • n (int > 0) – The length of the words.

  • m (int > 0) – The size of the alphabet.

Returns:

d – The generalized XOR distribution of size n over alphabet m.

Return type:

Distribution

Raises:

ValueError – Raised if n or m are not positive integers.

noisy_copies(q, n=None)[source]

n noisy copies of a latent fair bit: the n-variable doubly symmetric binary source.

A hidden fair bit \(Z \sim \operatorname{U}\{0, 1\}\) is observed through n independent binary symmetric channels, \(X_i = Z \oplus N_i\) with \(N_i \sim \operatorname{Bernoulli}(q)\), and \(Z\) is marginalized out. The result is exchangeable and depends only on the Hamming weight k of an outcome,

\[p_k = \tfrac{1}{2}\left( q^k (1 - q)^{n - k} + q^{n - k} (1 - q)^k \right).\]

It has no shared deterministic structure, so its Gacs-Korner common information is zero, and no private randomness, so its minimal sufficient statistic common information equals its entropy; between those extremes it strictly separates the CAEKL, dual total correlation, Wyner [Wyn75b], exact [KLEG14], and functional common informations. For n = 2 it is Wyner’s doubly symmetric binary source, with crossover \(2 q (1 - q)\). Its higher-order common information is \(1 - h\left(\tfrac{1}{2}(1 - (1 - 2q)^{2^{n-1}})\right)\), where \(h\) is the binary entropy [Ostergaard24].

Each copy may instead have its own crossover \(q_i\), in which case the copies are no longer exchangeable.

Parameters:
  • q (float or sequence of floats) – The binary symmetric channel crossover \(P(X_i \ne Z)\), in \([0, 1/2]\), or one crossover per copy.

  • n (int, None) – The number of noisy copies. Defaults to 3, or to the number of crossovers when q is a sequence.

Returns:

d – The n-variable doubly symmetric binary source, over n binary variables with \(2^n\) outcomes.

Return type:

Distribution

Raises:

ValueError – Raised if n differs from the number of crossovers.

penguins()[source]

The empirical joint distribution of the Palmer Penguins dataset.

The three random variables are, in order:

  • Species – Adelie, Chinstrap, or Gentoo.

  • Island – Biscoe, Dream, or Torgersen.

  • Sex – M or F.

The distribution is estimated from the 333 penguins with a recorded sex (11 of the 344 records have no recorded sex and are dropped). Only the three categorical columns are used; the four continuous morphometric measurements are ignored. The source data is fetched from mwaskom/seaborn-data at call time.

Returns:

d – The empirical joint distribution over (Species, Island, Sex).

Return type:

Distribution

Raises:

RuntimeError – If the source data cannot be fetched.

pr_box(eta=1, name=True)[source]

The Popescu-Rohrlich box, or PR box, is the canonical non-signalling, non-local probability distribution used in the study of superquantum correlations [PR94b]. It has two space-like separated inputs, X and Y, and two associated outputs, A and B.

eta is the noise level of this correlation. For 0 <= eta <= 1/2 the box can be realized classically. For 1/2 < eta <= 1/sqrt(2) the box can be realized quantum-mechanically.

Parameters:
  • eta (float, 0 <= eta <= 1) – The noise level of the box. Defaults to 1.

  • name (bool) – Whether to set rv names or not. Defaults to True.

Returns:

pr – The PR box distribution.

Return type:

Distribution

pr_box_d(d, eta=1, name=True)[source]

The d-output generalization of the PR box [BLM+05]. Inputs X and Y are binary and outputs A and B take values in {0, …, d-1}; the ideal box is uniform on outcomes with (b - a) = x * y (mod d), and every non-local vertex of the two-input non-signalling polytope is equivalent to one of these under reversible local operations. Inputs are uniformly distributed.

Parameters:
  • d (int >= 2) – The size of each output alphabet.

  • eta (float, 0 <= eta <= 1) – Mixing weight of the ideal box against uniform noise. Defaults to 1.

  • name (bool) – Whether to set rv names (XYAB) or not. Defaults to True.

Returns:

box – The d-output PR box distribution.

Return type:

Distribution

reverse_erasure_channel(p)[source]

The binary erasure channel run backwards.

The input \(X\) is the erasure symbol e with probability \(p\) and otherwise a fair bit; the output \(Y\) copies a bit and replaces e with a fair coin flip [Cuf13]. It is erasure_channel() with input and output exchanged.

Parameters:

p (float) – The erasure probability, in \([0, 1]\).

Returns:

d – The joint distribution of input and output.

Return type:

Distribution

student()[source]

The empirical joint distribution of the UCI Student Performance dataset.

The four random variables are, in order:

  • Internet – home internet access: Yes or No.

  • Romantic – in a romantic relationship: Yes or No.

  • WeekendAlcohol – weekend alcohol consumption: VeryLow, Low, Medium, High, or VeryHigh.

  • Grade – Pass if the final grade G3 >= 10 (on the 0-20 scale), else Fail.

The distribution is estimated from all 649 students in the Portuguese course file (student-por.csv); all forty 2 x 2 x 5 x 2 combinations occur. Only these four of the thirty-three columns are used. The source archive is fetched from the UCI Machine Learning Repository at call time.

Returns:

d – The empirical joint distribution over (Internet, Romantic, WeekendAlcohol, Grade).

Return type:

Distribution

Raises:

RuntimeError – If the source data cannot be fetched.

summed_dice(a=1, b=1)[source]

Two die X and Y are summed to form Z in the following way:

\[Z = X + b * Y\]

X and Y are distributed as:

\[P(X=i, Y=j) = a / 36 + (1 - a) * delta_{ij} / 6\]
Parameters:
  • a (float) – Specifies how independent X and Y are. a=0 means X and Y are perfectly correlated. a=1 means X and Y are independent.

  • b (integer) – An integer specifying how to add X and Y.

Returns:

d – The joint distribution for \(P(X, Y, Z)\).

Return type:

distribution

References

Malte Harder, Christoph Salge, Daniel Polani

A Bivariate Measure of Redundant Information

symmetric_common_information_witness(n=3, q=None)[source]

An exchangeable witness separating the entire common-information ordering.

Returns the independent product of a shared giant bit, n noisy copies of a latent fair bit (noisy_copies()), and n private fair bits, so that each variable is \(X_i = (G, Z \oplus N_i, P_i)\) over a common eight-symbol alphabet. Every rung of the ordering

\[0 < \operatorname{K} < \operatorname{J} < \operatorname{B} < \operatorname{C} < \operatorname{G} < \operatorname{F} < \operatorname{M} < \operatorname{H}\]

is strict [JC17]. For n = 2 the CAEKL mutual information and dual total correlation coincide with the mutual information, so the chain has one fewer distinct rung.

Parameters:
  • n (int) – The number of variables; at least 2. Defaults to 3.

  • q (float, optional) – The binary symmetric channel crossover for the noisy workhorse. When None (default) a value tuned per n (for n up to 5) is used, falling back to 0.15 otherwise.

Returns:

d – The exchangeable witness, over n variables with an eight-symbol alphabet and \(2^{2n+1}\) outcomes.

Return type:

Distribution

task_assignment(k, n=2)[source]

n distinct tasks dealt uniformly at random from k.

The distribution is uniform over n-tuples of distinct values from range(k) [CPC10]. For n = 2 this is the “scatter” channel of [Cuf13], uniform over \(x \ne y\), with

\[\I{X : Y} = \log_2 \frac{k}{k - 1}, \qquad \H{Y \dagger X} = \log_2 (k - 1), \qquad \operatorname{C}[X : Y] = 2 - \log_2 \frac{\lceil k \rceil_2}{\lceil k \rceil_2 - 1},\]

where \(\lceil k \rceil_2\) is k rounded up to an even number. For n = 3 and k divisible by three, the Wyner common information is

\[\operatorname{C}[X : Y : Z] = 3 \log_2 3 - \log_2 \frac{k}{k - 1} - \log_2 \frac{k}{k - 2}.\]
Parameters:
  • k (int) – The number of tasks.

  • n (int) – The number of variables, each assigned a different task. Defaults to 2.

Returns:

d – The uniform distribution over the \(k! / (k - n)!\) assignments.

Return type:

Distribution

titanic()[source]

The empirical joint distribution of the Titanic passenger dataset.

The four random variables are, in order:

  • Class – passenger class: 1st, 2nd, 3rd.

  • Sex – M or F.

  • Age – Child if age < 16, else Adult.

  • Survived – Yes or No.

The distribution is estimated from the 714 passengers with a recorded age (177 of the 891 records have no age and are dropped). The source data is fetched from datasciencedojo/datasets at call time.

Returns:

d – The empirical joint distribution over (Class, Sex, Age, Survived).

Return type:

Distribution

Raises:

RuntimeError – If the source data cannot be fetched.

tripartite_pr_box(eta=1, name=True)[source]

The tripartite extension of the PR box, uniform on outcomes with a xor b xor c = x * y * z [BP05]. It has three binary inputs X, Y, Z (uniformly distributed) and three binary outputs A, B, C.

Parameters:
  • eta (float, 0 <= eta <= 1) – Mixing weight of the ideal box against uniform noise. Defaults to 1.

  • name (bool) – Whether to set rv names (XYZABC) or not. Defaults to True.

Returns:

box – The tripartite PR box distribution.

Return type:

Distribution

uniform(a, b=None)[source]

The discrete uniform distribution:

\[P(x in a..b-1) = 1/(b-a)\]
Parameters:
  • a (int) – The lower bound of the uniform distribution. If b is None, then a is taken to be the length of the uniform with a lower bound of 0.

  • b (int, None) – The upper bound of the uniform distribution. If None, a uniform distribution over 0 .. a is returned.

Returns:

d – The uniform distribution from a to b-1.

Return type:

Distribution

Raises:

ValueError – Raised if b is not an integer or None, or if a is not an integer and positive if b is None or larger than b if be is not None.