pub fn ln_sum_exp(probs: &[LogProb]) -> LogProb {
        if probs.is_empty() {
            Self::ln_zero()
        } else {
            let mut pmax = probs[0];
            let mut imax = 0;
            for (i, &p) in probs.iter().enumerate().skip(1) {
                if p > pmax {
                    pmax = p;
                    imax = i;
                }
            }
            if pmax == Self::ln_zero() {
                Self::ln_zero()
            } else if *pmax == f64::INFINITY {
                LogProb(f64::INFINITY)
            } else {
                pmax + LogProb(
                    (probs
                        .iter()
                        .enumerate()
                        .filter_map(|(i, p)| {
                            if i == imax || *p == Self::ln_zero() {
                                None
                            } else {
                                Some((p - pmax).fastexp())
                            }
                        })
                        .sum::<f64>())
                    .ln_1p(),
                )
            }
        }
    }
/// Numerically stable sum of probabilities in log-space.
Numerically stable sum of probabilities in log-space.
Numerically stable sum of probabilities in log - space .
pub fn ln_sum_exp(probs: &[LogProb]) -> LogProb {
        if probs.is_empty() {
            Self::ln_zero()
        } else {
            let mut pmax = probs[0];
            let mut imax = 0;
            for (i, &p) in probs.iter().enumerate().skip(1) {
                if p > pmax {
                    pmax = p;
                    imax = i;
                }
            }
            if pmax == Self::ln_zero() {
                Self::ln_zero()
            } else if *pmax == f64::INFINITY {
                LogProb(f64::INFINITY)
            } else {
                pmax + LogProb(
                    (probs
                        .iter()
                        .enumerate()
                        .filter_map(|(i, p)| {
                            if i == imax || *p == Self::ln_zero() {
                                None
                            } else {
                                Some((p - pmax).fastexp())
                            }
                        })
                        .sum::<f64>())
                    .ln_1p(),
                )
            }
        }
    }
pub fn ln_sum_exp ( probs : & [ LogProb ] ) -> LogProb { if probs . is_empty ( ) { Self :: ln_zero ( ) } else { let mut pmax = probs [ 0 ] ; let mut imax = 0 ; for ( i , & p ) in probs . iter ( ) . enumerate ( ) . skip ( 1 ) { if p > pmax { pmax = p ; imax = i ; } } if pmax == Self :: ln_zero ( ) { Self :: ln_zero ( ) } else if * pmax == f64 :: INFINITY { LogProb ( f64 :: INFINITY ) } else { pmax + LogProb ( ( probs . iter ( ) . enumerate ( ) . filter_map ( | ( i , p ) | { if i == imax || * p == Self :: ln_zero ( ) { None } else { Some ( ( p - pmax ) . fastexp ( ) ) } } ) . sum :: < f64 > ( ) ) . ln_1p ( ) , ) } } }
Numerically stable sum of probabilities in log-space.
Numerically stable sum of probabilities in log - space .
probs
&[LogProb]
probs
&[LogProb]