de.lmu.ifi.dbs.elki.database.query.knn.AbstractDistanceKNNQuery Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elki Show documentation
Show all versions of elki Show documentation
ELKI - Main Module – Open-Source Data-Mining Framework with Index Acceleration
package de.lmu.ifi.dbs.elki.database.query.knn;
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
Copyright (C) 2015
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
import java.util.ArrayList;
import java.util.List;
import de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs;
import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
import de.lmu.ifi.dbs.elki.database.ids.KNNList;
import de.lmu.ifi.dbs.elki.database.query.distance.DistanceQuery;
import de.lmu.ifi.dbs.elki.database.relation.Relation;
/**
* Instance for the query on a particular database.
*
* @author Erich Schubert
* @since 0.4.0
*/
public abstract class AbstractDistanceKNNQuery implements KNNQuery {
/**
* The data to use for this query
*/
final protected Relation extends O> relation;
/**
* Hold the distance function to be used.
*/
final protected DistanceQuery distanceQuery;
/**
* Constructor.
*
* @param distanceQuery Distance query used
*/
public AbstractDistanceKNNQuery(DistanceQuery distanceQuery) {
super();
this.relation = distanceQuery.getRelation();
this.distanceQuery = distanceQuery;
}
@Override
public List extends KNNList> getKNNForBulkDBIDs(ArrayDBIDs ids, int k) {
// throw new
// UnsupportedOperationException(ExceptionMessages.UNSUPPORTED_NOT_YET);
// TODO: optimize
List ret = new ArrayList<>(ids.size());
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
ret.add(getKNNForDBID(iter, k));
}
return ret;
}
@Override
public KNNList getKNNForDBID(DBIDRef id, int k) {
return getKNNForObject(relation.get(id), k);
}
@Override
abstract public KNNList getKNNForObject(O obj, int k);
}