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

# logpmf

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

  Log of the probability mass function

  The probability mass function (“PMF”), denoted \(f(x)\), is the probability that the random variable \(X\) will assume the value \(x\).

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

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

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

  Parameters:
    xarray_like

      The argument of the log-PMF.

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

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

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

      - `'logexp'`: evaluate the PMF 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:
    outarray

      The log-PMF evaluated at the argument x.

  See also

  `pmf`
  `logcdf`

  Notes

  Suppose a discrete probability distribution has support over the integers \({l, l+1, ..., r-1, r}\). By definition of the support, the log-PMF evaluates to its minimum value of \(-\infty\) (i.e. \(\log(0)\)) for non-integral \(x\) and for \(x\) outside the support; i.e. for \(x < l\) or \(x > r\).

  For distributions with infinite support, it is common for `pmf` to return a value of `0` when the argument is theoretically within the support; this can occur because the true value of the PMF is too small to be represented by the chosen dtype. The log-PMF, 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.

  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.Binomial(n=10, p=0.5)

  Evaluate the log-PMF at the desired argument:

      >>> X.logpmf(5)
      np.float64(-1.4020427180880297)
      >>> np.allclose(X.logpmf(5), np.log(X.pmf(5)))
      True