Search in sources :

Example 41 with DBID

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

the class MTreeSplit method balancedPartition.

/**
 * Creates a balanced partition of the entries of the specified node.
 *
 * @param tree the tree to perform the split in
 * @param node the node to be split
 * @param routingObject1 the id of the first routing object
 * @param routingObject2 the id of the second routing object
 * @return an assignment that holds a balanced partition of the entries of the
 *         specified node
 */
Assignments<E> balancedPartition(AbstractMTree<O, N, E, ?> tree, N node, DBID routingObject1, DBID routingObject2) {
    assert (routingObject1 != null && routingObject2 != null);
    final int n = node.getNumEntries(), l = n - 2;
    int[] idx1 = new int[l], idx2 = new int[l];
    double[] dis1 = new double[l], dis2 = new double[l];
    Assignments<E> assign = new Assignments<>((n + 1) >> 1);
    assign.setFirstRoutingObject(routingObject1);
    assign.setSecondRoutingObject(routingObject2);
    for (int i = 0, j = 0; i < n; i++) {
        final E ent = node.getEntry(i);
        final DBID id = ent.getRoutingObjectID();
        if (DBIDUtil.equal(id, routingObject1)) {
            assign.addToFirst(ent, 0., i);
            continue;
        }
        if (DBIDUtil.equal(id, routingObject2)) {
            assign.addToSecond(ent, 0., i);
            continue;
        }
        // determine the distance of o to o1 / o2
        dis1[j] = tree.distance(routingObject1, id);
        idx1[j] = i;
        dis2[j] = tree.distance(routingObject2, id);
        idx2[j] = i;
        j++;
    }
    DoubleIntegerArrayQuickSort.sort(dis1, idx1, l);
    DoubleIntegerArrayQuickSort.sort(dis2, idx2, l);
    long[] assigned = BitsUtil.zero(n);
    int p1 = 0, p2 = 0;
    for (int i = 0; i < l; ++i) {
        p1 = assignBest(assign, assigned, node, dis1, idx1, p1, false);
        if (++i < l) {
            p2 = assignBest(assign, assigned, node, dis2, idx2, p2, true);
        }
    }
    assert (assign.getFirstAssignments().size() + assign.getSecondAssignments().size() == n) : "Sizes do not sum up: " + assign.getFirstAssignments().size() + " + " + assign.getFirstAssignments().size() + " != " + n;
    assert (Math.abs(assign.getFirstAssignments().size() - assign.getSecondAssignments().size()) <= 1) : assign.getFirstAssignments().size() + " " + assign.getSecondAssignments().size();
    return assign;
}
Also used : DBID(de.lmu.ifi.dbs.elki.database.ids.DBID)

Example 42 with DBID

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

the class ArrayDBIDStore method put.

@Override
@Deprecated
public DBID put(DBIDRef id, DBID value) {
    final int off = idmap.mapDBIDToOffset(id);
    DBID ret = data.get(off);
    data.set(off, value);
    return ret;
}
Also used : DBID(de.lmu.ifi.dbs.elki.database.ids.DBID)

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