Skip to main content

bayesian_update

Function bayesian_update 

Source
pub fn bayesian_update(
    prior: f64,
    likelihood: f64,
    evidence: f64,
) -> StatsResult<f64>
Expand description

Computes prior * likelihood / evidence and validates the posterior.

Every argument and the result must be a probability in 0.0..=1.0, and evidence must be nonzero.

ยงExamples

use sim_lib_numbers_stats::bayesian_update;

let posterior = bayesian_update(0.2, 0.75, 0.3).unwrap();
assert!((posterior - 0.5).abs() < 1e-12);