use of de.lmu.ifi.dbs.elki.math.geometry.XYCurve in project elki by elki-project.
the class ROCEvaluation method materializeROC.
/**
* Compute a ROC curve given a set of positive IDs and a sorted list of
* (comparable, ID)s, where the comparable object is used to decided when two
* objects are interchangeable.
*
* @param <I> Iterator type
* @param predicate Predicate to test for positive objects
* @param iter Iterator over results, with ties.
* @return area under curve
*/
public static <I extends ScoreIter> XYCurve materializeROC(Predicate<? super I> predicate, I iter) {
int poscnt = 0, negcnt = 0;
XYCurve curve = new XYCurve("False Positive Rate", "True Positive Rate");
// start in bottom left
curve.add(0.0, 0.0);
while (iter.valid()) {
// positive or negative match?
do {
if (predicate.test(iter)) {
++poscnt;
} else {
++negcnt;
}
iter.advance();
} while (// Loop while tied:
iter.valid() && iter.tiedToPrevious());
// Add a new point.
curve.addAndSimplify(negcnt, poscnt);
}
// Ensure we end up in the top right corner.
// Simplification will skip this if we already were.
curve.addAndSimplify(negcnt, poscnt);
curve.rescale(1. / negcnt, 1. / poscnt);
return curve;
}
Aggregations