ShotgunEnsembleClassifier extends ASimplifiedTSClassifier<Integer> { protected Integer mostFrequentLabelFromWindowLengthPredicitions(final Map<Integer, Integer> windowLengthPredicitions) { Map<Integer, Integer> labelFrequencyMap = new HashMap<>(); for (Integer label : windowLengthPredicitions.values()) { if (labelFrequencyMap.containsKey(label)) { labelFrequencyMap.put(label, labelFrequencyMap.get(label) + 1); } else { labelFrequencyMap.put(label, 1); } } int topFrequency = -1; int mostFrequentLabel = 0; for (Entry<Integer, Integer> entry : labelFrequencyMap.entrySet()) { int label = entry.getKey(); int labelFrequency = entry.getValue(); if (labelFrequency > topFrequency) { topFrequency = labelFrequency; mostFrequentLabel = label; } } return mostFrequentLabel; } ShotgunEnsembleClassifier(final int minWindowLength, final int maxWindowLength, final boolean meanNormalization, final double factor); @Override Integer predict(final double[] univInstance); @Override List<Integer> predict(final TimeSeriesDataset2 dataset); @Override ShotgunEnsembleLearnerAlgorithm getLearningAlgorithm(final TimeSeriesDataset2 dataset);  }
@Test public void testMostFrequentLabelFromWindowLengthPredicitons() { Map<Integer, Integer> windowLengthPredicitions = new HashMap<>(); windowLengthPredicitions.put(2, 1); windowLengthPredicitions.put(3, 2); windowLengthPredicitions.put(4, 2); windowLengthPredicitions.put(5, 2); windowLengthPredicitions.put(6, 1); windowLengthPredicitions.put(7, 2); windowLengthPredicitions.put(8, 3); windowLengthPredicitions.put(9, 3); int mostFrequentlabel = this.shotgunEnsembleClassifier.mostFrequentLabelFromWindowLengthPredicitions(windowLengthPredicitions); int expectation = 2; assertEquals(expectation, mostFrequentlabel); }