scipy.special.log_expit#
- scipy.special.log_expit(x) = <ufunc 'log_expit'>#
Logarithm of the logistic sigmoid function.
The SciPy implementation of the logistic sigmoid function is
scipy.special.expit
, so this function is calledlog_expit
.The function is mathematically equivalent to
log(expit(x))
, but is formulated to avoid loss of precision for inputs with large (positive or negative) magnitude.- Parameters
- xarray_like
The values to apply
log_expit
to element-wise.
- Returns
- outndarray
The computed values, an ndarray of the same shape as
x
.
See also
Notes
As a ufunc,
log_expit
takes a number of optional keyword arguments. For more information see ufuncsNew in version 1.8.0.
Examples
>>> from scipy.special import log_expit, expit
>>> log_expit([-3.0, 0.25, 2.5, 5.0]) array([-3.04858735, -0.57593942, -0.07888973, -0.00671535])
Large negative values:
>>> log_expit([-100, -500, -1000]) array([ -100., -500., -1000.])
Note that
expit(-1000)
returns 0, so the naive implementationlog(expit(-1000))
return-inf
.Large positive values:
>>> log_expit([29, 120, 400]) array([-2.54366565e-013, -7.66764807e-053, -1.91516960e-174])
Compare that to the naive implementation:
>>> np.log(expit([29, 120, 400])) array([-2.54463117e-13, 0.00000000e+00, 0.00000000e+00])
The first value is accurate to only 3 digits, and the larger inputs lose all precision and return 0.