TimeSeriesUtil { public static double variance(final double[] t) { double mean = mean(t); double squaredDeviations = 0; for (int i = 0; i < t.length; i++) { squaredDeviations += (t[i] - mean) * (t[i] - mean); } return squaredDeviations / t.length; } private  TimeSeriesUtil(); static boolean isTimeSeries(final INDArray... array); static boolean isTimeSeries(final int length, final INDArray... array); static boolean isTimeSeries(final int length, final double[]... array); static void isTimeSeriesOrException(final INDArray... array); static void isTimeSeriesOrException(final int length, final INDArray... array); static void isTimeSeriesOrException(final int length, final double[]... array); static boolean isSameLength(final INDArray timeSeries1, final INDArray... timeSeries); static boolean isSameLength(final double[] timeSeries1, final double[]... timeSeries); static void isSameLengthOrException(final INDArray timeSeries1, final INDArray... timeSeries); static void isSameLengthOrException(final double[] timeSeries1, final double[]... timeSeries); static INDArray createEquidistantTimestamps(final INDArray timeSeries); static double[] createEquidistantTimestamps(final double[] timeSeries); static double[] getInterval(final double[] timeSeries, final int start, final int end); static INDArray normalizeINDArray(final INDArray array, final boolean inplace); static int getMode(final int[] array); static T getMaximumKeyByValue(final Map<T, Integer> map); static double[] zNormalize(final double[] dataVector, final boolean besselsCorrection); static List<Integer> sortIndexes(final double[] vector, final boolean ascending); static int getNumberOfClasses(final TimeSeriesDataset2 dataset); static List<Integer> getClassesInDataset(final TimeSeriesDataset2 dataset); static void shuffleTimeSeriesDataset(final TimeSeriesDataset2 dataset, final int seed); static Pair<TimeSeriesDataset2, TimeSeriesDataset2> getTrainingAndTestDataForFold(final int fold, final int numFolds, final double[][] srcValueMatrix, final int[] srcTargetMatrix); static TimeSeriesDataset2 createDatasetForMatrix(final int[] targets, final double[][]... valueMatrices); static TimeSeriesDataset2 createDatasetForMatrix(final double[][]... valueMatrices); static String toString(final double[] timeSeries); static double[] keoghDerivate(final double[] t); static double[] keoghDerivateWithBoundaries(final double[] t); static double[] backwardDifferenceDerivate(final double[] t); static double[] backwardDifferenceDerivateWithBoundaries(final double[] t); static double[] forwardDifferenceDerivate(final double[] t); static double[] forwardDifferenceDerivateWithBoundaries(final double[] t); static double[] gulloDerivate(final double[] t); static double[] gulloDerivateWithBoundaries(final double[] t); static double sum(final double[] t); static double mean(final double[] t); static double variance(final double[] t); static double standardDeviation(final double[] t); static double[] normalizeByStandardDeviation(final double[] t);  }
@Test public void testVariance() { double variance = TimeSeriesUtil.variance(this.T); double expectation = (2 * 3.5 * 3.5 + 2 * 2.5 * 2.5 + 2 * 1.5 * 1.5 + 0.5) / 8; assertEquals(expectation, variance, 1e-5); }
@Test public void testVariance2() { double variance = TimeSeriesUtil.variance(this.U); double expectation = 0; assertEquals(expectation, variance, 1e-5); }
@Test public void testVariance3() { double[] T = { 0.2, 0.2, 0.2 }; double variance = TimeSeriesUtil.variance(T); double expectation = 0; assertEquals(expectation, variance, 1e-5); }