public void testPreprocessor() throws ParameterException, UnableToComplyException {
ListParameterization params = new ListParameterization();
params.addParameter(FileBasedDatabaseConnection.INPUT_ID, dataset);
// get database
UpdatableDatabase db = ClassGenericsUtil.parameterizeOrAbort(HashmapDatabase.class, params);
db.initialize();
Relation<DoubleVector> rep = db.getRelation(TypeUtil.DOUBLE_VECTOR_FIELD);
DistanceQuery<DoubleVector, DoubleDistance> distanceQuery = db.getDistanceQuery(rep, EuclideanDistanceFunction.STATIC);
// verify data set size.
assertEquals("Data set size doesn't match parameters.", shoulds, rep.size());
// get linear queries
LinearScanKNNQuery<DoubleVector, DoubleDistance> lin_knn_query = new LinearScanKNNQuery<DoubleVector, DoubleDistance>(distanceQuery);
LinearScanRKNNQuery<DoubleVector, DoubleDistance> lin_rknn_query = new LinearScanRKNNQuery<DoubleVector, DoubleDistance>(distanceQuery, lin_knn_query, k);
// get preprocessed queries
ListParameterization config = new ListParameterization();
config.addParameter(MaterializeKNNPreprocessor.Factory.DISTANCE_FUNCTION_ID, distanceQuery.getDistanceFunction());
config.addParameter(MaterializeKNNPreprocessor.Factory.K_ID, k);
MaterializeKNNAndRKNNPreprocessor<DoubleVector, DoubleDistance> preproc = new MaterializeKNNAndRKNNPreprocessor<DoubleVector, DoubleDistance>(rep, distanceQuery.getDistanceFunction(), k);
KNNQuery<DoubleVector, DoubleDistance> preproc_knn_query = preproc.getKNNQuery(distanceQuery, k);
RKNNQuery<DoubleVector, DoubleDistance> preproc_rknn_query = preproc.getRKNNQuery(distanceQuery);
// add as index
db.addIndex(preproc);
assertTrue("Preprocessor knn query class incorrect.", !(preproc_knn_query instanceof LinearScanKNNQuery));
assertTrue("Preprocessor rknn query class incorrect.", !(preproc_rknn_query instanceof LinearScanKNNQuery));
// test queries
testKNNQueries(rep, lin_knn_query, preproc_knn_query, k);
testRKNNQueries(rep, lin_rknn_query, preproc_rknn_query, k);
// also test partial queries, forward only
testKNNQueries(rep, lin_knn_query, preproc_knn_query, k / 2);
// insert new objects
List<DoubleVector> insertions = new ArrayList<DoubleVector>();
DoubleVector o = DatabaseUtil.assumeVectorField(rep).getFactory();
Random random = new Random(seed);
for(int i = 0; i < updatesize; i++) {
DoubleVector obj = VectorUtil.randomVector(o, random);
insertions.add(obj);
}
System.out.println("Insert " + insertions);
System.out.println();
DBIDs deletions = db.insert(MultipleObjectsBundle.makeSimple(rep.getDataTypeInformation(), insertions));
// test queries
testKNNQueries(rep, lin_knn_query, preproc_knn_query, k);
testRKNNQueries(rep, lin_rknn_query, preproc_rknn_query, k);
// delete objects
System.out.println("Delete " + deletions);
db.delete(deletions);
// test queries
testKNNQueries(rep, lin_knn_query, preproc_knn_query, k);
testRKNNQueries(rep, lin_rknn_query, preproc_rknn_query, k);
}