@Test public void testNumericVote() { List<NumericPrediction> predictions = Lists.newArrayList( new NumericPrediction(1.0f, 1), new NumericPrediction(3.0f, 2), new NumericPrediction(6.0f, 3) ); double[] weights = {1.0, 1.0, 1.0}; NumericPrediction vote = (NumericPrediction) WeightedPrediction.voteOnFeature(predictions, weights); assertEquals(FeatureType.NUMERIC, vote.getFeatureType()); assertEquals(10.0f/3.0f, vote.getPrediction()); }
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);  }