Module stability

Module stability 

Source
Expand description

Numerical stability improvements

§Numerical Stability Improvements

This module provides numerically stable implementations of common algorithms that are prone to precision loss, overflow, or catastrophic cancellation.

§Features

  • Stable summation algorithms (Kahan, pairwise, compensated)
  • Robust variance and standard deviation calculations
  • Overflow-resistant multiplication and exponentiation
  • Stable trigonometric range reduction
  • Robust normalization techniques
  • Improved root finding with bracketing
  • Stable matrix condition number estimation

Structs§

KahanSum
Kahan summation algorithm for accurate floating-point summation
WelfordVariance
Welford’s online algorithm for computing variance

Enums§

MatrixNorm
Matrix norm types

Traits§

StableComputation
Trait for numerically stable computations

Functions§

binomial_stable
Stable computation of binomial coefficients
condition_number_estimate
Condition number estimation using 1-norm
cross_entropy_stable
Cross entropy loss with numerical stability
expm1_stable
Stable computation of exp(x) - 1 for small x
factorial_stable
Numerically stable factorial computation
hypot_stable
Stable computation of sqrt(x² + y²) avoiding overflow
log1p_stable
Stable computation of log(1 + x) for small x
log_sigmoid_stable
Numerically stable log-sigmoid function
log_sum_exp
Log-sum-exp trick for stable computation of log(sum(exp(x)))
mulmod_stable
Stable computation of (a*b) % m avoiding overflow
neumaier_sum
Neumaier summation algorithm (improved Kahan summation)
pairwise_sum
Pairwise summation algorithm
reduce_angle
Stable angle reduction for trigonometric functions
sigmoid_stable
Numerically stable sigmoid function
stable_mean
Stable mean calculation using compensated summation
stable_norm_2
Stable L2 norm computation avoiding overflow/underflow
stable_softmax
Stable softmax computation
stable_variance
Stable two-pass algorithm for variance calculation
stablematrix_norm
Stable matrix norm computation