use of de.lmu.ifi.dbs.elki.database.ids.DBID 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.DBID 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;
}
use of de.lmu.ifi.dbs.elki.database.ids.DBID in project elki by elki-project.
the class MkAppTreeIndex method initialize.
@Override
public void initialize() {
super.initialize();
List<MkAppEntry> objs = new ArrayList<>(relation.size());
for (DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
DBID id = DBIDUtil.deref(iter);
final O object = relation.get(id);
objs.add(createNewLeafEntry(id, object, Double.NaN));
}
insertAll(objs);
}
use of de.lmu.ifi.dbs.elki.database.ids.DBID in project elki by elki-project.
the class MkCoPTree method reverseKNNQuery.
/**
* Performs a reverse k-nearest neighbor query for the given object ID. The
* query result is in ascending order to the distance to the query object.
*
* @param id the query object id
* @param k the number of nearest neighbors to be returned
* @return a List of the query results
*/
@Override
public DoubleDBIDList reverseKNNQuery(DBIDRef id, int k) {
if (k > settings.kmax) {
throw new IllegalArgumentException("Parameter k has to be less or equal than " + "parameter kmax of the MCop-Tree!");
}
ModifiableDoubleDBIDList result = DBIDUtil.newDistanceDBIDList();
ModifiableDBIDs candidates = DBIDUtil.newArray();
doReverseKNNQuery(k, id, result, candidates);
// refinement of candidates
Map<DBID, KNNList> knnLists = batchNN(getRoot(), candidates, k);
result.sort();
for (DBIDIter iter = candidates.iter(); iter.valid(); iter.advance()) {
DBID cid = DBIDUtil.deref(iter);
KNNList cands = knnLists.get(cid);
for (DoubleDBIDListIter iter2 = cands.iter(); iter2.valid(); iter2.advance()) {
if (DBIDUtil.equal(id, iter2)) {
result.add(iter2.doubleValue(), cid);
break;
}
}
}
result.sort();
// rkNNStatistics.addResults(result.size());
return result;
}
use of de.lmu.ifi.dbs.elki.database.ids.DBID in project elki by elki-project.
the class MkCoPTreeIndex method initialize.
@Override
public void initialize() {
super.initialize();
List<MkCoPEntry> objs = new ArrayList<>(relation.size());
for (DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
// FIXME: expensive
DBID id = DBIDUtil.deref(iter);
final O object = relation.get(id);
objs.add(createNewLeafEntry(id, object, Double.NaN));
}
insertAll(objs);
}
Aggregations