ml.classifiers.utils.ClassificationVoter Maven / Gradle / Ivy
package ml.classifiers.utils;
import utils.Pair;
import utils.PairBuilder;
import java.util.*;
public class ClassificationVoter implements IVoter> > {
public ClassificationVoter(){
this.values = new ArrayList>();
}
@Override
public void addItem(Integer item, Double criterionType){
this.values.add(PairBuilder.makePair(item, criterionType));
}
/**
* Allow any Object cast to double to be added
* @param item
* @param criterionType
*/
public void addItem(Integer item, Object criterionType){
this.addItem(item, (Double) criterionType);
}
/**
* Add a list of items T, U should be castable to Integer and Double respectively
*/
public void addItems(List> items){
for (int i = 0; i < items.size(); i++) {
this.values.add((Pair)items.get(i));
}
}
@Override
public List> getResult(int max){
//get the values
Object[] valuesArr = (Object[]) values.toArray();
Arrays.sort(valuesArr, new Comparator