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

# logpdf

Mixture.logpdf(x, /, *, method=None)

  Log of the probability density function

  The probability density function (“PDF”), denoted \(f(x)\), is the probability per unit length that the random variable will assume the value \(x\). Mathematically, it can be defined as the derivative of the cumulative distribution function \(F(x)\):

  \[f(x) = \frac{d}{dx} F(x)\]

  `logpdf` computes the logarithm of the probability density function (“log-PDF”), \(\log(f(x))\), but it may be numerically favorable compared to the naive implementation (computing \(f(x)\) and taking the logarithm).

  `logpdf` accepts x for \(x\).

  Parameters:
    x array_like

      The argument of the log-PDF.

    method{None, ‘formula’, ‘logexp’}

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

      - `'formula'`: use a formula for the log-PDF itself

      - `'logexp'`: evaluate the PDF and takes its logarithm

      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-PDF evaluated at the argument x.

  See also

  `pdf`
  `logcdf`

  Notes

  Suppose a continuous probability distribution has support \([l, r]\). By definition of the support, the log-PDF evaluates to its minimum value of \(-\infty\) (i.e. \(\log(0)\)) outside the support; i.e. for \(x < l\) or \(x > r\). The maximum of the log-PDF may be less than or greater than \(\log(1) = 0\) because the maximum of the PDF can be any positive real.

  For distributions with infinite support, it is common for `pdf` to return a value of `0` when the argument is theoretically within the support; this can occur because the true value of the PDF is too small to be represented by the chosen dtype. The log-PDF, however, will often be finite (not `-inf`) over a much larger domain. Consequently, it may be preferred to work with the logarithms of probabilities and probability densities to avoid underflow.

  For discrete distributions, `logpdf` returns `inf` at supported points and `-inf` (`log(0)`) elsewhere.

  References

  [1]

  Probability density function, Wikipedia, https://en.wikipedia.org/wiki/Probability_density_function

  Examples

  Instantiate a distribution with the desired parameters:

      >>> import numpy as np
      >>> from scipy import stats
      >>> X = stats.Uniform(a=-1.0, b=1.0)

  Evaluate the log-PDF at the desired argument:

      >>> X.logpdf(0.5)
      -0.6931471805599453
      >>> np.allclose(X.logpdf(0.5), np.log(X.pdf(0.5)))
      True