Here you can find the source of standardDeviation(List
Parameter | Description |
---|---|
values | to calculate std dev for. |
mean | of the values. |
public static Double standardDeviation(List<Double> values, Double mean)
//package com.java2s; /**//from w w w . j av a 2 s . c o m * Copyright 5AM Solutions Inc, ESAC, ScenPro & SAIC * * Distributed under the OSI-approved BSD 3-Clause License. * See http://ncip.github.com/caintegrator/LICENSE.txt for details. */ import java.util.List; public class Main { /** * Calculates the standard deviation. * @param values to calculate std dev for. * @param mean of the values. * @return standard deviation. */ public static Double standardDeviation(List<Double> values, Double mean) { Double totalSquaredDeviations = 0.0; for (Double value : values) { totalSquaredDeviations += Math.pow(value - mean, 2); } return Math.sqrt(mean(totalSquaredDeviations, values.size())); } /** * Calculates the standard deviation. * @param values to calculate std dev for. * @param mean of the values. * @return standard deviation. */ public static Double standardDeviation(float[] values, float mean) { double totalSquaredDeviations = 0.0; for (float value : values) { totalSquaredDeviations += Math.pow(value - mean, 2); } return Math.sqrt(mean(totalSquaredDeviations, values.length)); } /** * Retrieves mean value of the list of floats. * * @param totalValue total value of the number. * @param numValues number of values. * @return mean value. */ public static Double mean(Double totalValue, int numValues) { return numValues != 0 ? totalValue / numValues : 0; } /** * Retrieves mean value of the list of floats. * * @param values of values. * @return mean value. */ public static float mean(float[] values) { float totalNumber = 0.0f; for (float value : values) { totalNumber += value; } return values.length == 0 ? 0 : totalNumber / values.length; } }