Here you can find the source of variance(final List
Parameter | Description |
---|---|
list | the list |
public static double variance(final List<Double> list)
//package com.java2s; /*/* w ww . ja v a2s. c om*/ * Title: CloudSim Toolkit * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * * Copyright (c) 2009-2012, The University of Melbourne, Australia */ import java.util.List; public class Main { /** * Variance. * * @param list the list * @return the double */ public static double variance(final List<Double> list) { long n = 0; double mean = mean(list); double s = 0.0; for (double x : list) { n++; double delta = x - mean; mean += delta / n; s += delta * (x - mean); } // if you want to calculate std deviation // of a sample change this to (s/(n-1)) return s / (n - 1); } /** * Gets the average. * * @param list the list * * @return the average */ public static double mean(final List<Double> list) { double sum = 0; for (Double number : list) { sum += number; } return sum / list.size(); } }