Expand description
crate::probability → distributional primitives now in gam-math.
Functions§
- erfcx_
nonnegative - Scaled complementary error function
erfcx(x) = exp(x²) · erfc(x), specialized tox ≥ 0. Returns1.0forx ≤ 0and0.0forx = +∞. For0 < x < 26uses the directexp(x²)·erfc(x)form; beyond that the (otherwise overflowing)exp(x²)is replaced by a 4-term asymptotic expansion(1/(x√π))·(1 − 1/(2x²) + 3/(4x⁴) − …), keeping relative accuracy near machine epsilon. The non-negative restriction lets the caller skip the reflection identity. - log1mexp_
positive - Computes
log(1 - exp(-a))fora >= 0without cancellation. - normal_
cdf - Standard normal CDF Phi(x) evaluated via the exact special-function identity
- normal_
logcdf - Numerically stable
ln Φ(x)for the standard normal CDF. Forx ≥ 0computesln(Φ(x))directly with a small floor against underflow; forx < 0rewritesln Φ(x) = −u² + ln(½·erfcx(u)),u = −x/√2, which preserves digits all the way into the deep left tail (noln(0)). Returns±∞andNaNat the corresponding inputs. - normal_
logsf - Numerically stable
ln(1 − Φ(x)) = ln Φ(−x)for the standard normal survival function. Delegates tonormal_logcdf(-x)so the deep-right tail benefits from the sameerfcx-based representation. - normal_
pdf - Standard normal PDF phi(x).
- signed_
log_ sum_ exp - Numerically stable signed log-sum-exp. Given pairs
(log|aⱼ|, sign(aⱼ))(withsigns[j] ∈ {−1, 0, +1}), returns(log|S|, sign(S))forS = Σⱼ signs[j]·exp(log_mags[j]). Positive and negative magnitudes are reduced separately with the standard log-sum-exp trick (subtract the max, sum, log, add back); the two partial sums are then combined vialog(|p − n|) = max(log p, log n) + log1mexp(|log p − log n|), preserving accuracy even whenp ≈ n(catastrophic cancellation regime). When all signs are zero or all magnitudes are−∞, returns(NEG_INFINITY, 0.0). - signed_
probit_ logcdf_ and_ mills_ ratio - Joint evaluation of
ln Φ(x)and the Mills-ratio analogueφ(x) / Φ(x), signed for the symmetric branch. Used by the latent probit families where the inverse-link gradient needs the ratio and the likelihood needs the log-CDF on the samex; computing both in one call shares theerfcxevaluation that dominates the cost in the deep tail. - standard_
normal_ quantile - Standard normal quantile Φ⁻¹(p) using Acklam’s rational approximation.