@Test public void testCategoricalVote() { List<CategoricalPrediction> predictions = Lists.newArrayList( new CategoricalPrediction(new int[] {0, 1, 2}), new CategoricalPrediction(new int[] {6, 2, 0}), new CategoricalPrediction(new int[] {0, 2, 0}) ); double[] weights = {1.0, 1.0, 1.0}; CategoricalPrediction vote = (CategoricalPrediction) WeightedPrediction.voteOnFeature(predictions, weights); assertEquals(FeatureType.CATEGORICAL, vote.getFeatureType()); assertEquals(1, vote.getMostProbableCategoryID()); }
public static <T extends Prediction> Prediction voteOnFeature(List<T> predictions, double[] weights) { switch (predictions.iterator().next().getFeatureType()) { case NUMERIC: @SuppressWarnings("unchecked") List<NumericPrediction> numericVotes = (List<NumericPrediction>) predictions; return voteOnNumericFeature(numericVotes, weights); case CATEGORICAL: @SuppressWarnings("unchecked") List<CategoricalPrediction> categoricalVotes = (List<CategoricalPrediction>) predictions; return voteOnCategoricalFeature(categoricalVotes, weights); default: throw new IllegalStateException(); } }
WeightedPrediction { public static <T extends Prediction> Prediction voteOnFeature(List<T> predictions, double[] weights) { switch (predictions.iterator().next().getFeatureType()) { case NUMERIC: @SuppressWarnings("unchecked") List<NumericPrediction> numericVotes = (List<NumericPrediction>) predictions; return voteOnNumericFeature(numericVotes, weights); case CATEGORICAL: @SuppressWarnings("unchecked") List<CategoricalPrediction> categoricalVotes = (List<CategoricalPrediction>) predictions; return voteOnCategoricalFeature(categoricalVotes, weights); default: throw new IllegalStateException(); } } }
WeightedPrediction { public static <T extends Prediction> Prediction voteOnFeature(List<T> predictions, double[] weights) { switch (predictions.iterator().next().getFeatureType()) { case NUMERIC: @SuppressWarnings("unchecked") List<NumericPrediction> numericVotes = (List<NumericPrediction>) predictions; return voteOnNumericFeature(numericVotes, weights); case CATEGORICAL: @SuppressWarnings("unchecked") List<CategoricalPrediction> categoricalVotes = (List<CategoricalPrediction>) predictions; return voteOnCategoricalFeature(categoricalVotes, weights); default: throw new IllegalStateException(); } } private  WeightedPrediction(); }
WeightedPrediction { public static <T extends Prediction> Prediction voteOnFeature(List<T> predictions, double[] weights) { switch (predictions.iterator().next().getFeatureType()) { case NUMERIC: @SuppressWarnings("unchecked") List<NumericPrediction> numericVotes = (List<NumericPrediction>) predictions; return voteOnNumericFeature(numericVotes, weights); case CATEGORICAL: @SuppressWarnings("unchecked") List<CategoricalPrediction> categoricalVotes = (List<CategoricalPrediction>) predictions; return voteOnCategoricalFeature(categoricalVotes, weights); default: throw new IllegalStateException(); } } private  WeightedPrediction(); static Prediction voteOnFeature(List<T> predictions, double[] weights); }
WeightedPrediction { public static <T extends Prediction> Prediction voteOnFeature(List<T> predictions, double[] weights) { switch (predictions.iterator().next().getFeatureType()) { case NUMERIC: @SuppressWarnings("unchecked") List<NumericPrediction> numericVotes = (List<NumericPrediction>) predictions; return voteOnNumericFeature(numericVotes, weights); case CATEGORICAL: @SuppressWarnings("unchecked") List<CategoricalPrediction> categoricalVotes = (List<CategoricalPrediction>) predictions; return voteOnCategoricalFeature(categoricalVotes, weights); default: throw new IllegalStateException(); } } private  WeightedPrediction(); static Prediction voteOnFeature(List<T> predictions, double[] weights);  }