Here you can find the source of stDev(final List
Parameter | Description |
---|---|
list | the list |
public static double stDev(final List<Double> list)
//package com.java2s; /*/* ww w. j a v a 2s. c o m*/ * 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 { /** * Gets the standard deviation. * * @param list the list * @return the double */ public static double stDev(final List<Double> list) { return Math.sqrt(variance(list)); } /** * 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(); } }