Trait logprob::LogSumExp

source ·
pub trait LogSumExp: Iterator {
    // Provided methods
    fn log_sum_exp_no_alloc<T: Float + Ln2, L: Borrow<LogProb<T>>>(
        self
    ) -> Result<LogProb<T>, ProbabilitiesSumToGreaterThanOne>
       where Self: Sized + Iterator<Item = L> { ... }
    fn log_sum_exp_clamped_no_alloc<T: Float + Ln2, L: Borrow<LogProb<T>>>(
        self
    ) -> LogProb<T>
       where Self: Sized + Iterator<Item = L> { ... }
    fn log_sum_exp_float_no_alloc<T: Float + Ln2, L: Borrow<LogProb<T>>>(
        self
    ) -> T
       where Self: Sized + Iterator<Item = L> { ... }
    fn log_sum_exp<T: Float + Ln2 + Sum, L: Borrow<LogProb<T>>>(
        self
    ) -> Result<LogProb<T>, ProbabilitiesSumToGreaterThanOne>
       where Self: Sized + Iterator<Item = L> { ... }
    fn log_sum_exp_clamped<T: Float + Ln2 + Sum, L: Borrow<LogProb<T>>>(
        self
    ) -> LogProb<T>
       where Self: Sized + Iterator<Item = L> { ... }
    fn log_sum_exp_float<T: Float + Ln2 + Sum, L: Borrow<LogProb<T>>>(self) -> T
       where Self: Sized + Iterator<Item = L> { ... }
}
Expand description

This trait allows iterators to have LogSumExp.

Provided Methods§

source

fn log_sum_exp_no_alloc<T: Float + Ln2, L: Borrow<LogProb<T>>>( self ) -> Result<LogProb<T>, ProbabilitiesSumToGreaterThanOne>
where Self: Sized + Iterator<Item = L>,

Adds up an iterator of LogProb (as raw probabilities) and returns a new Result<LogProb, ProbabilitiesSumToGreaterThanOne>. Will only return Ok if the sum could be a valid LogProb. It does not allocate a vector.

source

fn log_sum_exp_clamped_no_alloc<T: Float + Ln2, L: Borrow<LogProb<T>>>( self ) -> LogProb<T>
where Self: Sized + Iterator<Item = L>,

Adds up an iterator of LogProb (as raw probabilities) and returns a new LogProb clamping values greater than 0.0. Will only return Ok if the sum could be a valid LogProb. It does not allocate a vector and will often be faster than log_sum_exp_clamped if you expect there to be clamping as the iterator can short-circuit.

source

fn log_sum_exp_float_no_alloc<T: Float + Ln2, L: Borrow<LogProb<T>>>(self) -> T
where Self: Sized + Iterator<Item = L>,

Adds up an iterator of LogProb (as raw probabilities) and returns a float with their sum, regardless of if it would be a valid LogProb. It does not allocate a vector.

source

fn log_sum_exp<T: Float + Ln2 + Sum, L: Borrow<LogProb<T>>>( self ) -> Result<LogProb<T>, ProbabilitiesSumToGreaterThanOne>
where Self: Sized + Iterator<Item = L>,

Adds up an iterator of LogProb (as raw probabilities) and returns a new Result<LogProb, ProbabilitiesSumToGreaterThanOne>. Will only return Ok if the sum could be a valid LogProb. It does allocate a vector, but will usually be faster for n>10.

source

fn log_sum_exp_clamped<T: Float + Ln2 + Sum, L: Borrow<LogProb<T>>>( self ) -> LogProb<T>
where Self: Sized + Iterator<Item = L>,

Adds up an iterator of LogProb (as raw probabilities) and returns a float with their sum, regardless of if it would be a valid LogProb. It does allocate a vector, but is usally slower than Self::log_sum_exp_clamped_no_alloc if you expect clamping.

source

fn log_sum_exp_float<T: Float + Ln2 + Sum, L: Borrow<LogProb<T>>>(self) -> T
where Self: Sized + Iterator<Item = L>,

Adds up an iterator of LogProb (as raw probabilities) and returns a float with their sum, regardless of if it would be a valid LogProb. It does allocate a vector, but will usually be faster for n>10.

Implementors§

source§

impl<I> LogSumExp for I
where I: Iterator + ?Sized,