dit.multivariate

Multivariate measures of information. Some are direct extensions of Shannon’s measures and others are more distantly related.

Classes

LogarithmicDecomposition

The logarithmic decomposition of a joint distribution.

Functions

alpha_synergistic_entropy

The \(\alpha\)-synergistic entropy [Var24a].

backbone_disclosure

Compute the full backbone decomposition of I(X; Y).

beta_common_information

Compute the beta-approximate common information (information-correlation function) of dist.

binding_information

Calculates the dual total correlation, also known as the binding information.

caekl_mutual_information

Calculates the Chan-AlBashabsheh-Ebrahimi-Kaced-Liu mutual information.

channel_synthesis_rate

The minimal communication rate for distributed channel synthesis [Cuf13].

cohesion

Computes the k-cohesion.

coinformation

Calculates the coinformation.

cross_caekl_mutual_information

Calculates the cross CAEKL mutual information, the cross-distribution generalization of the CAEKL mutual information.

cross_coinformation

Calculates the cross co-information, the cross-distribution generalization of the (multivariate) mutual information.

cross_dual_total_correlation

Calculates the cross dual total correlation, the cross-distribution generalization of the dual total correlation.

cross_total_correlation

Computes the cross total correlation, the cross-distribution generalization of the total correlation.

delta_k

Compute the Delta^k measure, a parameterized family of higher-order information measures.

deweese_caekl_mutual_information

Compute the DeWeese caekl mutual information.

deweese_coinformation

Compute the DeWeese coinformation.

deweese_dual_total_correlation

Compute the DeWeese dual total correlation.

deweese_total_correlation

Compute the DeWeese total correlation.

directed_kamath_common_information

Calculates the directed Kamath-Anantharam common information G(rvs -> about) = H(Phi^{about}_{rvs}), where Phi^{about}_{rvs} is the minimal sufficient statistic of rvs about about.

dual_total_correlation

Calculates the dual total correlation, also known as the binding information.

entanglement

Compute the entanglement.

entropy

Calculates the conditional joint entropy.

exact_common_information

Computes the exact common information, min H[V] where V renders all rvs independent.

exact_common_information_rate

An upper bound on the exact common information rate [KLEG14], from Yu and Tan [YT20a, YT20b]:

exact_common_information_rate_bounds

Lower and upper bounds on the exact common information rate \(\bar{G}[X : Y]\) [KLEG14].

frustration

Compute the order-k frustration: the divergence from the order-k maximum entropy distribution to the nearest model whose k-body interactions are unfrustrated.

functional_common_information

Compute the functional common information, F, of dist.

functional_variable

Return dist with the optimal functional common variable W appended.

gamma_k

Compute the Gamma^k measure, the entropic conjugate of the Delta^k measure.

generalized_dual_total_correlation

Compute the generalized dual total correlation.

gk_common_information

Calculates the Gacs-Korner common information K[X1:X2...] over the random variables in rvs.

higher_order_common_information

Compute the higher-order common information [Ostergaard24]:

independent_information

Compute the residual entropy.

information_of_formation

Compute the secret key cost [Win05], also known as the information of formation [RW03]: the minimal rate of secret key Alice and Bob need to produce XY by local operations and public communication, such that Eve could simulate the public transcript from Z.

interaction_information

Calculates the interaction information.

interactive_intrinsic_mutual_information

Compute a lower bound on the secret key agreement rate based on interactive communication.

intersection_entropy

Compute the intersection entropy H(X_1 u X_2 u .

intrinsic_caekl_mutual_information

Compute the intrinsic CAEKL mutual information.

intrinsic_dual_total_correlation

Compute the intrinsic dual total correlation.

intrinsic_mutual_information

Compute the intrinsic total correlation.

intrinsic_total_correlation

Compute the intrinsic total correlation.

iterated_discarding_skar

Compute a lower bound on the two-way secret key agreement rate achieved by iterated public discarding.

kamath_common_information

Calculates the Kamath-Anantharam dual common information U[X1:X2...] of the random variables in rvs.

kirkwood_mutual_information

Compute the Kirkwood mutual information: the Kullback-Leibler divergence from the joint distribution to its normalized generalized Kirkwood superposition approximation.

less_noisy_intrinsic_mutual_information

Compute the less-noisy intrinsic mutual information [PGR26]:

logarithmic_decomposition

Construct a LogarithmicDecomposition for the given distribution.

lower_intrinsic_mutual_information

Compute a trivial lower-bound on the secret key agreement rate.

max_synergistic_entropy

Compute the analytical upper bound on the mutual information that any SRV can have about a set of variables.

maxent_function

The Salamatian-Cohen-Médard Maximum Entropy Function:

minimal_intrinsic_CAEKL_mutual_information

Compute the minimal intrinsic CAEKL mutual information.

minimal_intrinsic_caekl_mutual_information

Compute the minimal intrinsic CAEKL mutual information.

minimal_intrinsic_dual_total_correlation

Compute the minimal intrinsic dual total correlation.

minimal_intrinsic_mutual_information

Compute the minimal intrinsic total correlation.

minimal_intrinsic_total_correlation

Compute the minimal intrinsic total correlation.

modified_synergistic_disclosure

Compute the modified synergistic disclosure for a single constraint alpha.

mss_common_information

Compute the minimal sufficient statistic common information, which is the entropy of the join of the minimal sufficent statistic of each variable about the others.

necessary_intrinsic_mutual_information

Compute a non-trivial lower bound on secret key agreement rate.

no_communication_skar

The rate at which X and Y can agree upon a key with Z eavesdropping, and no public communication.

o_information

Computes the O-information, defined as the total correlation minus the dual total correlation.

omniscience_rate

Compute the minimum rate of public communication for omniscience [CsiszarN04].

one_way_skar

Compute the secret key agreement rate constrained to one-way communication.

ouroboros_mutual_information

Compute the order-k ouroboros mutual information: the Kullback-Leibler divergence from the joint distribution to its normalized order-k ouroboros approximation.

pairwise_frustration

Compute the pairwise frustration, the order-2 frustration().

partial_entropy_spectrum

The partial entropy spectrum [Var24a]: the expected increments \(h^{syn}_{\alpha} - h^{syn}_{\alpha - 1}\) for \(\alpha = 1, \ldots, n\).

partial_information_spectrum

The partial spectrum of \(I[X : Y]\) for inputs \(X\) = rvs and target \(Y\) [Var24a]: the expectation over \(y\) of the input spectrum minus the spectrum of \(X \mid Y = y\).

partial_kullback_leibler_spectrum

The partial spectrum of \(D_{KL}[\text{posterior} \| \text{prior}]\) [Var24a]: the posterior expectation of the prior's local spectrum minus the posterior's.

partial_total_correlation_spectrum

The partial spectrum of the total correlation [Var24a], i.e. partial_kullback_leibler_spectrum() against the product of the marginals.

plot_maxent_function

Plot the spectral Maximum Entropy Function value \(H(\phi_X(X))\) as a function of the threshold \(t\).

quax_synergy

Compute the synergistic information I_syn(sources -> target) as defined by Quax, Har-Shemesh & Sloot (2017).

reduced_intrinsic_CAEKL_mutual_information

Compute the reduced intrinsic CAEKL mutual information.

reduced_intrinsic_caekl_mutual_information

Compute the reduced intrinsic CAEKL mutual information.

reduced_intrinsic_dual_total_correlation

Compute the reduced intrinsic dual total correlation.

reduced_intrinsic_mutual_information

Compute the reduced intrinsic total correlation.

reduced_intrinsic_total_correlation

Compute the reduced intrinsic total correlation.

relaxed_two_part_intrinsic_mutual_information

Compute the relaxed two-part intrinsic mutual information, an upper bound on the two-way secret key agreement rate that is never larger than the minimal intrinsic mutual information.

residual_entropy

Compute the residual entropy.

s_information

Computes the S-information, defined as the sum of the total correlation and the dual total correlation.

secrecy_capacity_skar

The rate at which X and Y can agree upon a key with Z eavesdropping, and no public communication.

secret_key_capacity

Compute the multiterminal secret key capacity of Csiszár and Narayan [CsiszarN04].

secret_key_cost

Compute the secret key cost [Win05], also known as the information of formation [RW03]: the minimal rate of secret key Alice and Bob need to produce XY by local operations and public communication, such that Eve could simulate the public transcript from Z.

self_synergy

Compute S_alpha(X -> X), the self-synergy of sources X.

stochastic_gk_common_information

Compute the stochastic Gacs-Korner common information of dist.

synergistic_disclosure

Compute S_alpha(X -> Y) for a single constraint set alpha.

synergistic_entropy

Compute the synergistic entropy H(X_1 + X_2 + .

tension_common_information

Compute the tension common information.

total_correlation

Computes the total correlation, also known as either the multi-information or the integration.

transmission

Compute the transmission of dist relative to a marginal model: the Kullback-Leibler divergence from the data to the maximum entropy distribution reconstructed from the marginals in structure.

tse_complexity

Calculates the TSE complexity.

two_part_intrinsic_CAEKL_mutual_information

Compute the two-part intrinsic CAEKL mutual information.

two_part_intrinsic_caekl_mutual_information

Compute the two-part intrinsic CAEKL mutual information.

two_part_intrinsic_dual_total_correlation

Compute the two-part intrinsic dual total correlation.

two_part_intrinsic_mutual_information

Compute the two-part intrinsic total correlation.

two_part_intrinsic_total_correlation

Compute the two-part intrinsic total correlation.

two_way_skar

Compute the two way secret key agreement rate.

union_entropy

Compute the union entropy H(X_1 t X_2 t .

unique_entropy

Compute the unique entropy H(X_1 X_2).

upper_intrinsic_caekl_mutual_information

Compute a trivial upper-bound on the secret key agreement rate.

upper_intrinsic_dual_total_correlation

Compute a trivial upper-bound on the secret key agreement rate.

upper_intrinsic_mutual_information

Compute a trivial upper-bound on the secret key agreement rate.

upper_intrinsic_total_correlation

Compute a trivial upper-bound on the secret key agreement rate.

variation_of_information

Compute the residual entropy.

wyner_common_information

Computes the wyner common information, min I[X:V] such that V renders all X_i independent.

Reference

class LogarithmicDecomposition(dist: Distribution)[source]

Bases: object

The logarithmic decomposition of a joint distribution.

Given a distribution over a joint outcome space Omega, this class computes:

  • The atom space Delta(Omega): all subsets of Omega with |S| >= 2.

  • The interior-loss measure mu(b) for each atom b.

  • The content Delta(X) for each random variable X: atoms that cross a partition boundary.

  • Entropy, mutual information, and co-information as sums of atom measures over appropriate content intersections.

  • Ideal generators and the R_n filter from the algebraic theory.

Parameters:

dist (Distribution) – A joint distribution. The joint outcome space is taken from the distribution’s non-zero-probability outcomes.

Notes

The number of atoms is 2^|Omega| - |Omega| - 1, so this is practical only for small outcome spaces (up to ~15-20 outcomes).

Examples

>>> import dit
>>> d = dit.example_dists.Xor()
>>> ld = LogarithmicDecomposition(d)
>>> abs(ld.coinformation() - (-1.0)) < 1e-10
True
property omega: frozenset

The joint outcome space as a frozenset of outcome tuples.

property atoms: set[frozenset]

subsets of Omega with |S| >= 2.

Return type:

set of frozenset

Type:

All logarithmic atoms Delta(Omega)

loss(subset: frozenset) → float[source]

Total entropy loss L(S) for a subset of outcomes.

Parameters:

subset (frozenset) – A subset of outcomes from Omega.

Returns:

The loss in bits.

Return type:

float

measure(atom: frozenset) → float[source]

Interior loss mu(b) for a single atom.

Parameters:

atom (frozenset) – A subset of Omega with |atom| >= 2.

Returns:

The signed measure of the atom in bits.

Return type:

float

measure_set(atom_set) → float[source]

Sum of mu(b) for all atoms b in the given set.

Parameters:

atom_set (iterable of frozenset)

Return type:

float

content(rvs=None) → set[frozenset][source]

Content Delta(X): atoms crossing a boundary in the partition of X.

An atom S is in Delta(X) if S contains at least two outcomes that belong to different parts of X’s partition.

Parameters:

rvs (list of int or list of list of int, optional) – Random variable indices. Each inner list is treated as a group (joint variable). If None, uses all variables jointly (gives all atoms – equivalent to Delta(Omega) for the finest partition).

Returns:

The content set.

Return type:

set of frozenset

Examples

>>> ld.content([0])      # Delta(X_0)
>>> ld.content([0, 1])   # Delta(X_0, X_1) = Delta(X_0 join X_1)
entropy(rvs=None) → float[source]

Entropy H(X) = mu(Delta(X)).

Parameters:

rvs (list of int, optional) – Variable indices defining X. If None, uses all variables.

Returns:

Entropy in bits.

Return type:

float

mutual_information(rvs_list) → float[source]

Mutual information I(X ; Y) = mu(Delta(X) ∩ Delta(Y)).

Parameters:

rvs_list (list of list of int) – Each inner list specifies one variable group. E.g. [[0], [1]] for I(X0 ; X1).

Return type:

float

coinformation(rvs_list=None) → float[source]

Co-information I(X1 ; … ; Xr) = mu(∩_i Delta(Xi)).

Parameters:

rvs_list (list of list of int, optional) – Each inner list specifies one variable group. If None, uses each single variable as a separate group.

Return type:

float

static degree(atom: frozenset) → int[source]

Degree of an atom: the number of outcomes it contains.

static generators(content_set: set[frozenset]) → set[frozenset][source]

Minimal elements (ideal generators) of a content set.

In the partial order where b_S1 <= b_S2 iff S1 ⊆ S2, the generators are those atoms not containing any other atom in the set.

Parameters:

content_set (set of frozenset)

Return type:

set of frozenset

static r_n(content_set: set[frozenset], n: int) → set[frozenset][source]

R_n(C): atoms in C lying in the upper set of a degree-n atom in C.

From Definition 62 of [1]: R_n(C) = {c in C : exists c’ in C with deg(c’) = n and c’ ⊆ c}

Parameters:
  • content_set (set of frozenset) – A set of atoms (e.g. a co-information content).

  • n (int) – The degree to filter on.

Return type:

set of frozenset

atom_table(rvs_groups=None)[source]

Summary table of all atoms with degree, measure, and memberships.

Parameters:

rvs_groups (list of list of int, optional) – Variable groups to show content membership for. Defaults to each single variable.

Returns:

Each dict has keys ‘atom’, ‘degree’, ‘measure’, and one boolean key per variable group.

Return type:

list of dict

alpha_synergistic_entropy(dist, alpha, rvs=None, definition='min')[source]

The \(\alpha\)-synergistic entropy [Var24a].

\[\operatorname{H}^{syn}_{\alpha} = \mathbb{E}\left[\min_{|a| = \alpha} h(x_a \mid x_{-a})\right]\]
Parameters:
  • dist (Distribution) – The distribution.

  • alpha (int) – The number of variables removed, from 1 to the number of variables.

  • rvs (list, None) – The variables. If None, all of them.

  • definition ({'min', 'max', 'avg'}) – How the losses of the \(\binom{n}{\alpha}\) subsets are combined; 'min' is Varley’s definition.

Returns:

h – The expected \(\alpha\)-synergistic entropy, in bits.

Return type:

float

backbone_disclosure(dist, sources=None, target=None, niter=None, bound=None)[source]

Compute the full backbone decomposition of I(X; Y).

The backbone decomposes I(X;Y) = sum_{m=1}^{n} B^m_partial, where each B^m_partial >= 0 measures the marginal gain from relaxing constraints on groups of m variables to groups of m-1.

Parameters:
  • dist (Distribution) – The joint distribution over sources and target.

  • sources (iter of iters, None) – The source variable groups. If None, all but last are used.

  • target (iter, None) – The target variable. If None, the last variable is used.

  • niter (int, None) – Number of basin-hopping restarts per lattice node.

  • bound (int, None) – Cardinality bound on V.

Returns:

backbone – Keys are integers m=1..n, values are B^m_partial (non-negative backbone atoms).

Return type:

dict

beta_common_information(dist, beta, rvs=None, crvs=None, niter=None, maxiter=1000, polish=False, bound=None)[source]

Compute the beta-approximate common information (information-correlation function) of dist.

\[C_{\beta}(X_1 : \ldots : X_n | Z) = \inf_{P_{U|X_1 \ldots X_n Z} :\; \max_{i \neq j} \rho_m(X_i; X_j | U, Z) \le \beta} I(X_1 \ldots X_n ; U | Z)\]

This generalises Wyner common information (beta=0) and, in the limit beta -> 1, Gacs-Korner common information. When beta >= rho_m(X;Y) the value is 0 because no auxiliary variable is needed.

Parameters:
  • dist (Distribution) – The distribution from which the common information is computed.

  • beta (float) – The maximal-correlation threshold, 0 <= beta <= 1.

  • rvs (list of lists, None) – A list of lists. Each inner list specifies the indexes of the random variables for one group. If None, each outcome coordinate forms its own group (equivalent to rvs=dist.rvs).

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, no conditioning is applied.

  • niter (int, None) – Number of basin-hopping restarts.

  • maxiter (int) – Maximum iterations per local optimisation.

  • polish (float or False, optional) – If a float, perform a second optimisation pass with probabilities below this threshold zeroed out. Default is False (no polishing), matching Wyner/ECI common-information optimizers.

  • bound (int, None) – Artificial bound on the cardinality of U. If None, the theoretical bound from Lemma 15a is used.

Returns:

c_beta – The beta-approximate common information.

Return type:

float

binding_information(dist, rvs=None, crvs=None)

Calculates the dual total correlation, also known as the binding information.

Parameters:
  • dist (Distribution) – The distribution from which the dual total correlation is calculated.

  • rvs (list, None) – The indexes of the random variable used to calculate the dual total correlation. If None, then the dual total correlation is calculated over all random variables.

  • crvs (list, None) – The indexes of the random variables to condition on. If None, then no variables are condition on.

Returns:

B – The dual total correlation.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

caekl_mutual_information(dist, rvs=None, crvs=None)[source]

Calculates the Chan-AlBashabsheh-Ebrahimi-Kaced-Liu mutual information.

Parameters:
  • dist (Distribution) – The distribution from which the CAEKL mutual information is calculated.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the total correlation. If None, then the total correlation is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

Returns:

J – The CAEKL mutual information.

Return type:

float

Examples

>>> d = dit.example_dists.Xor()
>>> dit.multivariate.caekl_mutual_information(d)
0.5
>>> dit.multivariate.caekl_mutual_information(d, rvs=[[0], [1]])
0.0
Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

channel_synthesis_rate(dist, inputs, outputs, common_randomness=0.0, public=False, crvs=None, niter=None, maxiter=1000, polish=1e-06, bound=None, backend='numpy', exact=False)[source]

The minimal communication rate for distributed channel synthesis [Cuf13].

An encoder sees i.i.d. inputs \(X\) and must, together with decoders sharing common randomness at rate \(R_0\), make the decoders produce outputs \(Y_1, \ldots, Y_m\) that are indistinguishable from i.i.d. draws of the joint distribution. The minimal rate is

\[R(R_0) = \min_{U} \max\left\{ \I{X : U},\ \I{X, Y_1, \ldots, Y_m : U} - R_0 \right\},\]

where \(U\) renders \(X, Y_1, \ldots, Y_m\) mutually conditionally independent. With one output, \(R(0)\) is the Wyner common information and \(R(R_0) = \I{X : Y}\) once \(R_0 \ge \H{Y \dagger X}\), the necessary conditional entropy [CPC10]. Several outputs form a broadcast channel whose decoders all receive the same message.

If the message is sent over a public channel and must look independent of the synthesized variables, the rate pair must instead satisfy \(R \ge \I{X : U}\) and \(R_0 \ge \I{X, Y_1, \ldots, Y_m : U}\), so that \(R_0\) must be at least the Wyner common information.

With exact=True the decoder must reproduce the joint distribution exactly rather than approximately, using variable-length messages. Yu and Tan [YT20a] show the rate

\[R(R_0) = \min_{X - U - Y} \max\left\{ \I{X : U},\ \Gamma_U - R_0 \right\}, \qquad \Gamma_U = -\H{X, Y | U} + \sum_u p(u) \mathbb{H}(p_{X|u}, p_{Y|u} \| p_{XY}),\]

is achievable, where \(\mathbb{H}\) is the maximal_cross_entropy(). It is at least the approximate rate, equals it once \(R_0 \ge \H{Y | X}\), is the exact synthesis rate of the doubly symmetric binary source, and without common randomness is exact_common_information_rate(). Every auxiliary variable found reproduces the distribution exactly, so the result is achievable even when the optimizer misses the minimum.

Parameters:
  • dist (Distribution) – The joint distribution of the channel input and outputs.

  • inputs (list) – The indexes of the channel input.

  • outputs (list) – The indexes of the channel output, or a list of such lists, one per decoder of a broadcast channel.

  • common_randomness (float) – The rate of common randomness, \(R_0\).

  • public (bool) – Whether the message is public. Defaults to False.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

  • niter (int > 0) – Number of basin hoppings to perform during the optimization.

  • maxiter (int > 0) – The number of iterations of the optimization subroutine to perform.

  • polish (False, float) – Whether to polish the result or not. If a float, this will perform a second optimization seeded with the result of the first, but with smaller tolerances and probabilities below polish set to 0. If False, don’t polish.

  • bound (int) – Bound the size of the auxiliary variable.

  • backend (str) – The optimization backend to use. One of 'numpy' (default), 'jax', or 'torch'.

  • exact (bool) – Whether the distribution must be reproduced exactly. Requires a single output, no crvs, a private channel, and the 'numpy' backend. Defaults to False.

Returns:

rate – The minimal communication rate, or with exact=True the Yu-Tan achievable rate.

Return type:

float

Raises:

ditException – Raised if public is True and no auxiliary variable meets the common-randomness budget, i.e. it is below the Wyner common information, or if exact is True with an unsupported option.

cohesion(dist, k, rvs=None, crvs=None)[source]

Computes the k-cohesion.

Parameters:
  • dist (Distribution) – The distribution from which the cohesion is calculated.

  • k (int, 1 <= k < N) – The order of the cohesion to compute.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the total correlation. If None, then the total correlation is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

Returns:

C_k – The k-Cohesion.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

coinformation(dist, rvs=None, crvs=None)[source]

Calculates the coinformation.

Parameters:
  • dist (Distribution) – The distribution from which the coinformation is calculated.

  • rvs (list, None) – The indexes of the random variable used to calculate the coinformation between. If None, then the coinformation is calculated over all random variables.

  • crvs (list, None) – The indexes of the random variables to condition on. If None, then no variables are condition on.

Returns:

I – The coinformation.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

Examples

Let’s construct a 3-variable distribution for the XOR logic gate and name the random variables X, Y, and Z.

>>> d = dit.example_dists.Xor()
>>> d.set_rv_names(['X', 'Y', 'Z'])

To calculate coinformations, recall that rvs specifies which groups of random variables are involved. For example, the 3-way mutual information I[X:Y:Z] is calculated as:

>>> dit.multivariate.coinformation(d, ['X', 'Y', 'Z'])
-1.0

It is a quirk of strings that each element of a string is also an iterable. So an equivalent way to calculate the 3-way mutual information I[X:Y:Z] is:

>>> dit.multivariate.coinformation(d, 'XYZ')
-1.0

The reason this works is that list(‘XYZ’) == [‘X’, ‘Y’, ‘Z’]. If we want to use random variable indexes, we need to have explicit groupings:

>>> dit.multivariate.coinformation(d, [[0], [1], [2]])
-1.0

To calculate the mutual information I[X, Y : Z], we use explicit groups:

>>> dit.multivariate.coinformation(d, ['XY', 'Z'])

Using indexes, this looks like:

>>> dit.multivariate.coinformation(d, [[0, 1], [2]])

The mutual information I[X:Z] is given by:

>>> dit.multivariate.coinformation(d, 'XZ')
0.0

Equivalently,

>>> dit.multivariate.coinformation(d, ['X', 'Z'])
0.0

Using indexes, this becomes:

>>> dit.multivariate.coinformation(d, [[0], [2]])
0.0

Conditional mutual informations can be calculated by passing in the conditional random variables. The conditional entropy I[X:Y|Z] is:

>>> dit.multivariate.coinformation(d, 'XY', 'Z')
1.0

Using indexes, this becomes:

>>> rvs = [[0], [1]]
>>> crvs = [[2]] # broken
>>> dit.multivariate.coinformation(d, rvs, crvs)
1.0

For the conditional random variables, groupings have no effect, so you can also obtain this as:

>>> rvs = [[0], [1]]
>>> crvs = [2]
>>> dit.multivariate.coinformation(d, rvs, crvs)
1.0

Finally, note that entropy can also be calculated. The entropy H[Z|XY] is obtained as:

>>> rvs = [[2]]
>>> crvs = [[0], [1]] # broken
>>> dit.multivariate.coinformation(d, rvs, crvs)
0.0
>>> crvs = [[0, 1]] # broken
>>> dit.multivariate.coinformation(d, rvs, crvs)
0.0
>>> crvs = [0, 1]
>>> dit.multivariate.coinformation(d, rvs, crvs)
0.0
>>> rvs = 'Z'
>>> crvs = 'XY'
>>> dit.multivariate.coinformation(d, rvs, crvs)
0.0

Note that [[0], [1]] says to condition on two groups. But conditioning is a flat operation and doesn’t respect the groups, so it is equal to a single group of 2 random variables: [[0, 1]]. With random variable names ‘XY’ is acceptable because list(‘XY’) = [‘X’, ‘Y’], which is species two singleton groups. By the previous argument, this is will be treated the same as [‘XY’].

cross_caekl_mutual_information(dist, ref_dist, rvs=None, crvs=None)[source]

Calculates the cross CAEKL mutual information, the cross-distribution generalization of the CAEKL mutual information.

Parameters:
  • dist (Distribution) – The test distribution p, over which the expectation is taken.

  • ref_dist (Distribution) – The reference distribution q, used to evaluate the pointwise information of each outcome.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the cross CAEKL mutual information. If None, then the cross CAEKL mutual information is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

Returns:

CJ – The cross CAEKL mutual information.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

cross_coinformation(dist, ref_dist, rvs=None, crvs=None)[source]

Calculates the cross co-information, the cross-distribution generalization of the (multivariate) mutual information.

For two random variables this is the cross mutual information of [Gohil et al., arXiv:2507.15372].

Parameters:
  • dist (Distribution) – The test distribution p, over which the expectation is taken.

  • ref_dist (Distribution) – The reference distribution q, used to evaluate the pointwise information of each outcome.

  • rvs (list, None) – The indexes of the random variable used to calculate the cross co-information between. If None, then the cross co-information is calculated over all random variables.

  • crvs (list, None) – The indexes of the random variables to condition on. If None, then no variables are condition on.

Returns:

CI – The cross co-information.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

cross_dual_total_correlation(dist, ref_dist, rvs=None, crvs=None)[source]

Calculates the cross dual total correlation, the cross-distribution generalization of the dual total correlation.

Parameters:
  • dist (Distribution) – The test distribution p, over which the expectation is taken.

  • ref_dist (Distribution) – The reference distribution q, used to evaluate the pointwise information of each outcome.

  • rvs (list, None) – The indexes of the random variable used to calculate the cross dual total correlation. If None, then the cross dual total correlation is calculated over all random variables.

  • crvs (list, None) – The indexes of the random variables to condition on. If None, then no variables are condition on.

Returns:

CB – The cross dual total correlation.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

cross_total_correlation(dist, ref_dist, rvs=None, crvs=None)[source]

Computes the cross total correlation, the cross-distribution generalization of the total correlation.

Parameters:
  • dist (Distribution) – The test distribution p, over which the expectation is taken.

  • ref_dist (Distribution) – The reference distribution q, used to evaluate the pointwise information of each outcome.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the cross total correlation. If None, then the cross total correlation is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

Returns:

CT – The cross total correlation.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

delta_k(dist, k, rvs=None, crvs=None)[source]

Compute the Delta^k measure, a parameterized family of higher-order information measures.

It is defined as \(\Delta^k = \mathcal{S} - k\mathcal{T}\), where \(\mathcal{S}\) is the S-information and \(\mathcal{T}\) is the total correlation. Since the S-information is the sum of the total correlation and the dual total correlation \(\mathcal{D}\), this is equivalent to \(\Delta^k = \mathcal{D} + (1 - k)\mathcal{T}\).

Special cases recover known measures: \(\Delta^0\) is the S-information, \(\Delta^1\) is the dual total correlation, and \(\Delta^2\) is the negative O-information. For larger k, the measure is sensitive to increasingly high-order synergies.

Parameters:
  • dist (Distribution) – The distribution from which the Delta^k measure is calculated.

  • k (int) – The order parameter.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the Delta^k measure. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

Returns:

D_k – The Delta^k measure.

Return type:

float

Examples

>>> d = dit.example_dists.n_mod_m(5, 2)
>>> dit.multivariate.delta_k(d, 2)
3.0
Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

deweese_caekl_mutual_information(dist, rvs=None, crvs=None, niter=None, deterministic=False, rng=None)

Compute the DeWeese caekl mutual information.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (iter of iters, None) – The random variables of interest. If None, use all.

  • crvs (iter, None) – The variables to condition on. If None, none.

  • niter (int, None) – If specified, the number of optimization steps to perform.

  • deterministic (bool) – Whether the functions to optimize over should be deterministic or not. Defaults to False.

Returns:

val – The value of the DeWeese caekl mutual information.

Return type:

float

deweese_coinformation(dist, rvs=None, crvs=None, niter=None, deterministic=False, rng=None)

Compute the DeWeese coinformation.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (iter of iters, None) – The random variables of interest. If None, use all.

  • crvs (iter, None) – The variables to condition on. If None, none.

  • niter (int, None) – If specified, the number of optimization steps to perform.

  • deterministic (bool) – Whether the functions to optimize over should be deterministic or not. Defaults to False.

Returns:

val – The value of the DeWeese coinformation.

Return type:

float

deweese_dual_total_correlation(dist, rvs=None, crvs=None, niter=None, deterministic=False, rng=None)

Compute the DeWeese dual total correlation.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (iter of iters, None) – The random variables of interest. If None, use all.

  • crvs (iter, None) – The variables to condition on. If None, none.

  • niter (int, None) – If specified, the number of optimization steps to perform.

  • deterministic (bool) – Whether the functions to optimize over should be deterministic or not. Defaults to False.

Returns:

val – The value of the DeWeese dual total correlation.

Return type:

float

deweese_total_correlation(dist, rvs=None, crvs=None, niter=None, deterministic=False, rng=None)

Compute the DeWeese total correlation.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (iter of iters, None) – The random variables of interest. If None, use all.

  • crvs (iter, None) – The variables to condition on. If None, none.

  • niter (int, None) – If specified, the number of optimization steps to perform.

  • deterministic (bool) – Whether the functions to optimize over should be deterministic or not. Defaults to False.

Returns:

val – The value of the DeWeese total correlation.

Return type:

float

directed_kamath_common_information(dist, rvs, about, crvs=None)[source]

Calculates the directed Kamath-Anantharam common information G(rvs -> about) = H(Phi^{about}_{rvs}), where Phi^{about}_{rvs} is the minimal sufficient statistic of rvs about about.

In the bivariate notation of Kamath & Anantharam (2010), this computes G(Y -> X) when called with rvs=Y, about=X. The variable on the tail of the arrow (rvs) is compressed via the minimal sufficient statistic; the variable on the head (about) is what that statistic preserves information about.

Parameters:
  • dist (Distribution) – The distribution from which the directed common information is calculated.

  • rvs (list) – The indexes (or names) of the random variables on the tail of the arrow. These are compressed to their minimal sufficient statistic about about.

  • about (list) – The indexes (or names) of the random variables on the head of the arrow. The minimal sufficient statistic preserves all information about these variables.

  • crvs (list, None) – The indexes of the random variables to condition on. If None, then no conditioning is performed.

Returns:

G – The directed Kamath-Anantharam common information.

Return type:

float

Raises:

ditException – Raised if rvs, about, or crvs contain non-existant random variables.

dual_total_correlation(dist, rvs=None, crvs=None)[source]

Calculates the dual total correlation, also known as the binding information.

Parameters:
  • dist (Distribution) – The distribution from which the dual total correlation is calculated.

  • rvs (list, None) – The indexes of the random variable used to calculate the dual total correlation. If None, then the dual total correlation is calculated over all random variables.

  • crvs (list, None) – The indexes of the random variables to condition on. If None, then no variables are condition on.

Returns:

B – The dual total correlation.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

entanglement(dist, rvs=None, crvs=None, niter=None, maxiter=1000, bound=None)[source]

Compute the entanglement.

The entanglement is the least total tension attainable by any probe W,

\[E(X_{0:n}) = \inf_W \Big\{ B[X_{0:n}|W] + \sum_i I[X_{-i}{:}W|X_i] \Big\},\]

which for a pair is inf_W I[X:Y|W] + I[X:W|Y] + I[W:Y|X] [MMRV02, MR26a, Zha03]. The multivariate residual is the dual total correlation, which puts E on the scale of the common informations.

Parameters:
  • dist (Distribution) – The distribution for which the entanglement is computed.

  • rvs (list of lists, None) – The source groups. If None, each variable of dist is its own source.

  • crvs (list, None) – A single list of indexes specifying variables to condition on. If None, none are conditioned on.

  • niter (int, None) – Number of basin hops to perform during the optimization.

  • maxiter (int) – The number of iterations of the optimization subroutine to perform.

  • bound (int, None) – Bound the size of the probe variable.

Returns:

E – The entanglement.

Return type:

float

Examples

A pair whose mutual information is fully extractable has zero entanglement:

>>> from dit import Distribution
>>> from dit.multivariate import entanglement
>>> giant_bit = Distribution(['00', '11'], [1/2, 1/2])
>>> float(entanglement(giant_bit))
0.0
entropy(dist, rvs=None, crvs=None)[source]

Calculates the conditional joint entropy.

Parameters:
  • dist (Distribution) – The distribution from which the entropy is calculated.

  • rvs (list, None) – The indexes of the random variable used to calculate the entropy. If None, then the entropy is calculated over all random variables.

  • crvs (list, None) – The indexes of the random variables to condition on. If None, then no variables are conditioned on.

Returns:

H – The entropy.

Return type:

float

Raises:

ditException – Raised if rvs or crvs contain non-existant random variables.

Examples

Let’s construct a 3-variable distribution for the XOR logic gate and name the random variables X, Y, and Z.

>>> d = dit.example_dists.Xor()
>>> d.set_rv_names(['X', 'Y', 'Z'])

The joint entropy of H[X,Y,Z] is:

>>> dit.multivariate.entropy(d, 'XYZ')
2.0

We can do this using random variables indexes too.

>>> dit.multivariate.entropy(d, [0,1,2])
2.0

The joint entropy H[X,Z] is given by:

>>> dit.multivariate.entropy(d, 'XZ')
1.0

Conditional entropy can be calculated by passing in the conditional random variables. The conditional entropy H[Y|X] is:

>>> dit.multivariate.entropy(d, 'Y', 'X')
1.0
exact_common_information(dist, rvs=None, crvs=None, niter=None, maxiter=1000, polish=1e-06, bound=None, backend='numpy', rng=None)

Computes the exact common information, min H[V] where V renders all rvs independent.

Parameters:
  • dist (Distribution) – The distribution for which the exact common information will be computed.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the exact common information. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

  • niter (int > 0) – Number of basin hoppings to perform during the optimization.

  • maxiter (int > 0) – The number of iterations of the optimization subroutine to perform.

  • polish (False, float) – Whether to polish the result or not. If a float, this will perform a second optimization seeded with the result of the first, but with smaller tolerances and probabilities below polish set to 0. If False, don’t polish.

  • bound (int) – Bound the size of the Markov variable.

  • backend (str) – The optimization backend to use. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

Returns:

ci – The exact common information.

Return type:

float

exact_common_information_rate(dist, rvs=None, block_length=1, niter=None, maxiter=1000, polish=1e-06, bound=None)[source]

An upper bound on the exact common information rate [KLEG14], from Yu and Tan [YT20a, YT20b]:

\[\bar{G}[X : Y] \leq \Gamma[X : Y] = \min_{X - W - Y} -\H{X, Y | W} + \sum_w p(w) \mathbb{H}(p_{X|w}, p_{Y|w} \| p_{XY}),\]

where \(\mathbb{H}\) is the maximal_cross_entropy(). Every feasible \(W\) achieves its value, so the result is a valid upper bound even when the optimizer misses the minimum. It lies between the Wyner common information and the one-shot exact_common_information(), equals the Wyner common information exactly when some \(W\) attaining the Wyner common information makes \(p_{XY}\) a product distribution on each \(\operatorname{supp} p_{X|w} \times \operatorname{supp} p_{Y|w}\) (for instance when one of \(p_{X|w}, p_{Y|w}\) is deterministic for every \(w\), as for the erasure channel), and equals \(\bar{G}\) for the doubly symmetric binary source.

With block_length=N the bound is also applied to \(n\) i.i.d. copies of the pair, returning \(\min_{n \leq N} \Gamma[X^n : Y^n] / n\), which decreases to \(\bar{G}\) as \(N\) grows. The work grows exponentially in \(N\); beyond small alphabets, pass bound.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (list, None) – Two lists of indexes, the variables of \(X\) and of \(Y\). If None, the distribution must have exactly two variables.

  • block_length (int) – The largest number of i.i.d. copies to bound. Defaults to 1.

  • niter (int > 0) – Number of basin hoppings to perform during each optimization.

  • maxiter (int > 0) – The number of iterations of the optimization subroutine to perform.

  • polish (False, float) – Whether to polish the result or not. If a float, this will perform a second optimization seeded with the result of the first, but with smaller tolerances and probabilities below polish set to 0. If False, don’t polish.

  • bound (int, None) – Bound the size of the auxiliary variable, for every block length.

Returns:

rate – The upper bound on the exact common information rate.

Return type:

float

Raises:

ditException – Raised if rvs does not specify exactly two groups of variables.

exact_common_information_rate_bounds(dist, rvs=None, block_length=1, niter=None, maxiter=1000, polish=1e-06, bound=None)[source]

Lower and upper bounds on the exact common information rate \(\bar{G}[X : Y]\) [KLEG14].

The upper bound is exact_common_information_rate(). The lower bound is the larger of the Wyner common information and the Yu-Tan bound [YT20a, YT20b]

\[\Gamma^{(o)}[X : Y] = \min_{X - W - Y} -\H{X, Y | W} + \min_{q \in \mathcal{C}(p_W, p_W)} \sum_{w, w'} q(w, w') \mathbb{H}(p_{X|w}, p_{Y|w'} \| p_{XY}).\]

The two bounds meet for the doubly symmetric binary source. Unlike the upper bound, the lower bound holds only at a global minimum over auxiliary variables with at most bound states, which local optimization cannot certify, so treat it as an estimate.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (list, None) – Two lists of indexes, the variables of \(X\) and of \(Y\). If None, the distribution must have exactly two variables.

  • block_length (int) – The largest number of i.i.d. copies used for the upper bound. Defaults to 1.

  • niter (int > 0) – Number of basin hoppings to perform during each optimization.

  • maxiter (int > 0) – The number of iterations of the optimization subroutine to perform.

  • polish (False, float) – Whether to polish the result or not. If a float, this will perform a second optimization seeded with the result of the first, but with smaller tolerances and probabilities below polish set to 0. If False, don’t polish.

  • bound (int, None) – Bound the size of the auxiliary variable.

Returns:

  • lower (float) – The lower bound.

  • upper (float) – The upper bound.

Raises:

ditException – Raised if rvs does not specify exactly two groups of variables.

frustration(dist, rvs=None, order=2, max_nodes=20000, tol=1e-07)[source]

Compute the order-k frustration: the divergence from the order-k maximum entropy distribution to the nearest model whose k-body interactions are unfrustrated.

Let \(\tilde{p}_k\) be the maximum entropy distribution with the same k-variable marginals as \(p\), and \(\Delta_j\) the connected informations [SSB+03], so that \(D_{KL}(p \| \tilde{p}_k) = \sum_{j > k} \Delta_j\). Interactions of order k can themselves be inconsistent, as the pairwise exclusions of the W distribution are; frustration measures this through the k-body interactions of \(\tilde{p}_k\) rather than through the sign of a co-information.

A binary sub-model picks two letters per variable. Its top-order interaction on a k-set S is the k-th mixed difference of \(\log q\) over the chosen letters, which relabeling a variable in S negates. A product of such interactions over a family of k-sets is invariant exactly when the family covers every variable an even number of times (a cycle over GF(2)). Let \(\mathcal{U}_k\) be the models of order at most k in which every such product, in every binary sub-model, is non-negative; lower-order interactions are unconstrained. For bits this is the condition that the parity constraints read off the signs are simultaneously satisfiable; for k = 2 it is balance of the signed graph of couplings [Har53], i.e. multivariate total positivity after relabeling [FLS+17]. Then

\[F_k = \min_{q \in \mathcal{U}_k} D_{KL}(\tilde{p}_k \| q) = \min_{q \in \mathcal{U}_k} D_{KL}(p \| q) - \sum_{j > k} \Delta_j ,\]

the second form by the Pythagorean theorem for hierarchical log-linear families [Ama01]. The k-subsets of k + 1 variables form a cycle only for even k, so for instance three-way frustration needs at least five variables. For three bits and k = 2, \(F_2 = \min_k I[X_i : X_j | X_k]_{\tilde{p}_2}\) when the loop of couplings is negative and zero otherwise, and \(F_2 \geq -I[X : Y : Z]_{\tilde{p}_2}\) [CT06].

Otherwise the minimum is computed exactly by branch-and-bound: every top-order interaction is linear in the natural parameters, so \(\mathcal{U}_k\) is a finite union of polyhedral cones and the projection onto each is a convex program [LUZ21]. A local search supplies the initial incumbent.

No canonical literature source is known for this measure.

Parameters:
  • dist (Distribution) – The distribution from which the frustration is calculated.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables forming one variable of the model. If None, each random variable is its own variable.

  • order (int) – The interaction order k, at least 2.

  • max_nodes (int) – The maximum number of branch-and-bound nodes. If optimality is not certified within this budget, the best value found is returned with a warning giving the certified bracket.

  • tol (float) – The optimality tolerance, in bits.

Returns:

F – The order-k frustration.

Return type:

float

Raises:

ditException – Raised if order is less than 2, or if the cycle space of the k-subsets is too large to enumerate.

Examples

>>> w = dit.Distribution(['001', '010', '100'], [1/3] * 3)
>>> round(dit.multivariate.frustration(w), 6)
0.666667
>>> dit.multivariate.frustration(dit.example_dists.Xor())
0.0
functional_common_information(dist, rvs=None, crvs=None, return_partition=False)[source]

Compute the functional common information, F, of dist. It is the entropy of the smallest random variable W such that all the variables in rvs are rendered independent conditioned on W (and crvs), and W is a function of rvs and crvs.

Parameters:
  • dist (Distribution) – The distribution from which the functional common information is computed.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the total correlation. If None, then the total correlation is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

  • return_partition (bool) – If True, also return the optimal W as a partition of the outcomes of dist: a frozenset of blocks, each a frozenset of outcomes.

Returns:

  • F (float) – The functional common information.

  • partition (frozenset of frozensets) – The optimal W, only if return_partition is True.

functional_variable(dist, rvs=None, crvs=None)[source]

Return dist with the optimal functional common variable W appended.

W is the least-entropy function of rvs and crvs rendering rvs independent given crvs, so entropy(d, [d.outcome_length() - 1]) is the functional common information. Its values are block labels 0, 1, ... (as strings when the outcomes of dist have string symbols).

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables to render independent. If None, all random variables are used.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

Returns:

d – The support of dist with W appended as its last variable.

Return type:

Distribution

gamma_k(dist, k, rvs=None, crvs=None)[source]

Compute the Gamma^k measure, the entropic conjugate of the Delta^k measure.

It is defined as \(\Gamma^k = \mathcal{S} - k\mathcal{D}\), where \(\mathcal{S}\) is the S-information and \(\mathcal{D}\) is the dual total correlation. Since the S-information is the sum of the total correlation \(\mathcal{T}\) and the dual total correlation, this is equivalent to \(\Gamma^k = \mathcal{T} + (1 - k)\mathcal{D}\).

Special cases recover known measures: \(\Gamma^0\) is the S-information, \(\Gamma^1\) is the total correlation, and \(\Gamma^2\) is the O-information. For larger k, the measure is sensitive to increasingly high-order redundancies.

Parameters:
  • dist (Distribution) – The distribution from which the Gamma^k measure is calculated.

  • k (int) – The order parameter.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the Gamma^k measure. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

Returns:

G_k – The Gamma^k measure.

Return type:

float

Examples

>>> d = dit.example_dists.n_mod_m(5, 2)
>>> dit.multivariate.gamma_k(d, 2)
-3.0
Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

generalized_dual_total_correlation(dist, order, rvs=None, crvs=None)[source]

Compute the generalized dual total correlation. It is the sum of all co-informations (conditioned or not) over at least order variables.

Parameters:
  • dist (Distribution) – The distribution from which the generalized dual total correlation is calculated.

  • order (int >= 1) – The order to use.

  • rvs (list, None) – The indexes of the random variable used to calculate the generalized dual total correlation. If None, then the dual total correlation is calculated over all random variables.

  • crvs (list, None) – The indexes of the random variables to condition on. If None, then no variables are condition on.

Returns:

GB – The generalized dual total correlation.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

gk_common_information(dist, rvs=None, crvs=None)[source]

Calculates the Gacs-Korner common information K[X1:X2…] over the random variables in rvs.

Parameters:
  • dist (Distribution) – The distribution from which the common information is calculated.

  • rvs (list, None) – The indexes of the random variables for which the Gacs-Korner common information is to be computed. If None, then the common information is calculated over all random variables.

  • crvs (list, None) – The indexes of the random variables to condition the common information by. If none, than there is no conditioning.

Returns:

K – The Gacs-Korner common information of the distribution.

Return type:

float

Raises:

ditException – Raised if rvs or crvs contain non-existant random variables.

higher_order_common_information(dist, rvs=None, niter=None, maxiter=None, rng=None)[source]

Compute the higher-order common information [Ostergaard24]:

\[\operatorname{HCI}[X_0 : \ldots : X_{n-1}] = \min_i \max_\pi \sup_{T_{n-1}} \min_j \I{T_{n-1} : X_j},\]

where \(T_1 = X_i\) and each \(T_{\ell+1}\) maximizes \(\I{T_{\ell+1} : X_{\pi(\ell)}}\) among target-minimal \(T_{\ell+1} - T_\ell - X_{0:n}\) with \(\I{T_{\ell+1} : T_\ell} \leq \I{T_\ell : X_{\pi(\ell)}}\).

For two variables it is the mutual information, and in general

\[\K{X_0 : \ldots : X_{n-1}} \leq \operatorname{HCI}[X_0 : \ldots : X_{n-1}] \leq \min_{i \neq j} \I{X_i : X_j}.\]

When the two bounds meet their common value is returned. Otherwise every ordering of every reference is searched, solving a rate-constrained information bottleneck at each stage, so the cost grows as \(n!\). Stages whose relevant part is a deterministic function of the processed variable are solved exactly; the rest are numerical. Ties among stage optimizers go to the one sharing the most with the least related other variable, which is exact for three variables and a heuristic for more.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (list of lists, None) – The variables \(X_0, \ldots, X_{n-1}\). If None, use every variable of dist.

  • niter (int, None) – The number of basin hops per optimization.

  • maxiter (int, None) – The number of iterations of the optimization subroutine.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizers.

Returns:

hci – The higher-order common information.

Return type:

float

independent_information(dist, rvs=None, crvs=None)

Compute the residual entropy.

Parameters:
  • dist (Distribution) – The distribution from which the residual entropy is calculated.

  • rvs (list, None) – The indexes of the random variable used to calculate the residual entropy. If None, then the total correlation is calculated over all random variables.

  • crvs (list, None) – The indexes of the random variables to condition on. If None, then no variables are condition on.

Returns:

R – The residual entropy.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

information_of_formation(dist, rvs, crvs, niter=None, bound_u=None, bound_v=None, rng=None)

Compute the secret key cost [Win05], also known as the information of formation [RW03]: the minimal rate of secret key Alice and Bob need to produce XY by local operations and public communication, such that Eve could simulate the public transcript from Z. It is

min I[XY : V | U] such that XY - Z - U and X - UV - Y

that is, the conditional Wyner common information C[X : Y | U] minimized over degradations U of Z. It is never less than the intrinsic mutual information [RW03], and never more than either C[X : Y] or C[X : Y | Z].

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (iterable of iterables, len(rvs) == 2) – The variables representing Alice and Bob.

  • crvs (iterable) – The variables representing Eve.

  • niter (int, None) – The number of basin hops to perform. If None, use 5.

  • bound_u (int, None) – Bound on the size of U. If None, use |Z| + 1.

  • bound_v (int, None) – Bound on the size of V. If None, use |X||Y|.

  • rng (int, np.random.Generator, None) – Source of randomness.

Returns:

skc – The secret key cost.

Return type:

float

interaction_information(dist, rvs=None, crvs=None)[source]

Calculates the interaction information.

Parameters:
  • dist (Distribution) – The distribution from which the interaction information is calculated.

  • rvs (list, None) – The indexes of the random variable used to calculate the interaction information between. If None, then the interaction information is calculated over all random variables.

  • crvs (list, None) – The indexes of the random variables to condition on. If None, then no variables are condition on.

Returns:

II – The interaction information.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

interactive_intrinsic_mutual_information(dist, rvs=None, crvs=None, rounds=2, bound_func=None, niter=None, backend='numpy')[source]

Compute a lower bound on the secret key agreement rate based on interactive communication.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (iterable) – The indices to consider as X (Alice) and Y (Bob).

  • crvs (iterable) – The indices to consider as Z (Eve).

  • rounds (int) – The number of rounds of communication to allow. Defaults to 2.

  • bound_func (func) – A function over i, |X|, |Y| which returns the bound on variable U_i.

  • niter (int, None) – The number of hops to perform during optimization.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

Returns:

iskar – The lower bound.

Return type:

float

intersection_entropy(dist, rvs=None, crvs=None)[source]

Compute the intersection entropy H(X_1 u X_2 u … u X_n).

The expected surprise of the least surprising marginal realisation:

H(X_1 u … u X_n) = E[ min(h(x_1), …, h(x_n)) ]

Parameters:
  • dist (Distribution) – The distribution from which the intersection entropy is calculated.

  • rvs (list, None) – The random variable groups. If None, each variable is its own group.

  • crvs (list, None) – Variables to condition on (not supported; must be None or empty).

Returns:

Hi – The intersection entropy.

Return type:

float

intrinsic_caekl_mutual_information(dist, rvs=None, crvs=None, niter=None, bound=None, backend='numpy', rng=None)

Compute the intrinsic CAEKL mutual information.

Parameters:
  • dist (Distribution) – The distribution to compute the intrinsic CAEKL mutual information of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic CAEKL mutual information. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bound (int, None) – Bound on the size of the auxiliary variable. If None, use the theoretical bound.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

intrinsic_dual_total_correlation(dist, rvs=None, crvs=None, niter=None, bound=None, backend='numpy', rng=None)

Compute the intrinsic dual total correlation.

Parameters:
  • dist (Distribution) – The distribution to compute the intrinsic dual total correlation of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic dual total correlation. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bound (int, None) – Bound on the size of the auxiliary variable. If None, use the theoretical bound.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

intrinsic_mutual_information(dist, rvs=None, crvs=None, niter=None, bound=None, backend='numpy', rng=None)

Compute the intrinsic total correlation.

Parameters:
  • dist (Distribution) – The distribution to compute the intrinsic total correlation of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic total correlation. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bound (int, None) – Bound on the size of the auxiliary variable. If None, use the theoretical bound.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

intrinsic_total_correlation(dist, rvs=None, crvs=None, niter=None, bound=None, backend='numpy', rng=None)

Compute the intrinsic total correlation.

Parameters:
  • dist (Distribution) – The distribution to compute the intrinsic total correlation of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic total correlation. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bound (int, None) – Bound on the size of the auxiliary variable. If None, use the theoretical bound.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

iterated_discarding_skar(dist, rvs, crvs, rounds=8, niter=None, rng=None)[source]

Compute a lower bound on the two-way secret key agreement rate achieved by iterated public discarding.

Alice and Bob alternate rounds. In each round the speaker publicly announces, independently for each position, whether to keep it; the keep probability depends only on the speaker’s own symbol. Discarded positions are abandoned, and after the final round whichever party fares better sends their (remaining) variable as a one-way key. This post-selection is the single-letter form of advantage distillation [Mau93], and is a special case of the interactive bound interactive_intrinsic_mutual_information() in which every auxiliary variable is a keep/discard flag. Because each round needs only one keep probability per symbol, many more rounds are tractable than for the general interactive bound.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (iterable of iterables, len(rvs) == 2) – The indices of the random variables agreeing upon a secret key.

  • crvs (iterable) – The indices of the eavesdropper.

  • rounds (int) – The number of discarding rounds, not counting the final key message. Defaults to 8.

  • niter (int, None) – The number of random restarts per choice of first speaker. Defaults to 10.

  • rng (np.random.Generator, int, None) – The source of randomness for the restarts.

Returns:

skar – The lower bound on the two-way secret key agreement rate.

Return type:

float

kamath_common_information(dist, rvs=None, crvs=None)[source]

Calculates the Kamath-Anantharam dual common information U[X1:X2…] of the random variables in rvs.

For two variables this is

U(X; Y) = max{ G(Y -> X), G(X -> Y) }

= max{ H(Phi^X_Y), H(Phi^Y_X) },

the symmetric “dual” to the Gács-Körner common information introduced by Kamath & Anantharam (2010). It is generalized to n variables as

U(X_{0:n}) = max_i H(Phi^{X_{!=i}}_{X_i}),

the maximum entropy of the minimal sufficient statistic of one variable about all the others.

Parameters:
  • dist (Distribution) – The distribution from which the common information is calculated.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of a random variable to compress via its minimal sufficient statistic about the rest. If None, then each single random variable is used.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no conditioning is performed.

Returns:

U – The Kamath-Anantharam dual common information.

Return type:

float

Raises:

ditException – Raised if rvs or crvs contain non-existant random variables.

kirkwood_mutual_information(dist, rvs=None, crvs=None, order=None)[source]

Compute the Kirkwood mutual information: the Kullback-Leibler divergence from the joint distribution to its normalized generalized Kirkwood superposition approximation.

For variables \(X_0, \ldots, X_{n-1}\) the generalized Kirkwood approximation of order \(k\) truncates the Möbius (interaction) expansion of \(\log p\) at subsets of size at most \(k\) [KYKG07, Wat60]:

\[\tilde{p}_k(x) = \prod_{1 \leq |S| \leq k} p(x_S)^{c_S}, \qquad c_S = (-1)^{k-|S|} \binom{n-|S|-1}{k-|S|},\]

which need not sum to one. The default order \(k = n-1\) is the standard Kirkwood approximation, the Möbius product over proper subsets with \(c_S = (-1)^{n-1-|S|}\). Order 1 is the product of marginals and order 0 is the uniform distribution. With \(\hat{p}_k = \tilde{p}_k / Z\) and \(Z = \sum_x \tilde{p}_k(x)\), the measure is \(K_k = D_{KL}(p \| \hat{p}_k)\).

For three variables and the default order this is the divergence from the normalized Kirkwood superposition approximation used by [WYY+10]. At the default order it satisfies

\[K = (-1)^n I[X_0 : \cdots : X_{n-1}] + \log_2 Z,\]

where \(I\) is the coinformation [KM20]. Order 1 gives the total correlation, and order 0 gives \(\sum_i \log_2 |\mathcal{X}_i| - H[X_0, \ldots, X_{n-1}]\). Since \(\hat{p}_k\) is log-linear in the \(k\)-marginals, \(K_k\) upper bounds the divergence to the maximum entropy distribution matching them. For fewer than two variables the result is zero.

Parameters:
  • dist (Distribution) – The distribution from which the Kirkwood mutual information is calculated.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the Kirkwood mutual information. If None, then it is calculated over all random variables.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

  • order (int, None) – The largest marginal size k used by the approximation. Must satisfy 0 <= k <= n - 1. If None, defaults to n - 1.

Returns:

K – The Kirkwood mutual information.

Return type:

float

Raises:

ditException – Raised if order is out of range.

Examples

>>> d = dit.example_dists.giant_bit(3, 2)
>>> dit.multivariate.kirkwood_mutual_information(d)
0.0
>>> d = dit.example_dists.n_mod_m(3, 2)
>>> dit.multivariate.kirkwood_mutual_information(d)
1.0
>>> dit.multivariate.kirkwood_mutual_information(d, order=1)
1.0
less_noisy_intrinsic_mutual_information(dist, rvs, crvs, niter=None, bound=None, rng=None)[source]

Compute the less-noisy intrinsic mutual information [PGR26]:

inf_{p(j|xy) : p(z|xy) is less noisy than p(j|xy)} I[X:Y|J]

If Eve’s channel is less noisy than that of J – I[U:Z] >= I[U:J] for every U - XY - ZJ and every input distribution – then the secret key agreement rate against Z is at most that against J [GGunluK17], which in turn is at most I[X:Y|J]. Every degradation of Z is dominated, so this never exceeds the intrinsic mutual information, and it never falls below the inf-max upper bound of Gohari and Anantharam (2010), stated as Eq. (11) of [AG26].

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (iterable of iterables, len(rvs) == 2) – The variables representing Alice and Bob.

  • crvs (iterable) – The variables representing Eve.

  • niter (int, None) – The number of local optimizations to run. If None, use 8.

  • bound (int, None) – The size of J. If None, use |Z|.

  • rng (int, np.random.Generator, None) – Source of randomness.

Returns:

lnimi – The less-noisy intrinsic mutual information.

Return type:

float

Notes

The less-noisy condition is checked on a finite sample of input distributions, so the returned value is a numerical estimate of an upper bound, not a certificate.

logarithmic_decomposition(dist: Distribution) → LogarithmicDecomposition[source]

Construct a LogarithmicDecomposition for the given distribution.

Parameters:

dist (Distribution)

Return type:

LogarithmicDecomposition

lower_intrinsic_mutual_information(dist, rvs, crvs)[source]

Compute a trivial lower-bound on the secret key agreement rate.

Parameters:
  • dist (Distribution) – The distribution to compute the bound for.

  • rvs (iterable of iterables, len(rvs) == 2) – The variables representing the agents to agree upon a key.

  • crvs (iterable) – The variable representing the eavesdropper.

Returns:

lb – A lower-bound on the secret key agreement rate.

Return type:

float

max_synergistic_entropy(dist, rvs=None, crvs=None)[source]

Compute the analytical upper bound on the mutual information that any SRV can have about a set of variables.

\[H(X_1, \ldots, X_n) - \max_i H(X_i)\]

This is the maximum possible synergistic entropy of the sources, per Equation 17 of Quax et al. (2017).

Parameters:
  • dist (Distribution) – The distribution from which the bound is calculated.

  • rvs (list, None) – The random variable groups. If None, each variable is its own group.

  • crvs (list, None) – Variables to condition on.

Returns:

bound – The upper bound on synergistic entropy.

Return type:

float

maxent_function(dist, epsilon, rvs=None, crvs=None, method='spectral')[source]

The Salamatian-Cohen-Médard Maximum Entropy Function:

\[M_{\epsilon}(X; Y) = \max_{\phi_X, \phi_Y} H(\phi_X(X)) \quad \text{s.t.} \quad H(\phi_X(X) \mid \phi_Y(Y)) \le \epsilon\]

where the maximization is over binary-valued functions \(\phi_X: \mathcal{X} \to \{-1, +1\}\) and \(\phi_Y: \mathcal{Y} \to \{-1, +1\}\). This is an approximate Gács-Körner common information that admits a helper of rate up to \(\epsilon\).

Parameters:
  • dist (Distribution) – The distribution from which to compute the measure.

  • epsilon (float) – The maximum allowed helper rate \(H(\phi_X(X) \mid \phi_Y(Y))\).

  • rvs (list, None) – A list selecting exactly two random variables (by index or name). If None, all variables of dist are used; dist must therefore be bivariate.

  • crvs (list, None) – Not supported; passing a non-empty crvs raises ditException.

  • method ({"spectral", "exact"}) –

    • "spectral" (default): the paper’s §IV-A approximation. Thresholds the second left/right singular vectors of \(Q = D_X^{-1/2} P D_Y^{-1/2}\) across all distinct cuts and returns the largest feasible \(H(\phi_X(X))\).

    • "exact": brute force over every binary partition of \(\mathcal{X}\) and \(\mathcal{Y}\). Refuses to run when the alphabets would produce more than ~:math:2^{20} partition pairs.

Returns:

M – The Maximum Entropy Function value (in bits when units are off).

Return type:

float

Raises:

ditException – If crvs is provided, rvs does not select exactly two variables, the method is unknown, or method=”exact” is requested on an alphabet that is too large to enumerate.

minimal_intrinsic_CAEKL_mutual_information(dist, rvs=None, crvs=None, niter=None, bounds=None, backend='numpy', rng=None)

Compute the minimal intrinsic CAEKL mutual information.

Parameters:
  • dist (Distribution) – The distribution to compute the minimal intrinsic CAEKL mutual information of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic CAEKL mutual information. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bounds ([int], None) – Bounds on the size of the auxiliary variable. If None, use the theoretical bound. This is used to better sample smaller subspaces.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

minimal_intrinsic_caekl_mutual_information(dist, rvs=None, crvs=None, niter=None, bounds=None, backend='numpy', rng=None)

Compute the minimal intrinsic CAEKL mutual information.

Parameters:
  • dist (Distribution) – The distribution to compute the minimal intrinsic CAEKL mutual information of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic CAEKL mutual information. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bounds ([int], None) – Bounds on the size of the auxiliary variable. If None, use the theoretical bound. This is used to better sample smaller subspaces.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

minimal_intrinsic_dual_total_correlation(dist, rvs=None, crvs=None, niter=None, bounds=None, backend='numpy', rng=None)

Compute the minimal intrinsic dual total correlation.

Parameters:
  • dist (Distribution) – The distribution to compute the minimal intrinsic dual total correlation of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic dual total correlation. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bounds ([int], None) – Bounds on the size of the auxiliary variable. If None, use the theoretical bound. This is used to better sample smaller subspaces.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

minimal_intrinsic_mutual_information(dist, rvs=None, crvs=None, niter=None, bounds=None, backend='numpy', rng=None)

Compute the minimal intrinsic total correlation.

Parameters:
  • dist (Distribution) – The distribution to compute the minimal intrinsic total correlation of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic total correlation. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bounds ([int], None) – Bounds on the size of the auxiliary variable. If None, use the theoretical bound. This is used to better sample smaller subspaces.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

minimal_intrinsic_total_correlation(dist, rvs=None, crvs=None, niter=None, bounds=None, backend='numpy', rng=None)

Compute the minimal intrinsic total correlation.

Parameters:
  • dist (Distribution) – The distribution to compute the minimal intrinsic total correlation of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic total correlation. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bounds ([int], None) – Bounds on the size of the auxiliary variable. If None, use the theoretical bound. This is used to better sample smaller subspaces.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

modified_synergistic_disclosure(dist, sources, target, alpha, niter=None, bound=None)[source]

Compute the modified synergistic disclosure for a single constraint alpha.

For singleton alpha (|alpha| = 1), returns I(T : a^C | a) instead of the optimization-based S_alpha. For |alpha| >= 2, falls back to the standard synergistic disclosure.

Gutknecht, Makkeh & Wibral (2023), “From Babel to Boole: The Logical Organization of Information Decompositions”, arXiv:2306.00734v2, eq. 52.

Parameters:
  • dist (Distribution) – The joint distribution over sources and target.

  • sources (list of lists) – Each inner list gives the indices of one source variable group.

  • target (list) – The indices of the target variable.

  • alpha (list of lists) – Each inner list gives source-list indices (0-based) specifying which sources form each constraint subgroup.

  • niter (int, None) – Number of basin-hopping restarts (used only for |alpha| >= 2).

  • bound (int, None) – Cardinality bound on V (used only for |alpha| >= 2).

Returns:

s_msd – The modified synergistic disclosure, in bits.

Return type:

float

mss_common_information(dist, rvs=None, crvs=None)[source]

Compute the minimal sufficient statistic common information, which is the entropy of the join of the minimal sufficent statistic of each variable about the others.

Parameters:
  • dist (Distribution) – The distribution for which the joint minimal sufficient statistic is computed.

  • rvs (list, None) – The random variables to compute the joint minimal sufficient statistic of. If None, all random variables are used.

  • crvs (list, None) – The random variables to condition the joint minimal sufficient statistic on. If None, then no random variables are conditioned on.

necessary_intrinsic_mutual_information(dist, rvs, crvs, niter=None, bound_u=None, bound_v=None, backend='numpy')[source]

Compute a non-trivial lower bound on secret key agreement rate.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (iterable of iterables, len(rvs) == 2) – The indices of the random variables agreeing upon a secret key.

  • crvs (iterable) – The indices of the eavesdropper.

  • niter (int, None) – The number of hops to perform during optimization.

  • bound_u (int, None) – The bound to use on the size of the variable U. If none, use the theoretical bound of |X|^2.

  • bound_v (int, None) – The bound to use on the size of the variable V. If none, use the theoretical bound of |X|.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

Returns:

nimi – The necessary intrinsic mutual information.

Return type:

float

no_communication_skar(dist, rv_x, rv_y, rv_z)[source]

The rate at which X and Y can agree upon a key with Z eavesdropping, and no public communication.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rv_x (iterable) – The indices to consider as the X variable, Alice.

  • rv_y (iterable) – The indices to consider as the Y variable, Bob.

  • rv_z (iterable) – The indices to consider as the Z variable, Eve.

Returns:

skar – The no-communication secret key agreement rate.

Return type:

float

o_information(dist, rvs=None, crvs=None)[source]

Computes the O-information, defined as the total correlation minus the dual total correlation.

Parameters:
  • dist (Distribution) – The distribution from which the o-information is calculated.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the o-information. If None, then the o-information is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

Returns:

O – The o-information.

Return type:

float

Examples

>>> d = dit.example_dists.n_mod_m(5, 2)
>>> dit.multivariate.o_information(d)
-3.0
>>> dit.multivariate.o_information(d, rvs=[[0], [1], [3], [4]], crvs=[2])
-2.0
Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

omniscience_rate(dist, rvs=None, key_terminals=None, crvs=None)[source]

Compute the minimum rate of public communication for omniscience [CsiszarN04].

This is the smallest total rate \(R_{CO}^{\mathcal{A}}\) of public discussion after which every terminal in the key set \(\mathcal{A}\) can recover the observations of all terminals \(\mathcal{M}\):

\[R_{CO}^{\mathcal{A}} = \min \sum_{j \in \mathcal{M}} R_j \quad \text{s.t.} \quad \sum_{j \in \mathcal{B}} R_j \geq \H{X_\mathcal{B} \mid X_{\mathcal{B}^c}} \quad \forall\, \emptyset \neq \mathcal{B} \subsetneq \mathcal{M},\ \mathcal{A} \not\subseteq \mathcal{B}.\]
Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables observed by one terminal. If None, each random variable is its own terminal.

  • key_terminals (iterable of int, None) – Indices into rvs of the terminals that must become omniscient. If None, all terminals must.

  • crvs (list, None) – Random variables known to everyone, including the eavesdropper (e.g. those of compromised terminals); all entropies are conditioned on them.

Returns:

R_CO – The minimum communication rate for omniscience.

Return type:

float

Raises:

ditException – Raised if fewer than two key terminals are given, if key_terminals does not index into rvs, or if dist is symbolic.

one_way_skar(dist, X, Y, Z, niter=None, bound_u=None, bound_v=None, backend='numpy')[source]

Compute the secret key agreement rate constrained to one-way communication.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • X (iterable) – The indices to consider as the X variable, Alice.

  • Y (iterable) – The indices to consider as the Y variable, Bob.

  • Z (iterable) – The indices to consider as the Z variable, Eve.

  • niter (int, None) – The number of hops to perform during optimization.

  • bound_u (int, None) – The bound to use on the size of the variable U. If none, use the theoretical bound of |X|^2.

  • bound_v (int, None) – The bound to use on the size of the variable V. If none, use the theoretical bound of |X|.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

Returns:

owskar – The necessary intrinsic mutual information.

Return type:

float

ouroboros_mutual_information(dist, rvs=None, crvs=None, order=None)[source]

Compute the order-k ouroboros mutual information: the Kullback-Leibler divergence from the joint distribution to its normalized order-k ouroboros approximation.

The order-k ouroboros approximation of \(X_0, \ldots, X_{n-1}\) is the symmetric geometric mean, over all wirings in which each variable is the output of a channel fed by k other variables, of the resulting products of conditional distributions:

\[\tilde{p}_k(x) = \frac{\prod_{|S| = k+1} p(x_S)^{n / \binom{n}{k+1}}} {\prod_{|S| = k} p(x_S)^{n / \binom{n}{k}}}, \qquad 1 \leq k \leq n - 2.\]

With \(\hat{p}_k = \tilde{p}_k / Z\) the measure is \(O_k = D_{KL}(p \| \hat{p}_k)\). For three variables and k = 1 it coincides with the Kirkwood mutual information. For k = 1 the approximation is the \((n-1)\)-th root of the pairwise conditional composite likelihood [VRF11]. Since \(\hat{p}_k\) is log-linear in the \((k+1)\)-marginals, \(O_k\) upper bounds the divergence to the maximum entropy distribution matching those marginals.

No canonical literature source is known for this construction.

Parameters:
  • dist (Distribution) – The distribution from which the ouroboros mutual information is calculated.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used. If None, then all random variables are used.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

  • order (int, None) – The number of inputs k to each channel. Must satisfy 1 <= k <= n - 2. If None, defaults to n - 2.

Returns:

O – The ouroboros mutual information.

Return type:

float

Raises:

ditException – Raised if fewer than three variables are given or if order is out of range.

Examples

>>> d = dit.example_dists.giant_bit(4, 2)
>>> dit.multivariate.ouroboros_mutual_information(d, order=1)
0.0
>>> d = dit.example_dists.n_mod_m(4, 2)
>>> dit.multivariate.ouroboros_mutual_information(d)
1.0
pairwise_frustration(dist, rvs=None, max_nodes=20000, tol=1e-07)[source]

Compute the pairwise frustration, the order-2 frustration().

Parameters:
  • dist (Distribution) – The distribution from which the frustration is calculated.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables forming one variable of the pairwise model. If None, each random variable is its own variable.

  • max_nodes (int) – The maximum number of branch-and-bound nodes.

  • tol (float) – The optimality tolerance, in bits.

Returns:

F – The pairwise frustration.

Return type:

float

Examples

>>> w = dit.Distribution(['001', '010', '100'], [1/3] * 3)
>>> round(dit.multivariate.pairwise_frustration(w), 6)
0.666667
partial_entropy_spectrum(dist, rvs=None, definition='min')[source]

The partial entropy spectrum [Var24a]: the expected increments \(h^{syn}_{\alpha} - h^{syn}_{\alpha - 1}\) for \(\alpha = 1, \ldots, n\). They sum to the joint entropy.

Parameters:
Returns:

spectrum – The spectrum, in bits; entry k is \(\alpha = k + 1\).

Return type:

ndarray

partial_information_spectrum(dist, rvs, target, definition='min')[source]

The partial spectrum of \(I[X : Y]\) for inputs \(X\) = rvs and target \(Y\) [Var24a]: the expectation over \(y\) of the input spectrum minus the spectrum of \(X \mid Y = y\). It sums to the mutual information.

Parameters:
Returns:

spectrum – The spectrum, in bits; entry k is \(\alpha = k + 1\).

Return type:

ndarray

partial_kullback_leibler_spectrum(posterior, prior, rvs=None, definition='min')[source]

The partial spectrum of \(D_{KL}[\text{posterior} \| \text{prior}]\) [Var24a]: the posterior expectation of the prior’s local spectrum minus the posterior’s. It sums to the divergence.

Parameters:
  • posterior (Distribution) – The distributions; the posterior’s support must be within the prior’s.

  • prior (Distribution) – The distributions; the posterior’s support must be within the prior’s.

  • rvs (list, None) – The variables. If None, all of them.

  • definition ({'min', 'max', 'avg'}) – See alpha_synergistic_entropy().

Returns:

spectrum – The spectrum, in bits.

Return type:

ndarray

partial_total_correlation_spectrum(dist, rvs=None, definition='min')[source]

The partial spectrum of the total correlation [Var24a], i.e. partial_kullback_leibler_spectrum() against the product of the marginals.

Parameters:
Returns:

spectrum – The spectrum, in bits.

Return type:

ndarray

plot_maxent_function(dist, rvs=None, crvs=None, ax=None, **plot_kwargs)[source]

Plot the spectral Maximum Entropy Function value \(H(\phi_X(X))\) as a function of the threshold \(t\).

At each distinct threshold position on the second left singular vector \(u\) of \(Q = D_X^{-1/2} P D_Y^{-1/2}\), the binary function \(\phi_X(i) = \mathrm{sign}(u_i - t)\) (and similarly \(\phi_Y\) from the second right singular vector \(v\)) is constructed per Salamatian et al. 2016 §IV-A, and \(H(\phi_X(X))\) is plotted at each \(t\).

Parameters:
  • dist (Distribution) – The distribution from which to compute the curve.

  • rvs (list, None) – A list selecting exactly two random variables (by index or name). If None, all variables of dist are used; dist must therefore be bivariate.

  • crvs (list, None) – Not supported; passing a non-empty crvs raises ditException.

  • ax (matplotlib.axes.Axes, None) – The axis to draw on. A new figure and axis are created if None.

  • **plot_kwargs – Forwarded to matplotlib.axes.Axes.plot().

Returns:

ax – The axis containing the plot.

Return type:

matplotlib.axes.Axes

Raises:

ditException – If crvs is provided, rvs does not select exactly two variables, or the joint pmf is too degenerate for a spectral sweep (one of the alphabets has size < 2).

quax_synergy(dist, sources, target, crvs=None, niter=None, maxiter=1000, polish=1e-06, bound=None)[source]

Compute the synergistic information I_syn(sources -> target) as defined by Quax, Har-Shemesh & Sloot (2017).

Finds a Synergistic Random Variable (SRV) S that maximises I(S : X) subject to I(S : X_i) = 0 for each source X_i, then returns I(Y : S).

\[I_{\mathrm{syn}}(X \to Y) = \max_{S:\; I(S:X)>0,\; \forall i\, I(S:X_i)=0} I(Y : S)\]
Parameters:
  • dist (Distribution) – The joint distribution over sources and target.

  • sources (list of lists) – Each inner list gives the indices (or names) of one source variable group X_i.

  • target (list) – The indices (or names) of the target variable Y.

  • crvs (list, None) – Variables to condition on.

  • niter (int, None) – Number of basin-hopping restarts.

  • maxiter (int) – Maximum iterations per local optimisation.

  • polish (float, False) – If a float, perform a polishing pass zeroing probabilities below this threshold. If False, skip polishing.

  • bound (int, None) – Cardinality bound on S. If None, a theoretical bound is used.

Returns:

isyn – The synergistic information, in bits (before unit conversion).

Return type:

float

reduced_intrinsic_CAEKL_mutual_information(dist, rvs=None, crvs=None, niter=None, bounds=None, backend='numpy', rng=None)

Compute the reduced intrinsic CAEKL mutual information.

Parameters:
  • dist (Distribution) – The distribution to compute the reduced intrinsic CAEKL mutual information of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic CAEKL mutual information. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bounds ([int], None) – Bounds on the size of the auxiliary variable U. If None, use the theoretical bound. This is used to better sample smaller subspaces.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

reduced_intrinsic_caekl_mutual_information(dist, rvs=None, crvs=None, niter=None, bounds=None, backend='numpy', rng=None)

Compute the reduced intrinsic CAEKL mutual information.

Parameters:
  • dist (Distribution) – The distribution to compute the reduced intrinsic CAEKL mutual information of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic CAEKL mutual information. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bounds ([int], None) – Bounds on the size of the auxiliary variable U. If None, use the theoretical bound. This is used to better sample smaller subspaces.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

reduced_intrinsic_dual_total_correlation(dist, rvs=None, crvs=None, niter=None, bounds=None, backend='numpy', rng=None)

Compute the reduced intrinsic dual total correlation.

Parameters:
  • dist (Distribution) – The distribution to compute the reduced intrinsic dual total correlation of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic dual total correlation. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bounds ([int], None) – Bounds on the size of the auxiliary variable U. If None, use the theoretical bound. This is used to better sample smaller subspaces.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

reduced_intrinsic_mutual_information(dist, rvs=None, crvs=None, niter=None, bounds=None, backend='numpy', rng=None)

Compute the reduced intrinsic total correlation.

Parameters:
  • dist (Distribution) – The distribution to compute the reduced intrinsic total correlation of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic total correlation. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bounds ([int], None) – Bounds on the size of the auxiliary variable U. If None, use the theoretical bound. This is used to better sample smaller subspaces.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

reduced_intrinsic_total_correlation(dist, rvs=None, crvs=None, niter=None, bounds=None, backend='numpy', rng=None)

Compute the reduced intrinsic total correlation.

Parameters:
  • dist (Distribution) – The distribution to compute the reduced intrinsic total correlation of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic total correlation. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bounds ([int], None) – Bounds on the size of the auxiliary variable U. If None, use the theoretical bound. This is used to better sample smaller subspaces.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

relaxed_two_part_intrinsic_mutual_information(dist, rvs, crvs, niter=None, bounds=None, bound_zbar=None, backend='numpy')[source]

Compute the relaxed two-part intrinsic mutual information, an upper bound on the two-way secret key agreement rate that is never larger than the minimal intrinsic mutual information.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (list) – A list of two lists, the indices of X (Alice) and Y (Bob).

  • crvs (list) – The indices of Z (Eve).

  • niter (int, None) – The number of basin hops to perform.

  • bounds ([int], None) – Bounds on the size of J to sweep over. Each yields a valid upper bound, and the smallest is returned. If None, use (2, 3, 4, None), where None means |X||Y||Z|.

  • bound_zbar (int, None) – Bound on the size of the corrupted Z. If None, use |Z|.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

Returns:

rtpimi – The relaxed two-part intrinsic mutual information.

Return type:

float

residual_entropy(dist, rvs=None, crvs=None)[source]

Compute the residual entropy.

Parameters:
  • dist (Distribution) – The distribution from which the residual entropy is calculated.

  • rvs (list, None) – The indexes of the random variable used to calculate the residual entropy. If None, then the total correlation is calculated over all random variables.

  • crvs (list, None) – The indexes of the random variables to condition on. If None, then no variables are condition on.

Returns:

R – The residual entropy.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

s_information(dist, rvs=None, crvs=None)[source]

Computes the S-information, defined as the sum of the total correlation and the dual total correlation.

Parameters:
  • dist (Distribution) – The distribution from which the s-information is calculated.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the s-information. If None, then the s-information is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

Returns:

S – The s-information.

Return type:

float

Examples

>>> d = dit.example_dists.n_mod_m(5, 2)
>>> dit.multivariate.s_information(d)
5.0
Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

secrecy_capacity_skar(dist, rvs=None, crvs=None, niter=None, bound_u=None, backend='numpy')[source]

The rate at which X and Y can agree upon a key with Z eavesdropping, and no public communication.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (iterable of iterables, len(rvs) == 2) – The indices of the random variables agreeing upon a secret key.

  • crvs (iterable) – The indices of the eavesdropper.

  • niter (int, None) – The number of hops to perform during optimization.

  • bound_u (int, None) – The bound to use on the size of the variable U. If none, use the theoretical bound of |X|.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

Returns:

sc – The secrecy capacity.

Return type:

float

secret_key_capacity(dist, rvs=None, key_terminals=None, crvs=None)[source]

Compute the multiterminal secret key capacity of Csiszár and Narayan [CsiszarN04].

The terminals in key_terminals (the set \(\mathcal{A}\)) agree on a secret key using unlimited public discussion; the remaining terminals act as helpers and need not be kept ignorant of the key. The capacity is

\[C_{SK}^{\mathcal{A}} = \H{X_\mathcal{M}} - R_{CO}^{\mathcal{A}},\]

where \(R_{CO}^{\mathcal{A}}\) is the omniscience_rate(). When crvs is given, every entropy is conditioned on it, which yields the private key capacity with those variables revealed to the eavesdropper. When every terminal is a key terminal this equals the caekl_mutual_information().

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables observed by one terminal. If None, each random variable is its own terminal.

  • key_terminals (iterable of int, None) – Indices into rvs of the terminals that share the key. If None, all terminals share it.

  • crvs (list, None) – Random variables known to the eavesdropper (e.g. those of compromised terminals, which still cooperate in the protocol).

Returns:

C_SK – The secret key capacity.

Return type:

float

Raises:

ditException – Raised if fewer than two key terminals are given, if key_terminals does not index into rvs, or if dist is symbolic.

Examples

A helper who knows the xor of Alice’s and Bob’s independent bits lets them agree on one secret bit:

>>> d = dit.Distribution(['000', '011', '101', '110'], [1 / 4] * 4)
>>> secret_key_capacity(d, [[0], [1], [2]], key_terminals=[0, 1])
1.0
secret_key_cost(dist, rvs, crvs, niter=None, bound_u=None, bound_v=None, rng=None)[source]

Compute the secret key cost [Win05], also known as the information of formation [RW03]: the minimal rate of secret key Alice and Bob need to produce XY by local operations and public communication, such that Eve could simulate the public transcript from Z. It is

min I[XY : V | U] such that XY - Z - U and X - UV - Y

that is, the conditional Wyner common information C[X : Y | U] minimized over degradations U of Z. It is never less than the intrinsic mutual information [RW03], and never more than either C[X : Y] or C[X : Y | Z].

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (iterable of iterables, len(rvs) == 2) – The variables representing Alice and Bob.

  • crvs (iterable) – The variables representing Eve.

  • niter (int, None) – The number of basin hops to perform. If None, use 5.

  • bound_u (int, None) – Bound on the size of U. If None, use |Z| + 1.

  • bound_v (int, None) – Bound on the size of V. If None, use |X||Y|.

  • rng (int, np.random.Generator, None) – Source of randomness.

Returns:

skc – The secret key cost.

Return type:

float

self_synergy(dist, sources=None, alpha=None, niter=None, bound=None)[source]

Compute S_alpha(X -> X), the self-synergy of sources X.

When alpha is None, uses the full individual-source constraints alpha = {{0}, {1}, …, {n-1}}.

Parameters:
  • dist (Distribution) – The joint distribution over sources.

  • sources (list of lists, None) – The source variable groups. If None, each variable is its own group.

  • alpha (list of lists, None) – Constraint subgroups (source-list indices). If None, each individual source is constrained.

  • niter (int, None) – Number of basin-hopping restarts.

  • bound (int, None) – Cardinality bound on V.

Returns:

s_self – The self-synergy, in bits.

Return type:

float

stochastic_gk_common_information(dist, rvs=None, crvs=None, niter=None, maxiter=1000, polish=1e-06, bound=None)[source]

Compute the stochastic Gacs-Korner common information of dist. This is the maximum I(X_i; Z) over stochastic variables Z satisfying p(Z|X_i) = p(Z|X_j) for all jointly occurring (X_i, X_j). When Z is restricted to deterministic functions, this recovers the classical Gacs-Korner common information.

Parameters:
  • dist (Distribution) – The distribution from which the stochastic Gacs-Korner common information is computed.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the common information. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

Returns:

SGK – The stochastic Gacs-Korner common information.

Return type:

float

synergistic_disclosure(dist, sources, target, alpha, niter=None, bound=None)[source]

Compute S_alpha(X -> Y) for a single constraint set alpha.

This is the maximum I(V; Y) over all alpha-synergistic channels, i.e. channels p_{V|X} satisfying I(V; X_{alpha_i}) = 0 for each subgroup alpha_i in alpha.

Parameters:
  • dist (Distribution) – The joint distribution over sources and target.

  • sources (list of lists) – Each inner list gives the indices of one source variable group.

  • target (list) – The indices of the target variable.

  • alpha (list of lists) – Each inner list gives source-list indices (0-based) specifying which sources form each constraint subgroup.

  • niter (int, None) – Number of basin-hopping restarts.

  • bound (int, None) – Cardinality bound on V.

Returns:

s_alpha – The synergistic disclosure, in bits.

Return type:

float

synergistic_entropy(dist, rvs=None, crvs=None)[source]

Compute the synergistic entropy H(X_1 + X_2 + … + X_n).

How much more information the joint distribution provides beyond what the marginals can share:

H(X_1 + … + X_n) = H(X_1, …, X_n) - H(X_1 t … t X_n)

Equivalently: E[ h(x_1, …, x_n) - max(h(x_1), …, h(x_n)) ]

Parameters:
  • dist (Distribution) – The distribution from which the synergistic entropy is calculated.

  • rvs (list, None) – The random variable groups. If None, each variable is its own group.

  • crvs (list, None) – Variables to condition on (not supported; must be None or empty).

Returns:

Hs – The synergistic entropy.

Return type:

float

tension_common_information(dist, rvs=None, crvs=None, niter=None, maxiter=1000, bound=None)[source]

Compute the tension common information.

This is the portion of the dual total correlation that is not obstructed by tension,

\[\Theta(X_{0:n}) = B[X_{0:n}] - E(X_{0:n}),\]

a continuous relaxation of the Gacs-Korner common information obeying K <= Theta <= B [MR26a]. For a pair B is the mutual information.

Parameters:
  • dist (Distribution) – The distribution for which the tension common information is computed.

  • rvs (list of lists, None) – The source groups. If None, each variable of dist is its own source.

  • crvs (list, None) – A single list of indexes specifying variables to condition on. If None, none are conditioned on.

  • niter (int, None) – Number of basin hops to perform during the optimization.

  • maxiter (int) – The number of iterations of the optimization subroutine to perform.

  • bound (int, None) – Bound the size of the probe variable.

Returns:

Theta – The tension common information.

Return type:

float

Examples

Unlike the Gacs-Korner common information, this does not collapse when the block structure of the support is perturbed:

>>> from dit import Distribution
>>> from dit.multivariate import gk_common_information, tension_common_information
>>> blocks = Distribution(['00', '01', '10', '11', '22'], [0.2] * 5)
>>> float(gk_common_information(blocks))
0.7219280948873623
total_correlation(dist, rvs=None, crvs=None)[source]

Computes the total correlation, also known as either the multi-information or the integration.

Parameters:
  • dist (Distribution) – The distribution from which the total correlation is calculated.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the total correlation. If None, then the total correlation is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

Returns:

T – The total correlation.

Return type:

float

Examples

>>> d = dit.example_dists.Xor()
>>> dit.multivariate.total_correlation(d)
1.0
>>> dit.multivariate.total_correlation(d, rvs=[[0], [1]])
0.0
Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

transmission(dist, structure=None)[source]

Compute the transmission of dist relative to a marginal model: the Kullback-Leibler divergence from the data to the maximum entropy distribution reconstructed from the marginals in structure.

This is the decomposition error of reconstructability analysis. With Shannon entropy denoted by U, it equals U(model) - U(data): the constraint the model fails to capture. For the independence structure it reduces to the total correlation, and for the saturated structure (all variables together) it is zero.

Parameters:
  • dist (Distribution) – The distribution whose decomposition error is computed.

  • structure (list of lists, None) – The marginal model: a list of marginals (each a set of random variables, or “projection”) to hold fixed, e.g. [[0, 1], [1, 2]] for the structure AB:BC. If None, the independence model (each variable on its own) is used, recovering the total correlation.

Returns:

T – The transmission (decomposition error).

Return type:

float

Examples

>>> d = dit.example_dists.Xor()
>>> dit.multivariate.transmission(d)
1.0
>>> dit.multivariate.transmission(d, [[0, 1], [1, 2]])
1.0
>>> dit.multivariate.transmission(d, [[0, 1, 2]])
0.0
tse_complexity(dist, rvs=None, crvs=None)[source]

Calculates the TSE complexity.

Parameters:
  • dist (Distribution) – The distribution from which the TSE complexity is calculated.

  • rvs (list, None) – The indexes of the random variable used to calculate the TSE complexity between. If None, then the TSE complexity is calculated over all random variables.

  • crvs (list, None) – The indexes of the random variables to condition on. If None, then no variables are condition on.

Returns:

TSE – The TSE complexity.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

two_part_intrinsic_CAEKL_mutual_information(dist, rvs=None, crvs=None, niter=None, bound_j=None, bound_u=None, bound_v=None, backend='numpy', rng=None)

Compute the two-part intrinsic CAEKL mutual information.

Parameters:
  • dist (Distribution) – The distribution to compute the two-part intrinsic CAEKL mutual information of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic CAEKL mutual information. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bound_j (int, None) – Specifies a bound on the size of the J auxiliary random variable. If None, then the theoretical bound is used.

  • bound_u (int, None) – Specifies a bound on the size of the U auxiliary random variable. If None, then the theoretical bound is used.

  • bound_v (int, None) – Specifies a bound on the size of the V auxiliary random variable. If None, then the theoretical bound is used.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

two_part_intrinsic_caekl_mutual_information(dist, rvs=None, crvs=None, niter=None, bound_j=None, bound_u=None, bound_v=None, backend='numpy', rng=None)

Compute the two-part intrinsic CAEKL mutual information.

Parameters:
  • dist (Distribution) – The distribution to compute the two-part intrinsic CAEKL mutual information of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic CAEKL mutual information. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bound_j (int, None) – Specifies a bound on the size of the J auxiliary random variable. If None, then the theoretical bound is used.

  • bound_u (int, None) – Specifies a bound on the size of the U auxiliary random variable. If None, then the theoretical bound is used.

  • bound_v (int, None) – Specifies a bound on the size of the V auxiliary random variable. If None, then the theoretical bound is used.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

two_part_intrinsic_dual_total_correlation(dist, rvs=None, crvs=None, niter=None, bound_j=None, bound_u=None, bound_v=None, backend='numpy', rng=None)

Compute the two-part intrinsic dual total correlation.

Parameters:
  • dist (Distribution) – The distribution to compute the two-part intrinsic dual total correlation of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic dual total correlation. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bound_j (int, None) – Specifies a bound on the size of the J auxiliary random variable. If None, then the theoretical bound is used.

  • bound_u (int, None) – Specifies a bound on the size of the U auxiliary random variable. If None, then the theoretical bound is used.

  • bound_v (int, None) – Specifies a bound on the size of the V auxiliary random variable. If None, then the theoretical bound is used.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

two_part_intrinsic_mutual_information(dist, rvs=None, crvs=None, niter=None, bound_j=None, bound_u=None, bound_v=None, backend='numpy', rng=None)

Compute the two-part intrinsic total correlation.

Parameters:
  • dist (Distribution) – The distribution to compute the two-part intrinsic total correlation of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic total correlation. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bound_j (int, None) – Specifies a bound on the size of the J auxiliary random variable. If None, then the theoretical bound is used.

  • bound_u (int, None) – Specifies a bound on the size of the U auxiliary random variable. If None, then the theoretical bound is used.

  • bound_v (int, None) – Specifies a bound on the size of the V auxiliary random variable. If None, then the theoretical bound is used.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

two_part_intrinsic_total_correlation(dist, rvs=None, crvs=None, niter=None, bound_j=None, bound_u=None, bound_v=None, backend='numpy', rng=None)

Compute the two-part intrinsic total correlation.

Parameters:
  • dist (Distribution) – The distribution to compute the two-part intrinsic total correlation of.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the intrinsic total correlation. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list) – A single list of indexes specifying the random variables to condition on.

  • niter (int) – The number of optimization iterations to perform.

  • bound_j (int, None) – Specifies a bound on the size of the J auxiliary random variable. If None, then the theoretical bound is used.

  • bound_u (int, None) – Specifies a bound on the size of the U auxiliary random variable. If None, then the theoretical bound is used.

  • bound_v (int, None) – Specifies a bound on the size of the V auxiliary random variable. If None, then the theoretical bound is used.

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

two_way_skar(dist, rvs, crvs, backend='numpy')[source]

Compute the two way secret key agreement rate. Returns nan if it can not be definitively determined.

Parameters:
  • dist (Distribution) – The distribution of interest.

  • rvs (iterable) – The indices to consider as X (Alice) and Y (Bob).

  • crvs (iterable) – The indices to consider as Z (Eve).

  • backend (str) – The optimization backend. One of 'numpy' (default), 'jax', or 'torch'.

Returns:

skar – The two way secret key agreement rate.

Return type:

float

union_entropy(dist, rvs=None, crvs=None)[source]

Compute the union entropy H(X_1 t X_2 t … t X_n).

The expected surprise of the most surprising marginal realisation:

H(X_1 t … t X_n) = E[ max(h(x_1), …, h(x_n)) ]

Parameters:
  • dist (Distribution) – The distribution from which the union entropy is calculated.

  • rvs (list, None) – The random variable groups. If None, each variable is its own group.

  • crvs (list, None) – Variables to condition on (not supported; must be None or empty).

Returns:

Hu – The union entropy.

Return type:

float

unique_entropy(dist, rvs=None, crvs=None)[source]

Compute the unique entropy H(X_1 X_2).

How much more information the first rv group provides relative to the second, on average:

H(X Y) = H(X t Y) - H(Y) = E[ max(h(x) - h(y), 0) ]

Parameters:
  • dist (Distribution) – The distribution from which the unique entropy is calculated.

  • rvs (list, None) – Exactly two random variable groups [rv_a, rv_b]. Returns H(rv_a \ rv_b).

  • crvs (list, None) – Variables to condition on (not supported; must be None or empty).

Returns:

Hu – The unique entropy.

Return type:

float

Raises:

ValueError – If rvs does not contain exactly two groups.

upper_intrinsic_caekl_mutual_information(dist, rvs, crvs)[source]

Compute a trivial upper-bound on the secret key agreement rate.

Parameters:
  • dist (Distribution) – The distribution to compute the bound for.

  • rvs (iterable of iterables) – The variables representing the agents to agree upon a key.

  • crvs (iterable) – The variable representing the eavesdropper.

Returns:

ub – A lower-bound on the secret key agreement rate.

Return type:

float

upper_intrinsic_dual_total_correlation(dist, rvs, crvs)[source]

Compute a trivial upper-bound on the secret key agreement rate.

Parameters:
  • dist (Distribution) – The distribution to compute the bound for.

  • rvs (iterable of iterables) – The variables representing the agents to agree upon a key.

  • crvs (iterable) – The variable representing the eavesdropper.

Returns:

ub – A lower-bound on the secret key agreement rate.

Return type:

float

upper_intrinsic_mutual_information(dist, rvs, crvs)

Compute a trivial upper-bound on the secret key agreement rate.

Parameters:
  • dist (Distribution) – The distribution to compute the bound for.

  • rvs (iterable of iterables) – The variables representing the agents to agree upon a key.

  • crvs (iterable) – The variable representing the eavesdropper.

Returns:

ub – A lower-bound on the secret key agreement rate.

Return type:

float

upper_intrinsic_total_correlation(dist, rvs, crvs)[source]

Compute a trivial upper-bound on the secret key agreement rate.

Parameters:
  • dist (Distribution) – The distribution to compute the bound for.

  • rvs (iterable of iterables) – The variables representing the agents to agree upon a key.

  • crvs (iterable) – The variable representing the eavesdropper.

Returns:

ub – A lower-bound on the secret key agreement rate.

Return type:

float

variation_of_information(dist, rvs=None, crvs=None)

Compute the residual entropy.

Parameters:
  • dist (Distribution) – The distribution from which the residual entropy is calculated.

  • rvs (list, None) – The indexes of the random variable used to calculate the residual entropy. If None, then the total correlation is calculated over all random variables.

  • crvs (list, None) – The indexes of the random variables to condition on. If None, then no variables are condition on.

Returns:

R – The residual entropy.

Return type:

float

Raises:

ditException – Raised if dist is not a joint distribution or if rvs or crvs contain non-existant random variables.

wyner_common_information(dist, rvs=None, crvs=None, niter=None, maxiter=1000, polish=1e-06, bound=None, backend='numpy', rng=None)

Computes the wyner common information, min I[X:V] such that V renders all X_i independent.

Parameters:
  • dist (Distribution) – The distribution for which the wyner common information will be computed.

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the wyner common information. If None, then it is calculated over all random variables, which is equivalent to passing rvs=dist.rvs.

  • crvs (list, None) – A single list of indexes specifying the random variables to condition on. If None, then no variables are conditioned on.

  • niter (int > 0) – Number of basin hoppings to perform during the optimization.

  • maxiter (int > 0) – The number of iterations of the optimization subroutine to perform.

  • polish (False, float) – Whether to polish the result or not. If a float, this will perform a second optimization seeded with the result of the first, but with smaller tolerances and probabilities below polish set to 0. If False, don’t polish.

  • bound (int) – Bound the size of the Markov variable.

  • backend (str) – The optimization backend to use. One of 'numpy' (default), 'jax', or 'torch'.

  • rng (np.random.Generator, int, None) – Source of randomness for the optimizer.

Returns:

ci – The wyner common information.

Return type:

float