dit.example_dists
A selection of generic distributions which could be useful.
Functions
[0] and [1] = [2] |
|
Like Rdn() with a small off-term. |
|
[0] or [1] = [2] |
|
A distribution with redundant information. |
|
Concatenation of Rdn() and Xor(). |
|
The Subtle distribution. |
|
A distribution with unique information. |
|
A distribution with synergistic information, [0] xor [1] = [2] |
|
The empirical joint distribution of the notes in Bach's chorales. |
|
The Bernoulli distribution: |
|
The binomial distribution: |
|
The common-cause joint distribution of human blood group systems by continent. |
|
The empirical joint distribution of the UCI Car Evaluation dataset. |
|
The Clauser-Horne-Shimony-Holt value of a bipartite binary box [CHSH69]. |
|
The empirical joint distribution of the 1984 congressional voting records. |
|
The empirical joint distribution of the notes in Corelli's trio sonatas. |
|
The correlated non-local box eps * PR + (1 - eps) * C, where C is the fully correlated box uniform on a xor b = 0 [BS09]. |
|
A fair bit passed through a binary erasure channel. |
|
The joint distribution of codons and the amino acids they code for. |
|
Return a 'giant bit' distribution of size n and alphabet size k. |
|
The hypergeometric distribution: |
|
Returns a distribution relating n iid uniform draws to their sum. |
|
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. |
|
The JEFF distribution, where the conditional probability \(p(y|X)\) is linear in X. |
|
The multinomial distribution: |
|
Constructs a generalized form of the XOR distribution, having an arbitrary alphabet and arbitrary word size. |
|
|
|
The empirical joint distribution of the Palmer Penguins dataset. |
|
The Popescu-Rohrlich box, or PR box, is the canonical non-signalling, non-local probability distribution used in the study of superquantum correlations [PR94b]. |
|
The d-output generalization of the PR box [BLM+05]. |
|
The binary erasure channel run backwards. |
|
The empirical joint distribution of the UCI Student Performance dataset. |
|
Two die X and Y are summed to form Z in the following way: |
|
An exchangeable witness separating the entire common-information ordering. |
|
|
|
The empirical joint distribution of the Titanic passenger dataset. |
|
The tripartite extension of the PR box, uniform on outcomes with a xor b xor c = x * y * z [BP05]. |
|
The discrete uniform distribution: |
Reference
- RdnXor()[source]
Concatenation of Rdn() and Xor(). Distribution has both redundant and synergistic information.
- 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, andBass. Each takes one of the twelve pitch classes (C,C#, …,B) orR(rest).The distribution is estimated over the four-part Major-mode chorales in the
music21core 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
limitusable 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:
- Raises:
ImportError – If
music21is 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:
- 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:
- 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:
- 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+orK-.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 nineM#N#S#s#phenotypes.
Each antigen system is conditionally independent of the others given
Region. The global (continent-agnostic) blood type distribution is theRegionmarginal; a single continent is recovered by conditioning onRegion.- Returns:
d – The joint distribution over
(Region, ABO, Rh, Kell, Duffy, Kidd, MNS).- Return type:
- 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 the4 x 4 x 3 x 4 = 192combinations occur – in particular,Lowsafety never yields aGoodorVeryGooddecision. 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:
- 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:
- 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) orR(republican).one variable per key vote (sixteen in all), each taking
yea,nay, or?(present / abstained / did not vote). In file order these areHandicappedInfants,WaterProject,BudgetResolution,PhysicianFeeFreeze,ElSalvadorAid,ReligiousGroupsInSchools,AntiSatelliteBan,AidToContras,MXMissile,Immigration,Synfuels,EducationSpending,SuperfundRightToSue,Crime,DutyFreeExports, andSouthAfricaExportAct.
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:
- 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, andOrgano. Each takes one of the twelve pitch classes (C,C#, …,B) orR(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
**kernmirror 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
limitusable 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:
- Raises:
ImportError – If
music21is not installed.RuntimeError – If the source data cannot be fetched.
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:
- Returns:
box – The correlated non-local box distribution.
- Return type:
- 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
eotherwise. 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:
- 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.ATGorAUG).AminoAcid– one of 20 amino acids (three-letter names) orStop.
With
bases=Truethe 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}. IfTrue, 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). IfTrue, 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)whenbases=True.- Return type:
- giant_bit(n=3, k=2)[source]
Return a ‘giant bit’ distribution of size n and alphabet size k.
- Parameters:
- Returns:
gb – The giant bit distribution.
- Return type:
- hypergeometric(N, K, n)[source]
The hypergeometric distribution:
\[f(k;N,K,n) = P(X = k) = KCk * (N-K)C(n-k) / NCn\]- Parameters:
- 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:
- Raises:
ValueError – Raised if N, K, or n are not positive integers.
- 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]andoutputs[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:
- 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:
- 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:
- 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:
- 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:
- Raises:
ValueError – Raised if n or m are not positive integers.
- noisy_copies(q, n=None)[source]
nnoisy copies of a latent fair bit: then-variable doubly symmetric binary source.A hidden fair bit \(Z \sim \operatorname{U}\{0, 1\}\) is observed through
nindependent 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 weightkof 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 = 2it 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:
- Returns:
d – The
n-variable doubly symmetric binary source, overnbinary variables with \(2^n\) outcomes.- Return type:
- Raises:
ValueError – Raised if
ndiffers 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, orGentoo.Island–Biscoe,Dream, orTorgersen.Sex–MorF.
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-dataat call time.- Returns:
d – The empirical joint distribution over
(Species, Island, Sex).- Return type:
- 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:
- Returns:
pr – The PR box distribution.
- Return type:
- 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:
- Returns:
box – The d-output PR box distribution.
- Return type:
- reverse_erasure_channel(p)[source]
The binary erasure channel run backwards.
The input \(X\) is the erasure symbol
ewith probability \(p\) and otherwise a fair bit; the output \(Y\) copies a bit and replacesewith a fair coin flip [Cuf13]. It iserasure_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:
- student()[source]
The empirical joint distribution of the UCI Student Performance dataset.
The four random variables are, in order:
Internet– home internet access:YesorNo.Romantic– in a romantic relationship:YesorNo.WeekendAlcohol– weekend alcohol consumption:VeryLow,Low,Medium,High, orVeryHigh.Grade–Passif the final gradeG3>= 10 (on the 0-20 scale), elseFail.
The distribution is estimated from all 649 students in the Portuguese course file (
student-por.csv); all forty2 x 2 x 5 x 2combinations 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:
- 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,
nnoisy copies of a latent fair bit (noisy_copies()), andnprivate 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 = 2the CAEKL mutual information and dual total correlation coincide with the mutual information, so the chain has one fewer distinct rung.- Parameters:
- Returns:
d – The exchangeable witness, over
nvariables with an eight-symbol alphabet and \(2^{2n+1}\) outcomes.- Return type:
- task_assignment(k, n=2)[source]
ndistinct tasks dealt uniformly at random fromk.The distribution is uniform over
n-tuples of distinct values fromrange(k)[CPC10]. Forn = 2this 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
krounded up to an even number. Forn = 3andkdivisible 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:
- Returns:
d – The uniform distribution over the \(k! / (k - n)!\) assignments.
- Return type:
- 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–MorF.Age–Childif age < 16, elseAdult.Survived–YesorNo.
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/datasetsat call time.- Returns:
d – The empirical joint distribution over
(Class, Sex, Age, Survived).- Return type:
- 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:
- Returns:
box – The tripartite PR box distribution.
- Return type:
- uniform(a, b=None)[source]
The discrete uniform distribution:
\[P(x in a..b-1) = 1/(b-a)\]- Parameters:
- Returns:
d – The uniform distribution from a to b-1.
- Return type:
- 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.