bundles / scipy 1.17.1 / scipy / stats / _probability_distribution / _ProbabilityDistribution / logpmf
function
scipy.stats._probability_distribution:_ProbabilityDistribution.logpmf
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_likeThe 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
methodoptions are available for all distributions. If the selectedmethodis not available, aNotImplementedErrorwill be raised.
Returns
out: arrayThe 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)✓
X.logpmf(5)
✗np.allclose(X.logpmf(5), np.log(X.pmf(5)))
✓See also
Aliases
-
scipy.stats._distribution_infrastructure._ProbabilityDistribution.logpmf