use of de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter in project elki by elki-project.
the class MkTabTreeIndex method knnDistances.
/**
* Returns the knn distance of the object with the specified id.
*
* @param object the query object
* @return the knn distance of the object with the specified id
*/
private double[] knnDistances(O object) {
KNNList knns = knnq.getKNNForObject(object, getKmax() - 1);
double[] distances = new double[getKmax()];
int i = 0;
for (DoubleDBIDListIter iter = knns.iter(); iter.valid() && i < getKmax(); iter.advance(), i++) {
distances[i] = iter.doubleValue();
}
return distances;
}
use of de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter in project elki by elki-project.
the class MaterializeKNNPreprocessor method preprocess.
/**
* The actual preprocessing step.
*/
@Override
protected void preprocess() {
// Could be subclass
final Logging log = getLogger();
createStorage();
ArrayDBIDs ids = DBIDUtil.ensureArray(relation.getDBIDs());
if (log.isStatistics()) {
log.statistics(new LongStatistic(this.getClass().getName() + ".k", k));
}
Duration duration = log.isStatistics() ? log.newDuration(this.getClass().getName() + ".precomputation-time").begin() : null;
FiniteProgress progress = getLogger().isVerbose() ? new FiniteProgress("Materializing k nearest neighbors (k=" + k + ")", ids.size(), getLogger()) : null;
// Try bulk
List<? extends KNNList> kNNList = null;
if (usebulk) {
kNNList = knnQuery.getKNNForBulkDBIDs(ids, k);
if (kNNList != null) {
int i = 0;
for (DBIDIter id = ids.iter(); id.valid(); id.advance(), i++) {
storage.put(id, kNNList.get(i));
log.incrementProcessed(progress);
}
}
} else {
final boolean ismetric = getDistanceQuery().getDistanceFunction().isMetric();
for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
if (ismetric && storage.get(iter) != null) {
log.incrementProcessed(progress);
// Previously computed (duplicate point?)
continue;
}
KNNList knn = knnQuery.getKNNForDBID(iter, k);
storage.put(iter, knn);
if (ismetric) {
for (DoubleDBIDListIter it = knn.iter(); it.valid() && it.doubleValue() == 0.; it.advance()) {
// Reuse
storage.put(it, knn);
}
}
log.incrementProcessed(progress);
}
}
log.ensureCompleted(progress);
if (duration != null) {
log.statistics(duration.end());
}
}
use of de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter in project elki by elki-project.
the class DoubleIntegerDBIDPairKNNListHeap method toString.
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("kNNList[");
for (DoubleDBIDListIter iter = this.iter(); iter.valid(); ) {
buf.append(iter.doubleValue()).append(':').append(DBIDUtil.toString(iter));
iter.advance();
if (iter.valid()) {
buf.append(',');
}
}
buf.append(']');
return buf.toString();
}
use of de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter in project elki by elki-project.
the class AutotuningPCA method assertSortedByDistance.
/**
* Ensure that the results are sorted by distance.
*
* @param results Results to process
*/
private void assertSortedByDistance(DoubleDBIDList results) {
// TODO: sort results instead?
double dist = -1.0;
boolean sorted = true;
for (DoubleDBIDListIter it = results.iter(); it.valid(); it.advance()) {
double qr = it.doubleValue();
if (qr < dist) {
sorted = false;
}
dist = qr;
}
if (!sorted) {
try {
ModifiableDoubleDBIDList.class.cast(results).sort();
} catch (ClassCastException | UnsupportedOperationException e) {
LoggingUtil.warning("WARNING: results not sorted by distance!", e);
}
}
}
Aggregations