    001package javax.visrec.ml.classification;
    002
    003import java.util.HashMap;
    004import java.util.Map;
    005
    006/**
    007 * EnsambleClassifier is a group of classifiers that provide common
    008 * classification result, which gives better accuracy then each individual
    009 * classifier. Usually average or most frequent answer is used as a final result.
    010 *
    011 * @author Zoran Sevarac
    012 * @param <T> The input type which is to be classified.
    013 * @param <R> Return type of the classifier.
    014 * @since 1.0
    015 */
    016public final class EnsambleClassifier<T, R> implements Classifier<T, R> {
    017
    018    private final Map<String, Classifier<T, R>> classifiers = new HashMap<>();
    019
    020    @Override
    021    public Map<R, Float> classify(T input) {
    022        classifiers.values().stream() // or parallelStream
    023                .forEach(c -> c.classify(input));
    024        // get the highest class frequency
    025        //.collect(); // get average scores? This method can be overriden, provide default impl here
    026        // return merged classification result of all classifiers  - mean or most frequent?
    027        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    028    }
    029
    030    // or just provide method for adding swith some intrenal id?
    031    public void addClassifier(String classifierId, Classifier<T, R> classifier) {
    032        classifiers.put(classifierId, classifier);
    033    }
    034
    035    public Classifier getClassifier(String classiferId) {
    036        return classifiers.get(classiferId);
    037    }
    038
    039    public void remove(String classifierId) {
    040        classifiers.remove(classifierId);
    041    }
    042
    043}