Search in sources :

Example 51 with ModifiableDoubleDBIDList

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

the class MkTabTree method reverseKNNQuery.

@Override
public DoubleDBIDList reverseKNNQuery(DBIDRef id, int k) {
    if (k > this.getKmax()) {
        throw new IllegalArgumentException("Parameter k has to be less or equal than " + "parameter kmax of the MkTab-Tree!");
    }
    ModifiableDoubleDBIDList result = DBIDUtil.newDistanceDBIDList();
    doReverseKNNQuery(k, id, null, getRoot(), result);
    result.sort();
    return result;
}
Also used : ModifiableDoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList)

Example 52 with ModifiableDoubleDBIDList

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

the class MaximumF1EvaluationTest method testMaximumF1.

/**
 * Test maximum F1 score computation
 */
@Test
public void testMaximumF1() {
    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();
    // P: 1.0 R: 0.2
    distances.add(0.0, DBIDUtil.importInteger(1));
    // P: 1.0 R: 0.4
    distances.add(1.0, DBIDUtil.importInteger(2));
    // P: 2/3 R: 0.4
    distances.add(2.0, DBIDUtil.importInteger(6));
    // P: 0.5 R: 0.4
    distances.add(3.0, DBIDUtil.importInteger(7));
    // P: 0.6 R: 0.6
    distances.add(3.0, DBIDUtil.importInteger(3));
    // P: 0.5 R: 0.6
    distances.add(4.0, DBIDUtil.importInteger(8));
    // P: 4/7 R: 0.8
    distances.add(4.0, DBIDUtil.importInteger(4));
    // P: 0.5 R: 0.8
    distances.add(5.0, DBIDUtil.importInteger(9));
    // P: 5/9 R: 1.0
    distances.add(6.0, DBIDUtil.importInteger(5));
    double maxf1 = new MaximumF1Evaluation().evaluate(positive, distances);
    assertEquals("Maximum F1 not correct.", 0.7142857142857143, maxf1, 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)

Example 53 with ModifiableDoubleDBIDList

use of de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList 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

ModifiableDoubleDBIDList (de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList)53 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)22 DoubleDBIDListIter (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)16 DBID (de.lmu.ifi.dbs.elki.database.ids.DBID)9 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)8 HashSetModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.HashSetModifiableDBIDs)6 ArrayDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 ArrayModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs)4 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)4 DoubleDBIDPair (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDPair)4 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)4 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)3 DoubleStatistic (de.lmu.ifi.dbs.elki.logging.statistics.DoubleStatistic)3 MeanVariance (de.lmu.ifi.dbs.elki.math.MeanVariance)3 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)3 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)2 DBIDArrayIter (de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter)2 DoubleDBIDListMIter (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListMIter)2