Search in sources :

Example 1 with EmptyDataException

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.");
    }
}
Also used : EmptyDataException(de.lmu.ifi.dbs.elki.utilities.exceptions.EmptyDataException) RangeQuery(de.lmu.ifi.dbs.elki.database.query.range.RangeQuery) FiniteProgress(de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress) ModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 2 with EmptyDataException

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.");
    }
}
Also used : EmptyDataException(de.lmu.ifi.dbs.elki.utilities.exceptions.EmptyDataException) KNNList(de.lmu.ifi.dbs.elki.database.ids.KNNList) FiniteProgress(de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 3 with EmptyDataException

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.");
    }
}
Also used : EmptyDataException(de.lmu.ifi.dbs.elki.utilities.exceptions.EmptyDataException) FiniteProgress(de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress) SortedEigenPairs(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.SortedEigenPairs) DoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDList) PCAFilteredResult(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCAFilteredResult) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Aggregations

DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)3 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)3 EmptyDataException (de.lmu.ifi.dbs.elki.utilities.exceptions.EmptyDataException)3 DoubleDBIDList (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDList)1 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)1 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)1 RangeQuery (de.lmu.ifi.dbs.elki.database.query.range.RangeQuery)1 PCAFilteredResult (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCAFilteredResult)1 SortedEigenPairs (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.SortedEigenPairs)1