Here you can find the source of std(final double[] vec)
Parameter | Description |
---|---|
vec | the vector to compute the standard deviation of |
vec
public static double std(final double[] vec)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w . j a v a2 s .c o m*/ * Computes the standard deviation of the given values, that is the square * root of the sample variance. * @param vec the vector to compute the standard deviation of * @return the standard deviation of <code>vec</code> */ public static double std(final double[] vec) { assert vec != null; return Math.sqrt(var(vec)); } /** * Computes the sample variance of the given values, that is the quadratic * deviation from mean. * @param vec the vector to compute the variance of * @return the variance of <code>vec</code> */ public static double var(final double[] vec) { assert vec != null; if (vec.length == 1) { return 0.; } final double mean = mean(vec); double var = 0; for (double d : vec) { var += (d - mean) * (d - mean); } var /= (vec.length - 1); return var; } /** * Computes the mean of the elements of a vector. * @param vec the vector. * @return the mean of the elements of the vector. */ public static double mean(final double[] vec) { assert vec != null; return sum(vec) / vec.length; } /** * Computes the sum of the elements of a vector. * @param array the array, to be summed. * @return the sum of the elements of the vector. */ public static double sum(final double[] vec) { assert vec != null; double s = 0; for (double i : vec) { s += i; } return s; } }