Search in sources :

Example 11 with ArrayModifiableDBIDs

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

the class RdKNNTree method postDelete.

/**
 * Performs necessary operations after deleting the specified object.
 */
@Override
protected void postDelete(RdKNNEntry entry) {
    // reverse knn of o
    ModifiableDoubleDBIDList rnns = DBIDUtil.newDistanceDBIDList();
    doReverseKNN(getRoot(), ((RdKNNLeafEntry) entry).getDBID(), rnns);
    // knn of rnn
    ArrayModifiableDBIDs ids = DBIDUtil.newArray(rnns);
    ids.sort();
    List<? extends KNNList> knnLists = knnQuery.getKNNForBulkDBIDs(ids, settings.k_max);
    // adjust knn distances
    adjustKNNDistance(getRootEntry(), ids, knnLists);
}
Also used : ArrayModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs) ModifiableDoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList)

Example 12 with ArrayModifiableDBIDs

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

the class RdKNNTree method reverseKNNQuery.

public DoubleDBIDList reverseKNNQuery(DBID oid, int k, SpatialPrimitiveDistanceFunction<? super O> distanceFunction, KNNQuery<O> knnQuery) {
    checkDistanceFunction(distanceFunction);
    if (k > settings.k_max) {
        throw new IllegalArgumentException("Parameter k is not supported, k > k_max: " + k + " > " + settings.k_max);
    }
    // get candidates
    ModifiableDoubleDBIDList candidates = DBIDUtil.newDistanceDBIDList();
    doReverseKNN(getRoot(), oid, candidates);
    if (k == settings.k_max) {
        candidates.sort();
        return candidates;
    }
    // refinement of candidates, if k < k_max
    ArrayModifiableDBIDs candidateIDs = DBIDUtil.newArray(candidates);
    candidateIDs.sort();
    List<? extends KNNList> knnLists = knnQuery.getKNNForBulkDBIDs(candidateIDs, k);
    ModifiableDoubleDBIDList result = DBIDUtil.newDistanceDBIDList();
    int i = 0;
    for (DBIDIter iter = candidateIDs.iter(); iter.valid(); iter.advance(), i++) {
        for (DoubleDBIDListIter qr = knnLists.get(i).iter(); qr.valid(); qr.advance()) {
            if (DBIDUtil.equal(oid, qr)) {
                result.add(qr.doubleValue(), iter);
                break;
            }
        }
    }
    result.sort();
    return result;
}
Also used : DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter) ArrayModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs) ModifiableDoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 13 with ArrayModifiableDBIDs

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

the class RdKNNTree method bulkLoad.

/**
 * Performs a bulk load on this RTree with the specified data. Is called by
 * the constructor and should be overwritten by subclasses if necessary.
 */
@Override
protected void bulkLoad(List<RdKNNEntry> entries) {
    super.bulkLoad(entries);
    // adjust all knn distances
    ArrayModifiableDBIDs ids = DBIDUtil.newArray(entries.size());
    for (RdKNNEntry entry : entries) {
        DBID id = ((RdKNNLeafEntry) entry).getDBID();
        ids.add(id);
    }
    ids.sort();
    List<? extends KNNList> knnLists = knnQuery.getKNNForBulkDBIDs(ids, settings.k_max);
    adjustKNNDistance(getRootEntry(), ids, knnLists);
    // test
    doExtraIntegrityChecks();
}
Also used : ArrayModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs) DBID(de.lmu.ifi.dbs.elki.database.ids.DBID)

Example 14 with ArrayModifiableDBIDs

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

the class DiSH method sortClusters.

/**
 * Returns a sorted list of the clusters w.r.t. the subspace dimensionality in
 * descending order.
 *
 * @param relation the database storing the objects
 * @param clustersMap the mapping of bits sets to clusters
 * @return a sorted list of the clusters
 */
private List<Cluster<SubspaceModel>> sortClusters(Relation<V> relation, Object2ObjectMap<long[], List<ArrayModifiableDBIDs>> clustersMap) {
    final int db_dim = RelationUtil.dimensionality(relation);
    // int num = 1;
    List<Cluster<SubspaceModel>> clusters = new ArrayList<>();
    for (long[] pv : clustersMap.keySet()) {
        List<ArrayModifiableDBIDs> parallelClusters = clustersMap.get(pv);
        for (int i = 0; i < parallelClusters.size(); i++) {
            ArrayModifiableDBIDs c = parallelClusters.get(i);
            Cluster<SubspaceModel> cluster = new Cluster<>(c);
            cluster.setModel(new SubspaceModel(new Subspace(pv), Centroid.make(relation, c).getArrayRef()));
            String subspace = BitsUtil.toStringLow(cluster.getModel().getSubspace().getDimensions(), db_dim);
            if (parallelClusters.size() > 1) {
                cluster.setName("Cluster_" + subspace + "_" + i);
            } else {
                cluster.setName("Cluster_" + subspace);
            }
            clusters.add(cluster);
        }
    }
    // sort the clusters w.r.t. lambda
    Comparator<Cluster<SubspaceModel>> comparator = new Comparator<Cluster<SubspaceModel>>() {

        @Override
        public int compare(Cluster<SubspaceModel> c1, Cluster<SubspaceModel> c2) {
            return c2.getModel().getSubspace().dimensionality() - c1.getModel().getSubspace().dimensionality();
        }
    };
    Collections.sort(clusters, comparator);
    return clusters;
}
Also used : ArrayList(java.util.ArrayList) SubspaceModel(de.lmu.ifi.dbs.elki.data.model.SubspaceModel) Cluster(de.lmu.ifi.dbs.elki.data.Cluster) Comparator(java.util.Comparator) ArrayModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs) Subspace(de.lmu.ifi.dbs.elki.data.Subspace)

Example 15 with ArrayModifiableDBIDs

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

the class DiSH method checkClusters.

/**
 * Removes the clusters with size < minpts from the cluster map and adds them
 * to their parents.
 *
 * @param relation the relation storing the objects
 * @param clustersMap the map containing the clusters
 */
private void checkClusters(Relation<V> relation, Object2ObjectMap<long[], List<ArrayModifiableDBIDs>> clustersMap) {
    final int dimensionality = RelationUtil.dimensionality(relation);
    // check if there are clusters < minpts
    // and add them to not assigned
    List<Pair<long[], ArrayModifiableDBIDs>> notAssigned = new ArrayList<>();
    Object2ObjectMap<long[], List<ArrayModifiableDBIDs>> newClustersMap = new Object2ObjectOpenCustomHashMap<>(BitsUtil.FASTUTIL_HASH_STRATEGY);
    Pair<long[], ArrayModifiableDBIDs> noise = new Pair<>(BitsUtil.zero(dimensionality), DBIDUtil.newArray());
    for (long[] pv : clustersMap.keySet()) {
        // noise
        if (BitsUtil.cardinality(pv) == 0) {
            List<ArrayModifiableDBIDs> parallelClusters = clustersMap.get(pv);
            for (ArrayModifiableDBIDs c : parallelClusters) {
                noise.second.addDBIDs(c);
            }
        } else // clusters
        {
            List<ArrayModifiableDBIDs> parallelClusters = clustersMap.get(pv);
            List<ArrayModifiableDBIDs> newParallelClusters = new ArrayList<>(parallelClusters.size());
            for (ArrayModifiableDBIDs c : parallelClusters) {
                if (!BitsUtil.isZero(pv) && c.size() < mu) {
                    notAssigned.add(new Pair<>(pv, c));
                } else {
                    newParallelClusters.add(c);
                }
            }
            newClustersMap.put(pv, newParallelClusters);
        }
    }
    clustersMap.clear();
    clustersMap.putAll(newClustersMap);
    for (Pair<long[], ArrayModifiableDBIDs> c : notAssigned) {
        if (c.second.isEmpty()) {
            continue;
        }
        Pair<long[], ArrayModifiableDBIDs> parent = findParent(relation, c, clustersMap);
        if (parent != null) {
            parent.second.addDBIDs(c.second);
        } else {
            noise.second.addDBIDs(c.second);
        }
    }
    List<ArrayModifiableDBIDs> noiseList = new ArrayList<>(1);
    noiseList.add(noise.second);
    clustersMap.put(noise.first, noiseList);
}
Also used : Object2ObjectOpenCustomHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap) ArrayModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Pair(de.lmu.ifi.dbs.elki.utilities.pairs.Pair)

Aggregations

ArrayModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs)49 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)23 DBIDArrayIter (de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter)12 ArrayList (java.util.ArrayList)11 DBIDVar (de.lmu.ifi.dbs.elki.database.ids.DBIDVar)10 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)9 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)8 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)7 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)6 ArrayDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs)6 Clustering (de.lmu.ifi.dbs.elki.data.Clustering)5 DBIDRef (de.lmu.ifi.dbs.elki.database.ids.DBIDRef)5 Relation (de.lmu.ifi.dbs.elki.database.relation.Relation)5 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)4 SortDBIDsBySingleDimension (de.lmu.ifi.dbs.elki.data.VectorUtil.SortDBIDsBySingleDimension)4 DoubleDBIDListIter (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)4 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)4 ModifiableDoubleDBIDList (de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList)4 SetDBIDs (de.lmu.ifi.dbs.elki.database.ids.SetDBIDs)4 Pair (de.lmu.ifi.dbs.elki.utilities.pairs.Pair)4