Java Array Variance variance(double m[], double[][] o)

Here you can find the source of variance(double m[], double[][] o)

Description

variance

License

Open Source License

Declaration

public static double[] variance(double m[], double[][] o) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    public static double[] variance(double m[], double[][] o) {
        int rows = o.length;
        int cols = o[0].length;

        double[] var = new double[m.length];
        Arrays.fill(var, 0.0);
        if (rows == 1) {
            return var;
        }/*  w  w  w .java2  s . c om*/

        for (double[] row : o) {

            assert (row.length == cols);

            for (int i = 0; i < cols; ++i) {
                var[i] += Math.pow(m[i] - row[i], 2.0);
            }
        }
        for (int i = 0; i < cols; i++) {
            var[i] /= (rows - 1);
        }

        return var;
    }
}

Related

  1. variance(double[] d, double mean)
  2. variance(double[] data, double meanVal)
  3. variance(double[][] x, double[] meanVector, boolean isAlongRows)