dit.other

Esoteric measures of information, typically fairly divorced from Shannon’s measures.

Functions

LMPR_complexity

Compute the LMPR complexity.

conditional_cumulative_residual_entropy

Returns the conditional cumulative residual entropy.

conditional_generalized_cumulative_residual_entropy

Returns the conditional cumulative residual entropy.

cumulative_residual_entropy

The cumulative residual entropy is an alternative to the Shannon differential entropy with several desirable properties including non-negativity.

disequilibrium

Compute the (normalized) disequilibrium as measured the Jensen-Shannon divergence from an equilibrium distribution.

extropy

Returns the extropy J[X] over the random variables in rvs.

generalized_cumulative_residual_entropy

The generalized cumulative residual entropy is a generalized from of the cumulative residual entropy.

lautum_information

Computes the lautum information.

maximal_leakage

Maximal leakage from X to Y.

negentropy

Compute the negentropy of a distribution.

perplexity

renyi_entropy

Compute the Renyi entropy of order order.

sibson_conditional_mutual_information_y_given_z

Conditional Sibson MI minimizing over Q_{Y|Z} (Esposito et al., Def.

sibson_conditional_mutual_information_z

Conditional Sibson MI minimizing over Q_Z (Esposito et al., Def.

sibson_mutual_information

Compute the Sibson mutual information of order order.

sibson_mutual_information_pmf

Compute the Sibson mutual information of order order.

tsallis_entropy

Compute the Tsallis entropy of order order.

Reference

LMPR_complexity(dist, rvs=None)[source]

Compute the LMPR complexity.

Parameters:
  • dist (Distribution) – Distribution to compute the LMPR complexity of.

  • rvs (list, None) – The indexes of the random variable used to calculate the LMPR complexity. If None, then the LMPR complexity is calculated over all variables. This should remain None for scalar distributions.

Returns:

C – The LMPR complexity.

Return type:

float

conditional_cumulative_residual_entropy(dist, rv, crvs=None)[source]

Returns the conditional cumulative residual entropy.

Parameters:
  • dist (Distribution) – The distribution to compute the conditional cumulative residual entropy of.

  • rv (list, None) – The possibly joint random variable to compute the conditional cumulative residual entropy of. If None, then all variables not in crvs are used.

  • crvs (list, None) – The random variables to condition on. If None, nothing is conditioned on.

Returns:

CCRE – The conditional cumulative residual entropy.

Return type:

Distribution

Examples

>>> from itertools import product
>>> events = [ (a, b) for a, b, in product(range(5), range(5)) if a <= b ]
>>> probs = [ 1/(5-a)/5 for a, b in events ]
>>> d = Distribution(events, probs)
>>> print(conditional_cumulative_residual_entropy(d, 1, [0]))
Class:    Distribution
Alphabet: (-0.0, 0.5, 0.91829583405448956, 1.3112781244591329, 1.6928786893420307)
Base:     linear

x p(x) -0.0 0.2 0.5 0.2 0.918295834054 0.2 1.31127812446 0.2 1.69287868934 0.2

conditional_generalized_cumulative_residual_entropy(dist, rv, crvs=None)[source]

Returns the conditional cumulative residual entropy.

Parameters:
  • dist (Distribution) – The distribution to compute the conditional generalized cumulative residual entropy of.

  • rv (list, None) – The possibly joint random variable to compute the conditional generalized cumulative residual entropy of. If None, then all variables not in crvs are used.

  • crvs (list, None) – The random variables to condition on. If None, nothing is conditioned on.

Returns:

CCRE – The conditional cumulative residual entropy.

Return type:

Distribution

Examples

>>> from itertools import product
>>> events = [ (a-2, b-2) for a, b, in product(range(5), range(5)) if a <= b ]
>>> probs = [ 1/(3-a)/5 for a, b in events ]
>>> d = Distribution(events, probs)
>>> print(conditional_generalized_cumulative_residual_entropy(d, 1, [0]))
Class:    Distribution
Alphabet: (-0.0, 0.5, 0.91829583405448956, 1.3112781244591329, 1.6928786893420307)
Base:     linear

x p(x) -0.0 0.2 0.5 0.2 0.918295834054 0.2 1.31127812446 0.2 1.69287868934 0.2

cumulative_residual_entropy(dist, extract=False)[source]

The cumulative residual entropy is an alternative to the Shannon differential entropy with several desirable properties including non-negativity.

Parameters:
  • dist (Distribution) – The distribution to compute the cumulative residual entropy of each index for.

  • extract (bool) – If True and dist.outcome_length() is 1, return the single GCRE value rather than a length-1 array.

Returns:

CREs – The cumulative residual entropy for each index.

Return type:

ndarray

Examples

>>> d1 = Distribution([1, 2, 3, 4, 5, 6], [1/6]*6)
>>> d2 = Distribution([1, 2, 3, 4, 5, 100], [1/6]*6)
>>> cumulative_residual_entropy(d1)
2.0683182557028439
>>> cumulative_residual_entropy(d2)
42.566064100334294
disequilibrium(dist, rvs=None)[source]

Compute the (normalized) disequilibrium as measured the Jensen-Shannon divergence from an equilibrium distribution.

Parameters:
  • dist (Distribution) – Distribution to compute the disequilibrium of.

  • rvs (list, None) – The indexes of the random variable used to calculate the diseqilibrium. If None, then the disequilibrium is calculated over all random variables. This should remain None for scalar distributions.

Returns:

D – The disequilibrium.

Return type:

float

extropy(dist, rvs=None)[source]

Returns the extropy J[X] over the random variables in rvs.

If the distribution represents linear probabilities, then the extropy is calculated with units of ‘bits’ (base-2).

Parameters:
  • dist (Distribution or float) – The distribution from which the extropy is calculated. If a float, then we calculate the binary extropy.

  • rvs (list, None) – The indexes of the random variable used to calculate the extropy. If None, then the extropy is calculated over all random variables. This should remain None for scalar distributions.

Returns:

J – The extropy of the distribution.

Return type:

float

generalized_cumulative_residual_entropy(dist, extract=False)[source]

The generalized cumulative residual entropy is a generalized from of the cumulative residual entropy. Rather than integrating from 0 to infinity over the absolute value of the CDF.

Parameters:
  • dist (Distribution) – The distribution to compute the generalized cumulative residual entropy of each index for.

  • extract (bool) – If True and dist.outcome_length() is 1, return the single GCRE value rather than a length-1 array.

Returns:

GCREs – The generalized cumulative residual entropy for each index.

Return type:

ndarray

Examples

>>> generalized_cumulative_residual_entropy(uniform(-2, 3))
1.6928786893420307
>>> generalized_cumulative_residual_entropy(uniform(0, 5))
1.6928786893420307
lautum_information(dist, rvs=None, crvs=None)[source]

Computes the lautum information.

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

  • rvs (list, None) – A list of lists. Each inner list specifies the indexes of the random variables used to calculate the lautum information. If None, then the lautum 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:

L – The lautum information.

Return type:

float

Examples

>>> outcomes = ['000', '001', '010', '011', '100', '101', '110', '111']
>>> pmf = [3/16, 1/16, 1/16, 3/16, 1/16, 3/16, 3/16, 1/16]
>>> d = dit.Distribution(outcomes, pmf)
>>> dit.other.lautum_information(d)
0.20751874963942196
>>> dit.other.lautum_information(d, rvs=[[0], [1]])
0.0
Raises:

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

maximal_leakage(dist, rvs_X, rvs_Y)[source]

Maximal leakage from X to Y.

Equivalent to Sibson mutual information of order infinity.

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

  • rvs_X (list) – Indexes of the source random variables.

  • rvs_Y (list) – Indexes of the observed random variables.

Returns:

L – Maximal leakage in bits.

Return type:

float

negentropy(dist, rvs=None)[source]

Compute the negentropy of a distribution.

The negentropy is the difference between the entropy of a uniform distribution over the same alphabet and the entropy of the distribution itself. It is a non-negative quantity which is zero if and only if the distribution is uniform, and quantifies how far the distribution is from uniformity.

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

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

Returns:

N – The negentropy.

Return type:

float

Examples

>>> d = dit.example_dists.Xor()
>>> dit.other.negentropy(d)
1.0
Raises:

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

perplexity(dist, rvs=None, crvs=None)[source]
Parameters:
  • dist (Distribution) – The distribution from which the perplexity is calculated.

  • rvs (list, None) – The indexes of the random variable used to calculate the perplexity. If None, then the perpelxity 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:

P – The perplexity.

Return type:

float

renyi_entropy(dist, order, rvs=None)[source]

Compute the Renyi entropy of order order.

Parameters:
  • dist (Distribution) – The distribution to take the Renyi entropy of.

  • order (float >= 0) – The order of the Renyi entropy.

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

Returns:

H_a – The Renyi entropy.

Return type:

float

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

  • ValueError – Raised if order is not a non-negative float.

sibson_conditional_mutual_information_y_given_z(dist, rvs_X, rvs_Y, rvs_Z, order)[source]

Conditional Sibson MI minimizing over Q_{Y|Z} (Esposito et al., Def. 3).

Reduces to unconditional Sibson MI when Z is constant (Esposito et al., Def. 3).

Parameters:
  • dist (Distribution) – The joint distribution over X, Y, and Z.

  • rvs_X (list) – Indexes defining each variable group.

  • rvs_Y (list) – Indexes defining each variable group.

  • rvs_Z (list) – Indexes defining each variable group.

  • order (float > 0) – The order alpha.

Returns:

I_a – Conditional Sibson mutual information in bits.

Return type:

float

sibson_conditional_mutual_information_z(dist, rvs_X, rvs_Y, rvs_Z, order)[source]

Conditional Sibson MI minimizing over Q_Z (Esposito et al., Def. 4).

Symmetric in X and Y.

Parameters:
  • dist (Distribution) – The joint distribution over X, Y, and Z.

  • rvs_X (list) – Indexes defining each variable group.

  • rvs_Y (list) – Indexes defining each variable group.

  • rvs_Z (list) – Indexes defining each variable group.

  • order (float > 0) – The order alpha.

Returns:

I_a – Conditional Sibson mutual information in bits.

Return type:

float

sibson_mutual_information(dist, rvs_X, rvs_Y, order)[source]

Compute the Sibson mutual information of order order.

This is asymmetric in (X, Y): rvs_X is the source variable whose marginal appears in the definition (Wu et al., Verdu).

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

  • rvs_X (list) – Indexes of the random variables defining X.

  • rvs_Y (list) – Indexes of the random variables defining Y.

  • order (float > 0) – The order alpha.

Returns:

I_a – Sibson mutual information in bits.

Return type:

float

Raises:

ValueError – If order is not positive.

sibson_mutual_information_pmf(p_xy, order)[source]

Compute the Sibson mutual information of order order.

Parameters:
  • p_xy (array_like, shape (n_x, n_y)) – Joint PMF with axis 0 indexing X and axis 1 indexing Y.

  • order (float > 0) – The order alpha. Use 1 for Shannon MI and numpy.inf for maximal leakage.

Returns:

I_a – Sibson mutual information in bits.

Return type:

float

Raises:

ValueError – If order is not positive.

tsallis_entropy(dist, order, rvs=None)[source]

Compute the Tsallis entropy of order order.

Parameters:
  • dist (Distribution) – The distribution to take the Tsallis entropy of.

  • order (float >= 0) – The order of the Tsallis entropy.

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

Returns:

S_q – The Tsallis entropy.

Return type:

float

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

  • ValueError – Raised if order is not a non-negative float.