use of de.lmu.ifi.dbs.elki.utilities.exceptions.EmptyDataException 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.");
}
}
use of de.lmu.ifi.dbs.elki.utilities.exceptions.EmptyDataException in project elki by elki-project.
the class HiSCPreferenceVectorIndex 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);
StringBuilder msg = new StringBuilder();
long start = System.currentTimeMillis();
FiniteProgress progress = LOG.isVerbose() ? new FiniteProgress("Preprocessing preference vector", relation.size(), LOG) : null;
KNNQuery<V> knnQuery = QueryUtil.getKNNQuery(relation, EuclideanDistanceFunction.STATIC, k);
for (DBIDIter it = relation.iterDBIDs(); it.valid(); it.advance()) {
if (LOG.isDebugging()) {
msg.append("\n\nid = ").append(DBIDUtil.toString(it));
// /msg.append(" ").append(database.getObjectLabelQuery().get(id));
msg.append("\n knns: ");
}
KNNList knns = knnQuery.getKNNForDBID(it, k);
long[] preferenceVector = determinePreferenceVector(relation, it, knns, msg);
storage.put(it, preferenceVector);
LOG.incrementProcessed(progress);
}
LOG.ensureCompleted(progress);
if (LOG.isDebugging()) {
LOG.debugFine(msg.toString());
}
long end = System.currentTimeMillis();
// TODO: re-add timing code!
if (LOG.isVerbose()) {
long elapsedTime = end - start;
LOG.verbose(this.getClass().getName() + " runtime: " + elapsedTime + " milliseconds.");
}
}
use of de.lmu.ifi.dbs.elki.utilities.exceptions.EmptyDataException in project elki by elki-project.
the class AbstractFilteredPCAIndex method initialize.
@Override
public void initialize() {
if (relation == null || relation.size() <= 0) {
throw new EmptyDataException();
}
// recomputed for the partitions!
if (storage != null) {
return;
}
storage = DataStoreUtil.makeStorage(relation.getDBIDs(), DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_TEMP, PCAFilteredResult.class);
long start = System.currentTimeMillis();
FiniteProgress progress = getLogger().isVerbose() ? new FiniteProgress("Performing local PCA", relation.size(), getLogger()) : null;
// TODO: use a bulk operation?
for (DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
DoubleDBIDList objects = objectsForPCA(iditer);
SortedEigenPairs epairs = pca.processIds(objects, relation).getEigenPairs();
int numstrong = filter.filter(epairs.eigenValues());
PCAFilteredResult pcares = new PCAFilteredResult(epairs, numstrong, 1., 0.);
storage.put(iditer, pcares);
getLogger().incrementProcessed(progress);
}
getLogger().ensureCompleted(progress);
long end = System.currentTimeMillis();
if (getLogger().isVerbose()) {
long elapsedTime = end - start;
getLogger().verbose(this.getClass().getName() + " runtime: " + elapsedTime + " milliseconds.");
}
}
Aggregations