Search in sources :

Example 21 with DBID

use of de.lmu.ifi.dbs.elki.database.ids.DBID in project elki by elki-project.

the class SortingDuplicatesTest method testDuplicateKeys.

@Test(timeout = 100)
public void testDuplicateKeys() {
    // We need an ide, but no real data.
    DBID id = DBIDUtil.importInteger(1);
    int size = 100000;
    ModifiableDoubleDBIDList list = DBIDUtil.newDistanceDBIDList(size);
    for (int i = 0; i < size; i++) {
        double distance = 0. + (i % 2);
        list.add(distance, id);
    }
    list.sort();
}
Also used : ModifiableDoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList) DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) Test(org.junit.Test)

Example 22 with DBID

use of de.lmu.ifi.dbs.elki.database.ids.DBID in project elki by elki-project.

the class FastOPTICS method expandClusterOrder.

/**
 * OPTICS algorithm for processing a point, but with different density
 * estimates
 *
 * @param ipt Point
 * @param order Cluster order (output)
 * @param dq Distance query
 * @param prog Progress for logging.
 */
protected void expandClusterOrder(DBID ipt, ClusterOrder order, DistanceQuery<V> dq, FiniteProgress prog) {
    UpdatableHeap<OPTICSHeapEntry> heap = new UpdatableHeap<>();
    heap.add(new OPTICSHeapEntry(ipt, null, Double.POSITIVE_INFINITY));
    while (!heap.isEmpty()) {
        final OPTICSHeapEntry current = heap.poll();
        DBID currPt = current.objectID;
        order.add(currPt, current.reachability, current.predecessorID);
        processed.add(currPt);
        double coredist = inverseDensities.doubleValue(currPt);
        for (DBIDIter it = neighs.get(currPt).iter(); it.valid(); it.advance()) {
            if (processed.contains(it)) {
                continue;
            }
            double nrdist = dq.distance(currPt, it);
            if (coredist > nrdist) {
                nrdist = coredist;
            }
            if (reachDist.doubleValue(it) == UNDEFINED_DISTANCE) {
                reachDist.put(it, nrdist);
            } else if (nrdist < reachDist.doubleValue(it)) {
                reachDist.put(it, nrdist);
            }
            heap.add(new OPTICSHeapEntry(DBIDUtil.deref(it), currPt, nrdist));
        }
        LOG.incrementProcessed(prog);
    }
}
Also used : UpdatableHeap(de.lmu.ifi.dbs.elki.utilities.datastructures.heap.UpdatableHeap) DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 23 with DBID

use of de.lmu.ifi.dbs.elki.database.ids.DBID in project elki by elki-project.

the class MkCoPTree method insertAll.

@Override
public void insertAll(List<MkCoPEntry> 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 (MkCoPEntry entry : entries) {
        ids.add(entry.getRoutingObjectID());
        // insert the object
        super.insert(entry, false);
    }
    // perform nearest neighbor queries
    Map<DBID, KNNList> knnLists = batchNN(getRoot(), ids, settings.kmax);
    // adjust the knn distances
    adjustApproximatedKNNDistances(getRootEntry(), knnLists);
    if (EXTRA_INTEGRITY_CHECKS) {
        getRoot().integrityCheck(this, getRootEntry());
    }
}
Also used : KNNList(de.lmu.ifi.dbs.elki.database.ids.KNNList) DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) ModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)

Example 24 with DBID

use of de.lmu.ifi.dbs.elki.database.ids.DBID in project elki by elki-project.

the class AbstractMkTree method batchNN.

/**
 * Performs a batch k-nearest neighbor query for a list of query objects.
 *
 * @param node the node representing the subtree on which the query should be
 *        performed
 * @param ids the ids of the query objects
 * @param kmax Maximum k value
 *
 * @deprecated Change to use by-object NN lookups instead.
 */
@Deprecated
protected final Map<DBID, KNNList> batchNN(N node, DBIDs ids, int kmax) {
    Map<DBID, KNNList> res = new HashMap<>(ids.size());
    for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
        DBID id = DBIDUtil.deref(iter);
        res.put(id, knnq.getKNNForDBID(id, kmax));
    }
    return res;
}
Also used : KNNList(de.lmu.ifi.dbs.elki.database.ids.KNNList) HashMap(java.util.HashMap) DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 25 with DBID

use of de.lmu.ifi.dbs.elki.database.ids.DBID in project elki by elki-project.

the class CASHIntervalSplit method determineIDs.

/**
 * Determines the ids belonging to the given interval, i.e. the
 * parameterization functions falling within the interval.
 *
 * @param superSetIDs a superset of the ids to be determined
 * @param interval the hyper bounding box defining the interval of alpha
 *        values
 * @param d_min the minimum distance value for the interval
 * @param d_max the maximum distance value for the interval
 * @return the ids belonging to the given interval, if the number ids of
 *         exceeds minPts, null otherwise
 */
public ModifiableDBIDs determineIDs(DBIDs superSetIDs, HyperBoundingBox interval, double d_min, double d_max) {
    StringBuilder msg = LOG.isDebugging() ? new StringBuilder() : null;
    if (msg != null) {
        msg.append("interval ").append(interval);
    }
    ModifiableDBIDs childIDs = DBIDUtil.newHashSet(superSetIDs.size());
    Map<DBID, Double> minima = f_minima.get(interval);
    Map<DBID, Double> maxima = f_maxima.get(interval);
    if (minima == null || maxima == null) {
        minima = new HashMap<>();
        f_minima.put(interval, minima);
        maxima = new HashMap<>();
        f_maxima.put(interval, maxima);
    }
    for (DBIDIter iter = superSetIDs.iter(); iter.valid(); iter.advance()) {
        DBID id = DBIDUtil.deref(iter);
        Double f_min = minima.get(id);
        Double f_max = maxima.get(id);
        if (f_min == null) {
            ParameterizationFunction f = database.get(id);
            HyperBoundingBox minMax = f.determineAlphaMinMax(interval);
            f_min = f.function(SpatialUtil.getMin(minMax));
            f_max = f.function(SpatialUtil.getMax(minMax));
            minima.put(id, f_min);
            maxima.put(id, f_max);
        }
        if (msg != null) {
            msg.append("\n\nf_min ").append(f_min);
            msg.append("\nf_max ").append(f_max);
            msg.append("\nd_min ").append(d_min);
            msg.append("\nd_max ").append(d_max);
        }
        if (f_min - f_max > ParameterizationFunction.DELTA) {
            throw new IllegalArgumentException("Houston, we have a problem: f_min > f_max! " + "\nf_min[" + FormatUtil.format(SpatialUtil.centroid(interval)) + "] = " + f_min + "\nf_max[" + FormatUtil.format(SpatialUtil.centroid(interval)) + "] = " + f_max + "\nf " + database.get(id));
        }
        if (f_min <= d_max && f_max >= d_min) {
            childIDs.add(id);
            if (msg != null) {
                msg.append("\nid ").append(id).append(" appended");
            }
        } else {
            if (msg != null) {
                msg.append("\nid ").append(id).append(" NOT appended");
            }
        }
    }
    if (msg != null) {
        msg.append("\nchildIds ").append(childIDs.size());
        LOG.debugFine(msg.toString());
    }
    if (childIDs.size() < minPts) {
        return null;
    } else {
        return childIDs;
    }
}
Also used : DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) ModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs) HyperBoundingBox(de.lmu.ifi.dbs.elki.data.HyperBoundingBox) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Aggregations

DBID (de.lmu.ifi.dbs.elki.database.ids.DBID)42 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)20 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)11 ArrayList (java.util.ArrayList)10 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)9 ModifiableDoubleDBIDList (de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList)9 DoubleDBIDListIter (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)6 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)5 HashSetModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.HashSetModifiableDBIDs)5 Database (de.lmu.ifi.dbs.elki.database.Database)4 ArrayModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs)4 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)4 HashMap (java.util.HashMap)4 KNNHeap (de.lmu.ifi.dbs.elki.database.ids.KNNHeap)3 MTreeEntry (de.lmu.ifi.dbs.elki.index.tree.metrical.mtreevariants.MTreeEntry)3 Test (org.junit.Test)3 AbstractClusterAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest)2 SLINK (de.lmu.ifi.dbs.elki.algorithm.clustering.hierarchical.SLINK)2 CutDendrogramByHeight (de.lmu.ifi.dbs.elki.algorithm.clustering.hierarchical.extraction.CutDendrogramByHeight)2 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)2