Java stddev std(final double[] x, final int begin, final int end)

Here you can find the source of std(final double[] x, final int begin, final int end)

Description

std

License

Open Source License

Declaration

public static double std(final double[] x, final int begin, final int end) 

Method Source Code

//package com.java2s;
/**/*  w w w . j  a va2s.c  o m*/
 * Copyright? 2014-2016 LIST (Luxembourg Institute of Science and Technology), all right reserved.
 * Authorship : Olivier PARISOT, Yoanne DIDRY
 * Licensed under GNU General Public License version 3
 */

public class Main {
    public static double std(final double[] x, final int begin, final int end) {
        int N = 0;
        double mean = 0d;
        for (int i = Math.max(0, begin); i < Math.min(x.length - 1, end); i++) {
            mean += x[i];
            N++;
        }
        mean /= N;

        double std = 0d;
        for (int i = Math.max(0, begin); i < Math.min(x.length - 1, end); i++) {
            std += (x[i] - mean) * (x[i] - mean);
        }

        return Math.sqrt(std / N);
    }

    public static double std(final double[] x) {
        final int N = x.length;

        final double avg = avg(x);

        double std = 0;
        for (int i = 0; i < N; i++) {
            std += (x[i] - avg) * (x[i] - avg);
        }

        return Math.sqrt(std / N);
    }

    public static double avg(final double... values) {
        return sum(values) / values.length;
    }

    public static double sum(final double... values) {
        double result = 0d;
        for (final double value : values)
            result += value;
        return result;
    }

    public static long sum(final long... values) {
        long result = 0;
        for (final long value : values)
            result += value;
        return result;
    }
}

Related

  1. std(double a[])
  2. std(double[] a)
  3. std(double[] arr)
  4. std(double[] array)
  5. std(final double[] vec)
  6. std(float[][] arr)
  7. std(long[] array)
  8. stdarr(int[] a, double avg)
  9. stddev(Collection a)