Skip to main content

log_sum_exp

Function log_sum_exp 

Source
pub fn log_sum_exp(v: &[f64]) -> f64
Expand description

ln Σ_i e^{v_i} without overflow (the log domain of probabilities and LLRs).

§Examples

use comnum_math::log_sum_exp;
assert!((log_sum_exp(&[1000.0, 1000.0]) - (1000.0 + 2f64.ln())).abs() < 1e-9);
assert_eq!(log_sum_exp(&[]), f64::NEG_INFINITY);