df_maths/
stats.rs

1use std::fmt::Display;
2
3/// 样本偏差值
4pub fn stddev<T: Display + std::fmt::Debug>(array: Vec<T>) -> f64 {
5    let len = array.len();
6    if len <= 1 {
7        return 0.0;
8    }
9    let mut total = 0.0;
10    let mut values = vec![];
11    for item in array {
12        let value = item.to_string().parse::<f64>().unwrap();
13        values.push(value);
14        total += value;
15    }
16    let mean = total / len.to_string().parse::<f64>().unwrap();
17    total = 0.0;
18    let _: Vec<f64> = values.iter_mut().map(|val| {
19        let t = (*val - mean).powi(2);
20        total += t;
21        t
22    }).collect();
23    (total / (len - 1) as f64).sqrt()
24}
25
26/// 统计过程控制
27/// Statistical Process Control
28pub struct Spc {}
29
30impl Spc {
31
32}