use of de.lmu.ifi.dbs.elki.database.query.range.RangeQuery in project elki by elki-project.
the class DiSHPreferenceVectorIndex method initialize.
@Override
public void initialize() {
if (relation == null || relation.size() == 0) {
throw new EmptyDataException();
}
storage = DataStoreUtil.makeStorage(relation.getDBIDs(), DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_TEMP, long[].class);
if (LOG.isDebugging()) {
LOG.debugFine(//
new StringBuilder().append("eps ").append(Arrays.asList(epsilon)).append("\n minpts ").append(//
minpts).append("\n strategy ").append(strategy).toString());
}
long start = System.currentTimeMillis();
FiniteProgress progress = LOG.isVerbose() ? new FiniteProgress("Preprocessing preference vector", relation.size(), LOG) : null;
// only one epsilon value specified
int dim = RelationUtil.dimensionality(relation);
if (epsilon.length == 1 && dim != 1) {
double eps = epsilon[0];
epsilon = new double[dim];
Arrays.fill(epsilon, eps);
}
// epsilons as string
RangeQuery<V>[] rangeQueries = initRangeQueries(relation, dim);
StringBuilder msg = LOG.isDebugging() ? new StringBuilder() : null;
for (DBIDIter it = relation.iterDBIDs(); it.valid(); it.advance()) {
if (msg != null) {
msg.setLength(0);
msg.append("\nid = ").append(DBIDUtil.toString(it));
// msg.append(" ").append(database.get(id));
// msg.append(" ").append(database.getObjectLabelQuery().get(id));
}
// determine neighbors in each dimension
ModifiableDBIDs[] allNeighbors = new ModifiableDBIDs[dim];
for (int d = 0; d < dim; d++) {
allNeighbors[d] = DBIDUtil.newHashSet(rangeQueries[d].getRangeForDBID(it, epsilon[d]));
}
if (msg != null) {
for (int d = 0; d < dim; d++) {
//
msg.append("\n neighbors [").append(d).append(']').append(" (").append(allNeighbors[d].size()).append(") = ").append(allNeighbors[d]);
}
}
storage.put(it, determinePreferenceVector(relation, allNeighbors, msg));
if (msg != null) {
LOG.debugFine(msg.toString());
}
LOG.incrementProcessed(progress);
}
LOG.ensureCompleted(progress);
// TODO: re-add timing code!
if (LOG.isVerbose()) {
long end = System.currentTimeMillis();
long elapsedTime = end - start;
LOG.verbose(this.getClass().getName() + " runtime: " + elapsedTime + " milliseconds.");
}
}
Aggregations