Here you can find the source of variance(double[] values)
Parameter | Description |
---|---|
values | the vector |
public static double variance(double[] values)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . j a v a 2s . c o m * Computes the sample variance of the elements of the vector. * @param values the vector * @return the sample variance of the elements of the vector */ public static double variance(double[] values) { if (values.length < 2) { return 0; } double mean = mean(values); double var = 0; for (double d : values) { var += (d - mean) * (d - mean); } return var / (values.length - 1); } /** * Computes average of the elements of the vector. * @param values the vector * @return the average of the elements of the vector */ public static double mean(double values[]) { double sum = 0; for (double value : values) sum += value; return sum / values.length; } /** * Computes average of the elements of the vector. * @param values the vector * @return the average of the elements of the vector */ public static double mean(int values[]) { double sum = 0; for (int value : values) sum += value; return sum / values.length; } }