dit.shannon

The basic forms of Shannon’s information measures.

Functions

conditional_entropy

Returns the conditional entropy of H[X|Y].

entropy

Returns the entropy H[X] over the random variables in rvs.

entropy_pmf

Returns the entropy of the probability mass function.

mutual_information

Returns the mutual information I[X:Y].

Reference

conditional_entropy(dist, rvs_X, rvs_Y)[source]

Returns the conditional entropy of H[X|Y].

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

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

  • rvs_X (list, None) – The indexes of the random variables defining X.

  • rvs_Y (list, None) – The indexes of the random variables defining Y.

Returns:

H_XgY – The conditional entropy H[X|Y].

Return type:

float

entropy(dist, rvs=None)[source]

Returns the entropy H[X] over the random variables in rvs.

If the distribution represents linear probabilities, then the entropy is calculated with units of ‘bits’ (base-2). Otherwise, the entropy is calculated in whatever base that matches the distribution’s pmf.

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

  • 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. This should remain None for scalar distributions.

Returns:

H – The entropy of the distribution.

Return type:

float

entropy_pmf(pmf)[source]

Returns the entropy of the probability mass function.

Assumption: Linearly distributed probabilities.

Parameters:

pmf (NumPy array, shape (k,) or (n,k)) – Returns the entropy over the last index.

mutual_information(dist, rvs_X, rvs_Y)[source]

Returns the mutual information I[X:Y].

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

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

  • rvs_X (list, None) – The indexes of the random variables defining X.

  • rvs_Y (list, None) – The indexes of the random variables defining Y.

Returns:

I – The mutual information I[X:Y].

Return type:

float