Here you can find the source of std(long[] array)
Parameter | Description |
---|---|
array | Input array |
public static double std(long[] array)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Pablo Pavon-Marino. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl.html * * Contributors://from w ww . java 2 s .c o m * Pablo Pavon-Marino - Jose-Luis Izquierdo-Zaragoza, up to version 0.3.1 * Pablo Pavon-Marino - from version 0.4.0 onwards ******************************************************************************/ public class Main { /** * Returns the standard deviation of an array using the Welford's method. * * @param array Input array * @return Standard deviation * */ public static double std(long[] array) { if (array.length == 0) return 0; double M = 0.0; double S = 0.0; int k = 1; for (long value : array) { double tmpM = M; M += (value - tmpM) / k; S += (value - tmpM) * (value - M); k++; } return Math.sqrt(S / (k - 1)); } }