Search in sources :

Example 21 with HashSetModifiableDBIDs

use of de.lmu.ifi.dbs.elki.database.ids.HashSetModifiableDBIDs in project elki by elki-project.

the class PrecisionAtKEvaluationTest method testPrecisionAtK.

/**
 * Test Precision@k score computation.
 */
@Test
public void testPrecisionAtK() {
    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();
    // Precision: 1.0
    distances.add(0.0, DBIDUtil.importInteger(1));
    // Precision: 1.0
    distances.add(1.0, DBIDUtil.importInteger(2));
    // 
    distances.add(2.0, DBIDUtil.importInteger(6));
    // 
    distances.add(3.0, DBIDUtil.importInteger(7));
    // Precision: 0.6
    distances.add(3.0, DBIDUtil.importInteger(3));
    // 
    distances.add(4.0, DBIDUtil.importInteger(8));
    // Precision: 4/7.
    distances.add(4.0, DBIDUtil.importInteger(4));
    // 
    distances.add(5.0, DBIDUtil.importInteger(9));
    // Precision: 5/9.
    distances.add(6.0, DBIDUtil.importInteger(5));
    // (1+1+.6+4/7.+5/9.)/5 = 0.7453968253968254
    double[] precision = new double[] { 1., 1., 2. / 3., 2.5 / 4., 3 / 5., 3.5 / 6., 4. / 7., 4. / 8., 5 / 9. };
    for (int k = 0; k < precision.length; ++k) {
        double pk = new PrecisionAtKEvaluation(k + 1).evaluate(positive, distances);
        assertEquals("Precision at k=" + (k + 1) + " not correct.", precision[k], pk, 1e-14);
    }
}
Also used : HashSetModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.HashSetModifiableDBIDs) ModifiableDoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList) Test(org.junit.Test)

Aggregations

HashSetModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.HashSetModifiableDBIDs)21 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)8 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)5 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)5 ModifiableDoubleDBIDList (de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList)5 ArrayList (java.util.ArrayList)5 DBID (de.lmu.ifi.dbs.elki.database.ids.DBID)4 Test (org.junit.Test)4 ArrayModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs)3 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)2 DBIDArrayIter (de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter)2 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)2 SetDBIDs (de.lmu.ifi.dbs.elki.database.ids.SetDBIDs)2 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)2 PCAFilteredResult (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCAFilteredResult)2 SortedEigenPairs (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.SortedEigenPairs)2 PreDeConModel (de.lmu.ifi.dbs.elki.algorithm.clustering.gdbscan.PreDeConNeighborPredicate.PreDeConModel)1 Cluster (de.lmu.ifi.dbs.elki.data.Cluster)1 Clustering (de.lmu.ifi.dbs.elki.data.Clustering)1 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)1