Skip to main content
`Ctrl`+`K`
scipy.stats.Binomial.

# logentropy

Binomial.logentropy(*, method=None)

  Logarithm of the differential entropy

  In terms of probability density function \(f(x)\) and support \(\chi\), the differential entropy (or simply “entropy”) of a continuous random variable \(X\) is:

  \[h(X) = - \int_{\chi} f(x) \log f(x) dx\]

  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”), \(\log(h(X))\), but it may be numerically favorable compared to the naive implementation (computing \(h(X)\) 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.

  See also

  `entropy`
  `logpdf`

  Notes

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

  References

  [1]

  Differential entropy, Wikipedia, https://en.wikipedia.org/wiki/Differential_entropy

  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()
      (-0.3665129205816642+0j)
      >>> np.allclose(np.exp(X.logentropy()), X.entropy())
      True

  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()
      (-1.6094379124341007, (0.4758849953271105+3.141592653589793j))