Here you can find the source of std(Collection
Parameter | Description |
---|---|
dist | a parameter |
populationStd | a parameter |
public static Double std(Collection<Double> dist, boolean populationStd)
//package com.java2s; import java.util.Collection; import java.util.List; public class Main { /**//from w ww . ja v a 2 s . co m * * @param stdSum * @param count * @param populationStd * @return */ public static double std(double stdSum, int count, boolean populationStd) { return populationStd ? count > 0 ? Math.sqrt(stdSum / count) : null : count - 1 > 0 ? Math.sqrt(stdSum / (count - 1)) : null; } /** * * @param dist * @param populationStd * @return */ public static Double std(Collection<Double> dist, boolean populationStd) { return std(mean(dist), dist, populationStd); } /** * * @param mean * @param dist * @param populationStd * @return */ public static Double std(Double mean, Collection<Double> dist, boolean populationStd) { if (dist != null && !dist.isEmpty()) { mean = mean == null ? mean(dist) : mean; //First compute the mean if it's null double sum = 0d; int count = 0; if (mean != null) { for (Double val : dist) { if (val != null) { sum += Math.pow(val - mean, 2); count++; } } return populationStd ? count > 0 ? Math.sqrt(sum / count) : null : count - 1 > 0 ? Math.sqrt(sum / (count - 1)) : null; } } return null; } /** * @param sums * @param count */ public static void mean(List<Double> sums, int count) { if (sums != null && !sums.isEmpty()) { for (int i = 0; i < sums.size(); i++) { sums.set(i, sums.get(i) / count); } } } /** * * @param sum * @param count * @return */ public static double mean(double sum, int count) { return count > 0 ? sum / count : null; } /** * * @param dist * @return */ public static Double mean(Collection<Double> dist) { if (dist != null && !dist.isEmpty()) { double sum = 0d; int count = 0; for (Double val : dist) { if (val != null) { sum += val; count++; } } return count > 0 ? sum / count : null; } return null; } }