com.etsy.conjecture.evaluation.EvaluationAggregator Maven / Gradle / Ivy
package com.etsy.conjecture.evaluation;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import com.etsy.conjecture.data.Label;
public class EvaluationAggregator implements Serializable {
private static final long serialVersionUID = 5825037849957449364L;
protected Map stats = new TreeMap();
protected Map> obj = new HashMap>();
public void add(ModelEvaluation eval) {
Map fold = eval.getStatistics();
if (!stats.isEmpty()) {
if (!fold.keySet().equals(stats.keySet())) {
throw new java.lang.RuntimeException(
"Tried to add incompatible folds, with fields:"
+ fold.keySet().toString() + " and "
+ stats.keySet().toString());
}
for (Map.Entry e : fold.entrySet()) {
stats.get(e.getKey()).addValue(e.getValue());
}
for (Map.Entry e : eval.getObjects().entrySet()) {
obj.get(e.getKey()).add(e.getValue());
}
} else {
for (Map.Entry e : fold.entrySet()) {
DescriptiveStatistics ds = new DescriptiveStatistics();
ds.addValue(e.getValue());
stats.put(e.getKey(), ds);
}
for (Map.Entry e : eval.getObjects().entrySet()) {
obj.put(e.getKey(), new ArrayList