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);
}
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;
}
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();
}
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;
}
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);
}
Aggregations