TimeSeriesUtil { public static INDArray normalizeINDArray(final INDArray array, final boolean inplace) { if (array.shape().length > 2 && array.shape()[0] != 1) { throw new IllegalArgumentException(String.format("Input INDArray object must be a vector with shape size 1. Actual shape: (%s)", Arrays.toString(array.shape()))); } final double mean = array.mean(1).getDouble(0); final double std = array.std(1).getDouble(0); INDArray result; if (inplace) { result = array.subi(mean); } else { result = array.sub(mean); } return result.addi(Nd4j.EPS_THRESHOLD).divi(std); } 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 normalizeINDArrayTest() { INDArray testArray = Nd4j.create(new double[] { 1, 2, 3 }); Assert.assertTrue(Nd4j.create(new double[] { -1, 0, 1 }).equalsWithEps(TimeSeriesUtil.normalizeINDArray(testArray, false), EPS_DELTA)); }