Crate logsumexp

source ·
Expand description

logsumexp

Numerically stable evaluation of ln(exp(a) + exp(b)) via the LogAddExp trait, and a numerically stable, 1-pass (online) algorithm for evaluation of LogSumExp via the LogSumExp trait.

Traits

  • A trait which, for the type on which it is implemented, provides numerically-stable evaluation of ln(exp(a) + exp(b)). The implementations provided for f64 (and &f64) and f32 (and &f32) utilize ln_1p_exp for maximum stability.
  • A trait for computing the log of the sum of exponentials of a sequence in a numerically-stable manner, using a 1-pass (online) algorithm based on Milakov, Maxim, and Natalia Gimelshein. “Online normalizer calculation for softmax.” (2018). In contrast to the version described in the reference, this algorithm correctly handles +/-infinity and nan values at any point in the sequence.