Java List Mean standardDeviation(List values, Double mean)

Here you can find the source of standardDeviation(List values, Double mean)

Description

Calculates the standard deviation.

License

BSD License

Parameter

Parameter Description
values to calculate std dev for.
mean of the values.

Return

standard deviation.

Declaration

public static Double standardDeviation(List<Double> values, Double mean) 

Method Source Code

//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;
    }
}

Related

  1. mean(List numbers)
  2. meanAbsolute(List vector)
  3. meanDouble(List list)
  4. meanDoubleList(List list)
  5. normalizeFromMeanAndStdev(List values, double mean, double stdev)