Expand description
Functions for computing in the log domain without overflow or cancellation (SciPy’s
logsumexp, softmax, log_softmax, logit, expit, log_expit, log_ndtr), and the
Box-Cox power transforms (boxcox, boxcox1p, inv_boxcox).
See the book entry Log-domain functions and inverse incomplete integrals.
Functions§
- boxcox
- The Box-Cox transform
(x^λ − 1)/λ, andln xforλ = 0(SciPy’sspecial.boxcox), written withexp_m1so that it is continuous and accurate nearλ = 0. - boxcox1p
- The Box-Cox transform of
1 + x, accurate for smallx(SciPy’sboxcox1p). - expit
- The logistic sigmoid
1 / (1 + e^{−x}), evaluated so that neither branch overflows. - inv_
boxcox - The inverse of
boxcox:(1 + λy)^{1/λ}, ande^yforλ = 0. - log_
expit ln expit(x) = −ln(1 + e^{−x}), accurate for large|x|.- log_
ndtr - The logarithm of the standard normal CDF,
ln Φ(x)(SciPy’slog_ndtr), accurate in both tails: forx > −1asln(1 − Φ(−x))withln_1p; for−20 < x ≤ −1fromerfc, which is accurate relative to its tiny value; below that from the asymptotic seriesln Φ(x) = −x²/2 − ln(−x) − ½ ln 2π + ln(1 − 1/x² + 3/x⁴ − 15/x⁶ + …). - log_
softmax aᵢ − logsumexp(a), the logarithm ofsoftmaxwithout underflow.- logit
- The log-odds
ln(p / (1 − p)), the inverse ofexpit. - logsumexp
ln Σ exp(aᵢ)without overflow (SciPy’slogsumexp): withm = max aᵢ, the sum ism + ln Σ exp(aᵢ − m), whose terms are at most 1. Returns−∞for an empty slice or when every term is−∞, and+∞if any term is+∞.- logsumexp_
weighted ln |Σ bᵢ exp(aᵢ)|and the sign of the sum, for weights of either sign (SciPy’slogsumexpwithbandreturn_sign=True). The log is−∞with sign 0 when the sum is zero.- softmax
exp(aᵢ) / Σ exp(aⱼ), computed asexp(aᵢ − logsumexp(a)).