Java Standard Deviation Calculate computeStddev(float[] array, float mean)

Here you can find the source of computeStddev(float[] array, float mean)

Description

Computes the standard deviation given an array and its mean value

License

Open Source License

Parameter

Parameter Description
array the array
mean the mean value of the array

Return

the standard deviation

Declaration

public static float computeStddev(float[] array, float mean) 

Method Source Code

//package com.java2s;
/*/*from  w  w w.j  av  a  2 s.co m*/
 * Copyright (C) 2010-2014  Andreas Maier
 * CONRAD is developed as an Open Source project under the GNU General Public License (GPL).
*/

public class Main {
    /**
     * Computes the standard deviation given an array and its mean value
     * @param array the array
     * @param mean the mean value of the array
     * @return the standard deviation
     */
    public static float computeStddev(float[] array, float mean) {
        float stddev = 0;
        for (int i = 0; i < array.length; i++) {
            stddev += Math.pow(array[i] - mean, 2);
        }
        return (float) Math.sqrt(stddev / array.length);
    }

    public static float computeStddev(float[] array, float mean, int start, int end) {
        float stddev = 0;
        for (int i = start; i < end; i++) {
            stddev += Math.pow(array[i] - mean, 2);
        }
        return (float) Math.sqrt(stddev / (end - start));
    }

    /**
     * calls Math.pow for each element of the array
     * @param array
     * @param exp the exponent.
     * @return reference to the input array
     */
    public static float[] pow(float[] array, float exp) {
        for (int i = 0; i < array.length; i++) {
            array[i] = (float) Math.pow((double) array[i], exp);
        }
        return array;
    }
}

Related

  1. calcStdDeviation(double[] population)
  2. calcStdDeviation(int sampleCount, long total, long sumOfSquares)
  3. computeStddev(double[] array, double mean)
  4. computeStdDev(double[] results, double mean)