Java stddev std(double[] arr)

Here you can find the source of std(double[] arr)

Description

std

License

Open Source License

Declaration

public static double std(double[] arr) 

Method Source Code

//package com.java2s;
/*****************************************************************************
  Util.java/*from   w  w  w .  j  av a2  s. co m*/
    
  (c) 2008-2013 - Alan Boyle
  Department of Genetics
  Stanford University
  aboyle@gmail.com
    
  Licensed under the GNU General Public License 3.0 license.
    
  This file is part of F-seq.
    
  F-seq is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
    
  F-seq 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 for more details.
    
  You should have received a copy of the GNU General Public License
  along with F-seq.  If not, see <http://www.gnu.org/licenses/>.
    
******************************************************************************/

public class Main {
    public static double std(double[] arr) {
        double m = mean(arr);
        double sum = 0.0;
        for (int i = 0; i < arr.length; ++i) {
            sum += Math.pow(arr[i] - m, 2);
        }
        return Math.sqrt(sum / arr.length);
    }

    public static double mean(double[] arr) {
        double sum = 0.0;
        for (int i = 0; i < arr.length; ++i)
            sum += arr[i];
        return sum / arr.length;
    }
}

Related

  1. standardDeviation(double[] data)
  2. standardDeviation(double[] data, int opt)
  3. std(Collection dist, boolean populationStd)
  4. std(double a[])
  5. std(double[] a)
  6. std(double[] array)
  7. std(final double[] vec)
  8. std(final double[] x, final int begin, final int end)
  9. std(float[][] arr)