bundles / scipy 1.17.1 / scipy / stats / _probability_distribution / _ProbabilityDistribution / logpdf
function
scipy.stats._probability_distribution:_ProbabilityDistribution.logpdf
Signature
def logpdf ( self , x , / , method ) Summary
Log of the probability density function
Extended Summary
The probability density function ("PDF"), denoted , is the probability per unit length that the random variable will assume the value . Mathematically, it can be defined as the derivative of the cumulative distribution function :
logpdf computes the logarithm of the probability density function ("log-PDF"), , but it may be numerically favorable compared to the naive implementation (computing and taking the logarithm).
logpdf accepts x for .
Parameters
x: array_likeThe 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
methodoptions are available for all distributions. If the selectedmethodis not available, aNotImplementedErrorwill be raised.
Returns
out: arrayThe log-PDF evaluated at the argument
x.
Notes
Suppose a continuous probability distribution has support . By definition of the support, the log-PDF evaluates to its minimum value of (i.e. ) outside the support; i.e. for or . The maximum of the log-PDF may be less than or greater than 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.
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)✓
X.logpdf(0.5)
✗np.allclose(X.logpdf(0.5), np.log(X.pdf(0.5)))
✓See also
Aliases
-
scipy.stats._distribution_infrastructure._ProbabilityDistribution.logpdf