Here you can find the source of stdInt(List
Parameter | Description |
---|---|
iNumbers | - integers |
public static Double stdInt(List<Integer> elements)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { /**/*from ww w .j a v a 2 s. c o m*/ * * @param iNumbers - integers * @return the standard deviation */ public static Double stdInt(List<Integer> elements) { List<Double> doubles = new ArrayList<Double>(elements.size()); for (Integer n : elements) { doubles.add(new Double(n)); } return std(doubles); } /** * * @param iNumbers - doubles * @return the standard deviation */ public static double std(List<Double> iNumbers) { double result = 0; double mu = average(iNumbers); for (Double number : iNumbers) result += Math.pow(number - mu, 2); result /= iNumbers.size(); return Math.sqrt(result); } /** * * @param iNumbers - doubles * @param mu - the average * @return the standard deviation */ public static double std(List<Double> iNumbers, double mu) { double result = 0; for (Double number : iNumbers) result += Math.pow(number - mu, 2); result /= iNumbers.size(); return Math.sqrt(result); } /** * * @param numbers - doubles * @return their average */ public static double average(List<Double> numbers) { double sum = 0; for (Double number : numbers) sum += number; return sum / numbers.size(); } }