for (int i = 0; i < classifier.length; i++) {
result[i] = classifier[i].predict(features);
}
int numPossibleOutcomes = result[0].getDimension() == 1 ? 2 : result[0]
.getDimension();
DoubleVector toReturn = new DenseDoubleVector(
result[0].getDimension() == 1 ? 1 : numPossibleOutcomes);
// now combine the results based on the rule
switch (type) {
case MAJORITY:
double[] histogram = createPredictionHistogram(result,
numPossibleOutcomes);
if (numPossibleOutcomes == 2) {
toReturn.set(0, ArrayUtils.maxIndex(histogram));
} else {
toReturn.set(ArrayUtils.maxIndex(histogram), 1d);
}
break;
case PROBABILITY:
histogram = createPredictionHistogram(result, numPossibleOutcomes);
double histSum = 0;
for (double d : histogram) {
histSum += d;
}
if (numPossibleOutcomes == 2) {
toReturn.set(0, histogram[1] / histSum);
} else {
for (int i = 0; i < histogram.length; i++) {
toReturn.set(i, histogram[i] / histSum);
}
}
break;
case AVERAGE:
for (int i = 0; i < result.length; i++) {
toReturn = toReturn.add(result[i]);
}
toReturn = toReturn.divide(classifier.length);
break;
default:
throw new UnsupportedOperationException("Type " + type
+ " isn't supported yet!");
}