LogSumExp

Trait LogSumExp 

Source
pub trait LogSumExp {
    type Output;

    // Required method
    fn ln_sum_exp(self) -> Self::Output;
}
Expand description

A trait for computing ln_sum_exp

Required Associated Types§

Source

type Output

The result of the computation

Required Methods§

Source

fn ln_sum_exp(self) -> Self::Output

Compute the log of the sum of exponentials

This computes the same value value as self.map(|v| v.exp()).sum().ln() but in a more numerically stable way then computing it using that formula. This is also slightly more stable then doing self.reduce(|a, b| a.ln_add_exp(b)).

§Examples
use logaddexp::LogSumExp;
[1.0, 2.0, 4.0].into_iter().ln_sum_exp();

Implementors§

Source§

impl<T> LogSumExp for T
where T: Iterator + Clone, T::Item: Float + FloatConst,