use of de.lmu.ifi.dbs.elki.database.query.knn.LinearScanDistanceKNNQuery in project elki by elki-project.
the class SpacefillingMaterializeKNNPreprocessorTest method testPreprocessor.
@Test
public void testPreprocessor() {
Database db = AbstractSimpleAlgorithmTest.makeSimpleDatabase(dataset, shoulds);
Relation<DoubleVector> rel = db.getRelation(TypeUtil.DOUBLE_VECTOR_FIELD);
DistanceQuery<DoubleVector> distanceQuery = db.getDistanceQuery(rel, EuclideanDistanceFunction.STATIC);
// get linear queries
LinearScanDistanceKNNQuery<DoubleVector> lin_knn_query = new LinearScanDistanceKNNQuery<>(distanceQuery);
// get preprocessed queries
ListParameterization config = new ListParameterization();
//
config.addParameter(//
SpacefillingMaterializeKNNPreprocessor.Factory.Parameterizer.CURVES_ID, //
HilbertSpatialSorter.class.getName() + "," + PeanoSpatialSorter.class.getName() + "," + ZCurveSpatialSorter.class.getName() + "," + BinarySplitSpatialSorter.class.getName());
config.addParameter(SpacefillingMaterializeKNNPreprocessor.Factory.K_ID, k);
config.addParameter(SpacefillingMaterializeKNNPreprocessor.Factory.Parameterizer.VARIANTS_ID, 10);
config.addParameter(SpacefillingMaterializeKNNPreprocessor.Factory.Parameterizer.WINDOW_ID, 1.);
config.addParameter(SpacefillingMaterializeKNNPreprocessor.Factory.Parameterizer.RANDOM_ID, 0L);
SpacefillingMaterializeKNNPreprocessor.Factory<DoubleVector> preprocf = ClassGenericsUtil.parameterizeOrAbort(SpacefillingMaterializeKNNPreprocessor.Factory.class, config);
SpacefillingMaterializeKNNPreprocessor<DoubleVector> preproc = preprocf.instantiate(rel);
preproc.initialize();
// add as index
db.getHierarchy().add(rel, preproc);
KNNQuery<DoubleVector> preproc_knn_query = preproc.getKNNQuery(distanceQuery, k);
assertFalse("Preprocessor knn query class incorrect.", preproc_knn_query instanceof LinearScanDistanceKNNQuery);
// test queries
testKNNQueries(rel, lin_knn_query, preproc_knn_query, k);
// also test partial queries, forward only
testKNNQueries(rel, lin_knn_query, preproc_knn_query, k / 2);
}
use of de.lmu.ifi.dbs.elki.database.query.knn.LinearScanDistanceKNNQuery in project elki by elki-project.
the class NNDescentTest method testPreprocessor.
@Test
public void testPreprocessor() {
Database db = AbstractSimpleAlgorithmTest.makeSimpleDatabase(dataset, shoulds);
Relation<DoubleVector> rel = db.getRelation(TypeUtil.DOUBLE_VECTOR_FIELD);
DistanceQuery<DoubleVector> distanceQuery = db.getDistanceQuery(rel, EuclideanDistanceFunction.STATIC);
// get linear queries
LinearScanDistanceKNNQuery<DoubleVector> lin_knn_query = new LinearScanDistanceKNNQuery<>(distanceQuery);
// get preprocessed queries
ListParameterization config = new ListParameterization();
config.addParameter(NNDescent.Factory.DISTANCE_FUNCTION_ID, distanceQuery.getDistanceFunction());
config.addParameter(NNDescent.Factory.K_ID, k);
config.addParameter(NNDescent.Factory.Parameterizer.SEED_ID, 0);
config.addParameter(NNDescent.Factory.Parameterizer.DELTA_ID, 0.1);
config.addParameter(NNDescent.Factory.Parameterizer.RHO_ID, 0.5);
NNDescent.Factory<DoubleVector> preprocf = ClassGenericsUtil.parameterizeOrAbort(NNDescent.Factory.class, config);
NNDescent<DoubleVector> preproc = preprocf.instantiate(rel);
KNNQuery<DoubleVector> preproc_knn_query = preproc.getKNNQuery(distanceQuery, k);
// add as index
db.getHierarchy().add(rel, preproc);
assertFalse("Preprocessor knn query class incorrect.", preproc_knn_query instanceof LinearScanDistanceKNNQuery);
// test queries
testKNNQueries(rel, lin_knn_query, preproc_knn_query, k);
// also test partial queries, forward only
testKNNQueries(rel, lin_knn_query, preproc_knn_query, k / 2);
}
use of de.lmu.ifi.dbs.elki.database.query.knn.LinearScanDistanceKNNQuery in project elki by elki-project.
the class SpacefillingKNNPreprocessorTest method testCauchy.
@Test
public void testCauchy() {
Database db = AbstractSimpleAlgorithmTest.makeSimpleDatabase(dataset, shoulds);
Relation<DoubleVector> rel = db.getRelation(TypeUtil.DOUBLE_VECTOR_FIELD);
DistanceQuery<DoubleVector> distanceQuery = db.getDistanceQuery(rel, EuclideanDistanceFunction.STATIC);
// get linear queries
LinearScanDistanceKNNQuery<DoubleVector> lin_knn_query = new LinearScanDistanceKNNQuery<>(distanceQuery);
// get preprocessed queries
ListParameterization config = new ListParameterization();
//
config.addParameter(//
SpacefillingKNNPreprocessor.Factory.Parameterizer.CURVES_ID, //
HilbertSpatialSorter.class.getName() + "," + PeanoSpatialSorter.class.getName() + "," + ZCurveSpatialSorter.class.getName() + "," + BinarySplitSpatialSorter.class.getName());
config.addParameter(SpacefillingKNNPreprocessor.Factory.Parameterizer.DIM_ID, 7);
config.addParameter(SpacefillingKNNPreprocessor.Factory.Parameterizer.PROJECTION_ID, CauchyRandomProjectionFamily.class);
config.addParameter(SpacefillingKNNPreprocessor.Factory.Parameterizer.VARIANTS_ID, 10);
config.addParameter(SpacefillingKNNPreprocessor.Factory.Parameterizer.WINDOW_ID, 5.);
config.addParameter(SpacefillingKNNPreprocessor.Factory.Parameterizer.RANDOM_ID, 0L);
config.addParameter(CauchyRandomProjectionFamily.Parameterizer.RANDOM_ID, 0L);
SpacefillingKNNPreprocessor.Factory<DoubleVector> preprocf = ClassGenericsUtil.parameterizeOrAbort(SpacefillingKNNPreprocessor.Factory.class, config);
SpacefillingKNNPreprocessor<DoubleVector> preproc = preprocf.instantiate(rel);
preproc.initialize();
// add as index
db.getHierarchy().add(rel, preproc);
KNNQuery<DoubleVector> preproc_knn_query = preproc.getKNNQuery(distanceQuery, k);
assertFalse("Preprocessor knn query class incorrect.", preproc_knn_query instanceof LinearScanDistanceKNNQuery);
// test queries
testKNNQueries(rel, lin_knn_query, preproc_knn_query, k);
// also test partial queries, forward only
testKNNQueries(rel, lin_knn_query, preproc_knn_query, k / 2);
}
Aggregations