{ } Raw JSON

bundles / scipy latest / scipy / stats / _probability_distribution / _ProbabilityDistribution / logpmf

function

scipy.stats._probability_distribution:_ProbabilityDistribution.logpmf

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

Signature

def   logpmf ( self x / method = None )

Summary

Log of the probability mass function

Extended Summary

The probability mass function ("PMF"), denoted , is the probability that the random variable will assume the value .

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

logpmf accepts x for .

Parameters

x : array_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

out : array

The log-PMF evaluated at the argument x.

Notes

Suppose a discrete probability distribution has support over the integers . By definition of the support, the log-PMF evaluates to its minimum value of (i.e. ) for non-integral and for outside the support; i.e. for or .

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.

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.allclose(X.logpmf(5), np.log(X.pmf(5)))

See also

logcdf
pmf

Aliases

  • scipy.stats._distribution_infrastructure._ProbabilityDistribution.logpmf