use of de.lmu.ifi.dbs.elki.database.query.distance.DistanceQuery in project elki by elki-project.
the class KNNJoinTest method testLinearScan.
@Test
public void testLinearScan() {
Database db = AbstractSimpleAlgorithmTest.makeSimpleDatabase(dataset, shoulds);
Relation<NumberVector> relation = db.getRelation(TypeUtil.NUMBER_VECTOR_FIELD);
// Euclidean
{
DistanceQuery<NumberVector> dq = db.getDistanceQuery(relation, EuclideanDistanceFunction.STATIC);
KNNQuery<NumberVector> knnq = QueryUtil.getLinearScanKNNQuery(dq);
MeanVariance meansize = new MeanVariance();
for (DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
meansize.put(knnq.getKNNForDBID(iditer, 2).size());
}
org.junit.Assert.assertEquals("Euclidean mean 2NN", mean2nnEuclid, meansize.getMean(), 0.00001);
org.junit.Assert.assertEquals("Euclidean variance 2NN", var2nnEuclid, meansize.getSampleVariance(), 0.00001);
}
// Manhattan
{
DistanceQuery<NumberVector> dq = db.getDistanceQuery(relation, ManhattanDistanceFunction.STATIC);
KNNQuery<NumberVector> knnq = QueryUtil.getLinearScanKNNQuery(dq);
MeanVariance meansize = new MeanVariance();
for (DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
meansize.put(knnq.getKNNForDBID(iditer, 2).size());
}
org.junit.Assert.assertEquals("Manhattan mean 2NN", mean2nnManhattan, meansize.getMean(), 0.00001);
org.junit.Assert.assertEquals("Manhattan variance 2NN", var2nnManhattan, meansize.getSampleVariance(), 0.00001);
}
}
Aggregations