/// Integrate numerically stable over given log-space density and grid points. Uses the trapezoidal rule.
Integrate numerically stable over given log-space density and grid points. Uses the trapezoidal rule.
Integrate numerically stable over given log - space density and grid points . Uses the trapezoidal rule .
pub fn ln_trapezoidal_integrate_grid_exp<T, D>(mut density: D, grid: &[T]) -> LogProb
    where
        T: Copy + Add<Output = T> + Sub<Output = T> + Div<Output = T> + Mul<Output = T> + Float,
        D: FnMut(usize, T) -> LogProb,
        f64: From<T>,
    {
        let probs = grid
            .iter()
            .enumerate()
            .dropping(1)
            .map(|(i, v)| {
                LogProb(
                    *(density(i - 1, grid[i - 1]).ln_add_exp(density(i, *v))) - 2.0f64.ln()
                        + f64::from(*v - grid[i - 1]).ln(),
                )
            })
            .collect_vec();
        LogProb::ln_sum_exp(&probs)
    }
pub fn ln_trapezoidal_integrate_grid_exp < T , D > ( mut density : D , grid : & [ T ] ) -> LogProb where T : Copy + Add < Output = T > + Sub < Output = T > + Div < Output = T > + Mul < Output = T > + Float , D : FnMut ( usize , T ) -> LogProb , f64 : From < T > , { let probs = grid . iter ( ) . enumerate ( ) . dropping ( 1 ) . map ( | ( i , v ) | { LogProb ( * ( density ( i - 1 , grid [ i - 1 ] ) . ln_add_exp ( density ( i , * v ) ) ) - 2.0f64 . ln ( ) + f64 :: from ( * v - grid [ i - 1 ] ) . ln ( ) , ) } ) . collect_vec ( ) ; LogProb :: ln_sum_exp ( & probs ) }
Integrate numerically stable over given log-space density and grid points.
Integrate numerically stable over given log - space density and grid points .
density
D
grid
&[T]