logpmf
- Binomial.logpmf(x, /, *, method=None)
Log of the probability mass function
The probability mass function (“PMF”), denoted , is the probability that the random variable will assume the value .
Log of the probability mass function
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 .
The argument of the log-PMF.
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.
The log-PMF evaluated at the argument x.
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.
Probability density function, Wikipedia, https://en.wikipedia.org/wiki/Probability_density_function
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