Here you can find the source of meanAndStandardDeviation(final double[] inp, final int startIndex, final int pastEnd)
Parameter | Description |
---|---|
inp | floating point input array |
startIndex | the first index to average |
pastEnd | the index just past the last one to average |
private static double[] meanAndStandardDeviation(final double[] inp, final int startIndex, final int pastEnd)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w.j ava 2 s. c om*/ * Calculates the mean and standard deviation of an array of double * * @param inp floating point input array * @param startIndex the first index to average * @param pastEnd the index just past the last one to average * @return {mean, standardDeviation} */ private static double[] meanAndStandardDeviation(final double[] inp, final int startIndex, final int pastEnd) { if (startIndex < 0) throw new IllegalArgumentException("startIndex must be >= 0"); if (pastEnd > inp.length) throw new IllegalArgumentException( "pastEnd must be <= inp.length"); if (startIndex >= pastEnd) throw new IllegalArgumentException( "pastEnd must be > startIndex"); double sum_y = 0.0; double sum_ymean = 0.0; double total = pastEnd - startIndex; for (int i = startIndex; i < pastEnd; ++i) sum_y += inp[i]; double local_mean = sum_y / total; for (int i = startIndex; i < pastEnd; ++i) { double y = inp[i] - local_mean; sum_ymean += (y * y); } double std_dev = Math.sqrt(sum_ymean / total); return new double[] { local_mean, std_dev }; } }