Java mean stdDeviation(int[] values, double mean)

Here you can find the source of stdDeviation(int[] values, double mean)

Description

std Deviation

License

Open Source License

Declaration

public static double stdDeviation(int[] values, double mean) 

Method Source Code

//package com.java2s;
/*//  w ww  .ja va2 s  . c o m
 * Copyright 2007 Luis Rodero Merino.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Luis Rodero Merino if you need additional information or
 * have any questions. Contact information:
 * Email: lrodero AT gsyc.es
 * Webpage: http://gsyc.es/~lrodero
 * Phone: +34 91 488 8107; Fax: +34 91 +34 91 664 7494
 * Postal address: Desp. 121, Departamental II,
 *                 Universidad Rey Juan Carlos
 *                 C/Tulip?n s/n, 28933, M?stoles, Spain 
 *       
 */

public class Main {
    public static double stdDeviation(int[] values, double mean) {

        // Computing standar deviation
        double sum = 0.0;
        for (int index = 0; index < values.length; index++)
            sum += (mean - values[index]) * (mean - values[index]);

        return Math.sqrt(sum / values.length);
    }

    public static double stdDeviation(int[] values) {

        double mean = mean(values);

        // Computing standar deviation
        double sum = 0.0;
        for (int index = 0; index < values.length; index++)
            sum += (mean - values[index]) * (mean - values[index]);

        return Math.sqrt(sum / values.length);
    }

    public static double mean(int[] values) {

        // Computing mean
        double sum = 0.0;
        for (int index = 0; index < values.length; index++)
            sum += values[index];

        return sum / values.length;
    }
}

Related

  1. meanWithoutZeros(int[] in, int x1, int x2)
  2. meanWithoutZerosCentered(int[] in, int center, int width)
  3. std(double[] a, double mean, boolean isUnbiasedEstimator)
  4. std(double[] a, int size, double mean)
  5. std(double[] array, double mean)
  6. stdDevsOfRows(double[][] matrix, double[] means)
  7. stdev(final double[] values, final double mean)
  8. stdevm(double[] values, double mean)