use of de.lmu.ifi.dbs.elki.database.ids.KNNList in project elki by elki-project.
the class PreprocessorKNNQuery method getKNNForDBID.
@Override
public KNNList getKNNForDBID(DBIDRef id, int k) {
if (!warned && k > preprocessor.getK()) {
getLogger().warning("Requested more neighbors than preprocessed: requested " + k + " preprocessed " + preprocessor.getK(), new Throwable());
warned = true;
}
KNNList dr = preprocessor.get(id);
if (k < preprocessor.getK() && k < dr.size()) {
return getSublist(dr, k);
}
return dr;
}
use of de.lmu.ifi.dbs.elki.database.ids.KNNList in project elki by elki-project.
the class MkMaxTreeIndex method createNewLeafEntry.
/**
* @return a new MkMaxLeafEntry representing the specified data object
*/
protected MkMaxLeafEntry createNewLeafEntry(DBID id, O object, double parentDistance) {
KNNList knns = knnq.getKNNForObject(object, getKmax() - 1);
double knnDistance = knns.getKNNDistance();
return new MkMaxLeafEntry(id, parentDistance, knnDistance);
}
use of de.lmu.ifi.dbs.elki.database.ids.KNNList in project elki by elki-project.
the class MkTabTree method kNNdistanceAdjustment.
@Override
protected void kNNdistanceAdjustment(MkTabEntry entry, Map<DBID, KNNList> knnLists) {
MkTabTreeNode<O> node = getNode(entry);
double[] knnDistances_node = initKnnDistanceList();
if (node.isLeaf()) {
for (int i = 0; i < node.getNumEntries(); i++) {
MkTabEntry leafEntry = node.getEntry(i);
KNNList knns = knnLists.get(getPageID(leafEntry));
double[] distances = new double[knns.size()];
int j = 0;
for (DoubleDBIDListIter iter = knns.iter(); iter.valid(); iter.advance(), j++) {
distances[j] = iter.doubleValue();
}
leafEntry.setKnnDistances(distances);
// FIXME: save copy
knnDistances_node = max(knnDistances_node, leafEntry.getKnnDistances());
}
} else {
for (int i = 0; i < node.getNumEntries(); i++) {
MkTabEntry dirEntry = node.getEntry(i);
kNNdistanceAdjustment(dirEntry, knnLists);
// FIXME: save copy
knnDistances_node = max(knnDistances_node, dirEntry.getKnnDistances());
}
}
entry.setKnnDistances(knnDistances_node);
}
use of de.lmu.ifi.dbs.elki.database.ids.KNNList in project elki by elki-project.
the class MkAppTree method insertAll.
/**
* Inserts the specified objects into this MkApp-Tree.
*
* @param entries the entries to be inserted
*/
@Override
public void insertAll(List<MkAppEntry> entries) {
if (entries.isEmpty()) {
return;
}
if (LOG.isDebugging()) {
LOG.debugFine("insert " + entries + "\n");
}
if (!initialized) {
initialize(entries.get(0));
}
ModifiableDBIDs ids = DBIDUtil.newArray(entries.size());
// insert
for (MkAppEntry entry : entries) {
ids.add(entry.getRoutingObjectID());
// insert the object
super.insert(entry, false);
}
// do batch nn
Map<DBID, KNNList> knnLists = batchNN(getRoot(), ids, settings.kmax + 1);
// adjust the knn distances
adjustApproximatedKNNDistances(getRootEntry(), knnLists);
if (EXTRA_INTEGRITY_CHECKS) {
getRoot().integrityCheck(this, getRootEntry());
}
}
use of de.lmu.ifi.dbs.elki.database.ids.KNNList in project elki by elki-project.
the class MkAppTree method getMeanKNNList.
private double[] getMeanKNNList(DBIDs ids, Map<DBID, KNNList> knnLists) {
double[] means = new double[settings.kmax];
for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
DBID id = DBIDUtil.deref(iter);
KNNList knns = knnLists.get(id);
int k = 0;
for (DoubleDBIDListIter it = knns.iter(); k < settings.kmax && it.valid(); it.advance(), k++) {
means[k] += it.doubleValue();
}
}
for (int k = 0; k < settings.kmax; k++) {
means[k] /= ids.size();
}
return means;
}
Aggregations