TimeSeriesUtil { public static int getMode(final int[] array) { HashMap<Integer, Integer> statistics = new HashMap<>(); for (int i = 0; i < array.length; i++) { if (!statistics.containsKey(array[i])) { statistics.put(array[i], 1); } else { statistics.replace(array[i], statistics.get(array[i]) + 1); } } return getMaximumKeyByValue(statistics) != null ? getMaximumKeyByValue(statistics) : -1; } 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 getModeTest() { int[] testArray = new int[] { 1, 2, 1, 1, 4, 6, 6, 6, 7, 7, 7, 7, 7, 7, 2, 1, 1 }; Assert.assertEquals(7, TimeSeriesUtil.getMode(testArray)); testArray = new int[] {}; Assert.assertEquals(-1, TimeSeriesUtil.getMode(testArray)); testArray = new int[] { 1, 1, 2, 2 }; Assert.assertEquals(1, TimeSeriesUtil.getMode(testArray)); }