WeightedPredictionsAggregator implements PredictionsAggregator { @Override public Double apply(double[] answers) { A.ensure(answers.length == weights.length, "Composition vector must have same size as weights vector"); double res = bias; for (int i = 0; i < answers.length; i++) res += weights[i] * answers[i]; return res; } WeightedPredictionsAggregator(double[] weights);  WeightedPredictionsAggregator(double[] weights, double bias); @Override Double apply(double[] answers); @Override String toString(); @Override String toString(boolean pretty); double[] getWeights(); double getBias();  }
@Test public void testApply1() { WeightedPredictionsAggregator aggregator = new WeightedPredictionsAggregator(new double[] {}); assertEquals(0.0, aggregator.apply(new double[] {}), 0.001); }
@Test public void testApply2() { WeightedPredictionsAggregator aggregator = new WeightedPredictionsAggregator(new double[] {1.0, 0.5, 0.25}); assertEquals(3.0, aggregator.apply(new double[] {1.0, 2.0, 4.0}), 0.001); }
@Test(expected = IllegalArgumentException.class) public void testIllegalArguments() { WeightedPredictionsAggregator aggregator = new WeightedPredictionsAggregator(new double[] {1.0, 0.5, 0.25}); aggregator.apply(new double[] { }); }