Search in sources :

Example 6 with XYCurve

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;
}
Also used : XYCurve(de.lmu.ifi.dbs.elki.math.geometry.XYCurve)

Aggregations

XYCurve (de.lmu.ifi.dbs.elki.math.geometry.XYCurve)6 DBIDsTest (de.lmu.ifi.dbs.elki.evaluation.scores.adapter.DBIDsTest)3 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)1 HashSetModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.HashSetModifiableDBIDs)1 ModifiableDoubleDBIDList (de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList)1 PRCurve (de.lmu.ifi.dbs.elki.evaluation.outlier.OutlierPrecisionRecallCurve.PRCurve)1 ROCResult (de.lmu.ifi.dbs.elki.evaluation.outlier.OutlierROCCurve.ROCResult)1 DistanceResultAdapter (de.lmu.ifi.dbs.elki.evaluation.scores.adapter.DistanceResultAdapter)1 OutlierScoreAdapter (de.lmu.ifi.dbs.elki.evaluation.scores.adapter.OutlierScoreAdapter)1 SimpleAdapter (de.lmu.ifi.dbs.elki.evaluation.scores.adapter.SimpleAdapter)1 LinearScale (de.lmu.ifi.dbs.elki.math.scales.LinearScale)1 CSSNamingConflict (de.lmu.ifi.dbs.elki.visualization.css.CSSClassManager.CSSNamingConflict)1 StyleLibrary (de.lmu.ifi.dbs.elki.visualization.style.StyleLibrary)1 SVGPath (de.lmu.ifi.dbs.elki.visualization.svg.SVGPath)1 StaticVisualizationInstance (de.lmu.ifi.dbs.elki.visualization.visualizers.StaticVisualizationInstance)1 Test (org.junit.Test)1 Element (org.w3c.dom.Element)1