集册 Java实例教程 计算双数组的方差。

计算双数组的方差。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

540
计算双精度数组的方差。


//package com.nowjava;
/**
来 自 nowjava.com - 时  代  Java
**/


public class Main {



    /**

     * Compute the variance of the timeseries.

     * 

     * @param series The input timeseries.

     * @return the variance of values.

     */

    public static double var(double[] series) {

        double res = 0D;

        double mean = mean(series);

        for (int i = 0; i < series.length; i++) {

            res += (series[i] - mean) * (series[i] - mean);

        }

        return res / ((Integer) (series.length - 1)).doubleValue();

    }/** 时 代 J a v a 公 众 号 提 供 **/


    /**

     * Compute the mean of the timeseries.

     * 

     * @param series The input timeseries.

     * @return the mean of values.

     */

    public static double mean(double[] series) {

        double res = 0D;

        
展开阅读全文