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

# ilogcdf

Normal.ilogcdf(logp, /, *, method=None)

  Inverse of the logarithm of the cumulative distribution function.

  The inverse of the logarithm of the cumulative distribution function (“inverse log-CDF”) is the argument \(x\) for which the logarithm of the cumulative distribution function \(\log(F(x))\) evaluates to \(\log(p)\).

  Mathematically, it is equivalent to \(F^{-1}(\exp(y))\), where \(y = \log(p)\), but it may be numerically favorable compared to the naive implementation (computing \(p = \exp(y)\), then \(F^{-1}(p)\)).

  `ilogcdf` accepts logp for \(\log(p) ≤ 0\).

  Parameters:
    logp array_like

      The argument of the inverse log-CDF.

    method{None, ‘formula’, ‘complement’, ‘inversion’}

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

      - `'formula'`: use a formula for the inverse log-CDF itself

      - `'complement'`: evaluate the inverse log-CCDF at the logarithmic complement of logp (see Notes)

      - `'inversion'`: solve numerically for the argument at which the log-CDF is equal to logp

      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 inverse log-CDF evaluated at the provided argument.

  See also

  `icdf`
  `logcdf`

  Notes

  Suppose a probability distribution has support \([l, r]\). The inverse log-CDF returns its minimum value of \(l\) at \(\log(p) = \log(0) = -\infty\) and its maximum value of \(r\) at \(\log(p) = \log(1) = 0\). Because the log-CDF has range \([-\infty, 0]\), the inverse log-CDF is only defined on the negative reals; for \(\log(p) > 0\), `ilogcdf` returns `nan`.

  Occasionally, it is needed to find the argument of the CDF for which the resulting probability is very close to `0` or `1` - too close to represent accurately with floating point arithmetic. In many cases, however, the logarithm of this resulting probability may be represented in floating point arithmetic, in which case this function may be used to find the argument of the CDF for which the logarithm of the resulting probability is \(y = \log(p)\).

  The “logarithmic complement” of a number \(z\) is mathematically equivalent to \(\log(1-\exp(z))\), but it is computed to avoid loss of precision when \(\exp(z)\) is nearly \(0\) or \(1\).

  Examples

  Instantiate a distribution with the desired parameters:

      >>> import numpy as np
      >>> from scipy import stats
      >>> X = stats.Uniform(a=-0.5, b=0.5)

  Evaluate the inverse log-CDF at the desired argument:

      >>> X.ilogcdf(-0.25)
      0.2788007830714034
      >>> np.allclose(X.ilogcdf(-0.25), X.icdf(np.exp(-0.25)))
      True