pub fn ln_sub_exp(self, other: LogProb) -> LogProb {
        if other == Self::ln_zero() {
            self
        } else {
            let (p0, p1) = (self, other);
            assert!(
                p0 >= p1,
                "Subtraction would lead to negative probability, which is undefined in log space."
            );
            if *p1 == f64::NEG_INFINITY {
                p0
            } else if relative_eq!(*p0, *p1) || p0 == Self::ln_zero() {
                // the first case leads to zero,
                // in the second case p0 and p1 are -inf, which is fine
                Self::ln_zero()
            } else if *p0 == f64::INFINITY {
                LogProb(f64::INFINITY)
            } else {
                p0 + (p1 - p0).ln_one_minus_exp()
            }
        }
    }
/// Numerically stable subtraction of probabilities in log-space.
Numerically stable subtraction of probabilities in log-space.
Numerically stable subtraction of probabilities in log - space .
pub fn ln_sub_exp(self, other: LogProb) -> LogProb {
        if other == Self::ln_zero() {
            self
        } else {
            let (p0, p1) = (self, other);
            assert!(
                p0 >= p1,
                "Subtraction would lead to negative probability, which is undefined in log space."
            );
            if *p1 == f64::NEG_INFINITY {
                p0
            } else if relative_eq!(*p0, *p1) || p0 == Self::ln_zero() {
                // the first case leads to zero,
                // in the second case p0 and p1 are -inf, which is fine
                Self::ln_zero()
            } else if *p0 == f64::INFINITY {
                LogProb(f64::INFINITY)
            } else {
                p0 + (p1 - p0).ln_one_minus_exp()
            }
        }
    }
pub fn ln_sub_exp ( self , other : LogProb ) -> LogProb { if other == Self :: ln_zero ( ) { self } else { let ( p0 , p1 ) = ( self , other ) ; assert ! ( p0 p1 " " ) ; if * p1 == f64 :: NEG_INFINITY { p0 } else if relative_eq ! ( p0 p1 ) || p0 == Self :: ln_zero ( ) { // the first case leads to zero, // in the second case p0 and p1 are -inf, which is fine Self :: ln_zero ( ) } else if * p0 == f64 :: INFINITY { LogProb ( f64 :: INFINITY ) } else { p0 + ( p1 - p0 ) . ln_one_minus_exp ( ) } } }
Numerically stable subtraction of probabilities in log-space.
Numerically stable subtraction of probabilities in log - space .
self
other
LogProb
self
other
LogProb