pub fn variance_simd<F>(a: &ArrayView1<'_, F>) -> Fwhere
F: Float + SimdUnifiedOps,Expand description
SIMD-accelerated variance computation
Computes the sample variance: Var(x) = sum((x - mean)²) / (n-1) Uses Bessel’s correction for unbiased estimation.
§Arguments
a- Input array
§Returns
Sample variance of the array
§Examples
use scirs2_core::ndarray::array;
use scirs2_core::ndarray_ext::elementwise::variance_simd;
let x = array![2.0_f64, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0];
let var = variance_simd::<f64>(&x.view());
// Sample variance: sum of squared deviations = 32, n = 8
// var = 32 / (8-1) = 32/7 ≈ 4.571
let expected = 32.0 / 7.0;
assert!((var - expected).abs() < 1e-10);§Use Cases
- Statistical analysis
- Quality control (process capability)
- Risk assessment (financial variance)
- Feature scaling (standardization)