package com.gyee.common.util.algorithm;/*
@author   谢生杰
@date   2023/3/15-11:04
*/

public class MathUtils {

    //标准差σ=sqrt(s^2)
    public static double standardDiviation(Double[] x) {
        int m = x.length;
        double sum = 0;
        for (int i = 0; i < m; i++) {//求和
            sum += x[i];
        }
        double dAve = sum / m;//求平均值
        double dVar = 0;
        for (int i = 0; i < m; i++) {//求方差
            dVar += (x[i] - dAve) * (x[i] - dAve);
        }
        //reture Math.sqrt(dVar/(m-1));
        return Math.sqrt(dVar / m);
    }
}
