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