pub fn weighted_std(values: &[f64], log_weights: &[f64]) -> f64Expand description
Compute the self-normalised importance-weighted standard deviation of
values.
Uses the same SNIS weights as weighted_mean to estimate
$$\hat{\sigma} = \sqrt{\frac{\sum_i w_i (x_i - \hat{\mu})^2}{\sum_i w_i}}$$
This is the weighted population standard deviation (not the unbiased sample estimate), which is appropriate for summarising an importance- sampling posterior.
§Panics
Panics if values and log_weights have different lengths.
§Examples
use ferric::weighted_std;
// Population std of [1, 2, 3] with uniform weights is sqrt(2/3).
let values = vec![1.0_f64, 2.0, 3.0];
let log_weights = vec![0.0_f64; 3];
let std = weighted_std(&values, &log_weights);
assert!((std - (2.0_f64 / 3.0).sqrt()).abs() < 1e-10);