List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics setWindowSize
public void setWindowSize(int windowSize) throws MathIllegalArgumentException
From source file:com.candy.algo.SMA.java
public static double[] Sma(double inputs[], int windowSize) { // Get a DescriptiveStatistics instance DescriptiveStatistics stats = new DescriptiveStatistics(); stats.setWindowSize(windowSize); double[] sma = new double[inputs.length]; for (int i = 0; i < inputs.length; i++) { stats.addValue(inputs[i]);/*ww w . jav a 2 s . co m*/ if (i >= (windowSize - 1)) sma[i] = stats.getMean(); else sma[i] = Double.NaN; } return sma; }
From source file:org.mot.common.math.CalculatorFactory.java
public Double getAverage(Double[] data, Integer windowSize) { // Create a DescriptiveStats instance and set the window size to 100 DescriptiveStatistics stats = new DescriptiveStatistics(); stats.setWindowSize(windowSize); for (int i = 0; i < data.length; i++) { if (data[i] != null) { stats.addValue(data[i]);/*from w ww . j av a2s. com*/ } else { break; } } return stats.getMean(); }
From source file:org.mot.common.math.CalculatorFactory.java
public Double getTimeWindowDeviation(Number[] data, Integer windowSize) { // Create a DescriptiveStats instance and set the window size to 100 DescriptiveStatistics stats = new DescriptiveStatistics(); stats.setWindowSize(windowSize); if (windowSize == 0) { windowSize = data.length;/*w w w. java2 s . c om*/ } for (int i = 0; i < data.length; i++) { if (data[i] != null) { stats.addValue((Double) data[i]); } else { break; } } return stats.getStandardDeviation(); }