{ } Raw JSON

bundles / scipy 1.17.1 / scipy / stats / _probability_distribution / _ProbabilityDistribution / logentropy

function

scipy.stats._probability_distribution:_ProbabilityDistribution.logentropy

source: /scipy/stats/_probability_distribution.py :1818

Signature

def   logentropy ( self * method )

Summary

Logarithm of the differential entropy

Extended Summary

In terms of probability density function and support , the differential entropy (or simply "entropy") of a continuous random variable is:

The definition for a discrete random variable is analogous, with the PMF replacing the PDF and a sum over the support replacing the integral.

logentropy computes the logarithm of the differential entropy ("log-entropy"), , but it may be numerically favorable compared to the naive implementation (computing then taking the logarithm).

Parameters

method : {None, 'formula', 'logexp', 'quadrature}

The strategy used to evaluate the log-entropy. By default (None), the infrastructure chooses between the following options, listed in order of precedence.

  • 'formula': use a formula for the log-entropy itself

  • 'logexp': evaluate the entropy and take the logarithm

  • 'quadrature': numerically log-integrate (or, in the discrete case, log-sum) the logarithm of the entropy integrand (summand)

Not all method options are available for all distributions. If the selected method is not available, a NotImplementedError will be raised.

Returns

out : array

The log-entropy.

Notes

The differential entropy of a continuous distribution can be negative. In this case, the log-entropy is complex with imaginary part . For consistency, the result of this function always has complex dtype, regardless of the value of the imaginary part.

Examples

Instantiate a distribution with the desired parameters:
import numpy as np
from scipy import stats
X = stats.Uniform(a=-1., b=1.)
Evaluate the log-entropy:
X.logentropy()
np.allclose(np.exp(X.logentropy()), X.entropy())
For a random variable with negative entropy, the log-entropy has an imaginary part equal to `np.pi`.
X = stats.Uniform(a=-.1, b=.1)
X.entropy(), X.logentropy()

See also

entropy
logpdf

Aliases

  • scipy.stats._distribution_infrastructure._ProbabilityDistribution.logentropy