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;
}
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);
}
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);
}
}
Aggregations