Search in sources :

Example 1 with DistanceResultAdapter

use of de.lmu.ifi.dbs.elki.evaluation.scores.adapter.DistanceResultAdapter in project elki by elki-project.

the class ROCEvaluationTest method testROCCurve.

/**
 * Test ROC curve generation, including curve simplification
 */
@Test
public void testROCCurve() {
    HashSetModifiableDBIDs positive = DBIDUtil.newHashSet();
    positive.add(DBIDUtil.importInteger(1));
    positive.add(DBIDUtil.importInteger(2));
    positive.add(DBIDUtil.importInteger(3));
    positive.add(DBIDUtil.importInteger(4));
    positive.add(DBIDUtil.importInteger(5));
    final ModifiableDoubleDBIDList distances = DBIDUtil.newDistanceDBIDList();
    // Starting point: ................................ 0.0,0. ++
    // + 0.0,.2 -- redundant
    distances.add(0.0, DBIDUtil.importInteger(1));
    // + 0.0,.4 ++
    distances.add(1.0, DBIDUtil.importInteger(2));
    // - .25,.4 ++
    distances.add(2.0, DBIDUtil.importInteger(6));
    // -
    distances.add(3.0, DBIDUtil.importInteger(7));
    // + .50,.6 -- redundant
    distances.add(3.0, DBIDUtil.importInteger(3));
    // -
    distances.add(4.0, DBIDUtil.importInteger(8));
    // + .75,.8 ++
    distances.add(4.0, DBIDUtil.importInteger(4));
    // - 1.0,.8 ++
    distances.add(5.0, DBIDUtil.importInteger(9));
    // + 1.0,1. ++
    distances.add(6.0, DBIDUtil.importInteger(5));
    XYCurve roccurve = ROCEvaluation.materializeROC(new DBIDsTest(positive), new DistanceResultAdapter(distances.iter()));
    // System.err.println(roccurve);
    assertEquals("ROC curve too complex", 6, roccurve.size());
    double auc = XYCurve.areaUnderCurve(roccurve);
    assertEquals("ROC AUC (curve) not correct.", 0.6, auc, 1e-14);
    double auc2 = new ROCEvaluation().evaluate(positive, distances);
    assertEquals("ROC AUC (direct) not correct.", 0.6, auc2, 1e-14);
}
Also used : HashSetModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.HashSetModifiableDBIDs) XYCurve(de.lmu.ifi.dbs.elki.math.geometry.XYCurve) ModifiableDoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList) DBIDsTest(de.lmu.ifi.dbs.elki.evaluation.scores.adapter.DBIDsTest) DistanceResultAdapter(de.lmu.ifi.dbs.elki.evaluation.scores.adapter.DistanceResultAdapter) Test(org.junit.Test) DBIDsTest(de.lmu.ifi.dbs.elki.evaluation.scores.adapter.DBIDsTest)

Aggregations

HashSetModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.HashSetModifiableDBIDs)1 ModifiableDoubleDBIDList (de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList)1 DBIDsTest (de.lmu.ifi.dbs.elki.evaluation.scores.adapter.DBIDsTest)1 DistanceResultAdapter (de.lmu.ifi.dbs.elki.evaluation.scores.adapter.DistanceResultAdapter)1 XYCurve (de.lmu.ifi.dbs.elki.math.geometry.XYCurve)1 Test (org.junit.Test)1