Search in sources :

Example 1 with SpatialComparable

use of de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable in project elki by elki-project.

the class SpatialSorter method computeMinMax.

/**
 * Compute the minimum and maximum for each dimension.
 *
 * @param objs Objects
 * @return Array of min, max pairs (length = 2 * dim)
 */
static double[] computeMinMax(Iterable<? extends SpatialComparable> objs) {
    Iterator<? extends SpatialComparable> it = objs.iterator();
    if (!it.hasNext()) {
        throw new IllegalArgumentException("Cannot compute minimum and maximum of empty list.");
    }
    SpatialComparable first = it.next();
    final int dim = first.getDimensionality();
    // Compute min and max for each dimension:
    double[] mm = new double[dim << 1];
    for (int d = 0, d2 = 0; d < dim; d++) {
        mm[d2++] = first.getMin(d);
        mm[d2++] = first.getMax(d);
    }
    while (it.hasNext()) {
        SpatialComparable obj = it.next();
        for (int d = 0, d2 = 0; d < dim; d++) {
            mm[d2] = MathUtil.min(mm[d2], obj.getMin(d));
            d2++;
            mm[d2] = MathUtil.max(mm[d2], obj.getMax(d));
            d2++;
        }
    }
    return mm;
}
Also used : SpatialComparable(de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable)

Example 2 with SpatialComparable

use of de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable in project elki by elki-project.

the class Scales method calcScales.

/**
 * Compute a linear scale for each dimension.
 *
 * @param rel Relation
 * @return Scales, indexed starting with 0 (like Vector, not database
 *         objects!)
 */
public static LinearScale[] calcScales(Relation<? extends SpatialComparable> rel) {
    int dim = RelationUtil.dimensionality(rel);
    DoubleMinMax[] minmax = DoubleMinMax.newArray(dim);
    LinearScale[] scales = new LinearScale[dim];
    // analyze data
    for (DBIDIter iditer = rel.iterDBIDs(); iditer.valid(); iditer.advance()) {
        SpatialComparable v = rel.get(iditer);
        if (v instanceof NumberVector) {
            for (int d = 0; d < dim; d++) {
                final double mi = v.getMin(d);
                if (mi != mi) {
                    // NaN
                    continue;
                }
                minmax[d].put(mi);
            }
        } else {
            for (int d = 0; d < dim; d++) {
                final double mi = v.getMin(d);
                if (mi == mi) {
                    // No NaN
                    minmax[d].put(mi);
                }
                final double ma = v.getMax(d);
                if (ma == ma) {
                    // No NaN
                    minmax[d].put(ma);
                }
            }
        }
    }
    // generate scales
    for (int d = 0; d < dim; d++) {
        scales[d] = new LinearScale(minmax[d].getMin(), minmax[d].getMax());
    }
    return scales;
}
Also used : DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) NumberVector(de.lmu.ifi.dbs.elki.data.NumberVector) SpatialComparable(de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 3 with SpatialComparable

use of de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable in project elki by elki-project.

the class LeastEnlargementInsertionStrategy method choose.

@Override
public <A> int choose(A options, ArrayAdapter<? extends SpatialComparable, A> getter, SpatialComparable obj, int height, int depth) {
    final int size = getter.size(options);
    assert (size > 0) : "Choose from empty set?";
    double leastEnlargement = Double.POSITIVE_INFINITY;
    int best = -1;
    for (int i = 0; i < size; i++) {
        SpatialComparable entry = getter.get(options, i);
        double enlargement = SpatialUtil.enlargement(entry, obj);
        if (enlargement < leastEnlargement) {
            leastEnlargement = enlargement;
            best = i;
        }
    }
    assert (best > -1);
    return best;
}
Also used : SpatialComparable(de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable)

Example 4 with SpatialComparable

use of de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable in project elki by elki-project.

the class XSplitter method add2MBR.

/**
 * Adds the minimum and maximum bounds of the MBR of entry
 * <code>entrySorting[index]</code> in {@link #entries} to the dimension-wise
 * upper and lower bound priority queues <code>pqUBFirst</code> and
 * <code>pqLBFirst</code>.
 *
 * @param entrySorting a sorting providing the mapping of <code>index</code>
 *        to the entry in {@link #entries} to be added
 * @param pqUB One priority queue for each dimension. They are sorted by upper
 *        bound in descending order and consist of entry indices in
 *        <code>entrySorting</code> for the entries belonging to
 *        <code>mbr</code>.
 * @param pqLB One priority queue for each dimension. They are sorted by lower
 *        bound in ascending order and consist of entry indices in
 *        <code>entrySorting</code> for the entries belonging to
 *        <code>mbr</code>.
 * @param index the index in the sorting referencing the entry to be added
 */
private void add2MBR(int[] entrySorting, List<Heap<DoubleIntPair>> pqUB, List<Heap<DoubleIntPair>> pqLB, int index) {
    SpatialComparable currMBR = node.getEntry(entrySorting[index]);
    for (int d = 0; d < currMBR.getDimensionality(); d++) {
        double max = currMBR.getMax(d);
        pqUB.get(d).add(new DoubleIntPair(max, index));
        double min = currMBR.getMin(d);
        pqLB.get(d).add(new DoubleIntPair(min, index));
    }
}
Also used : SpatialComparable(de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable) DoubleIntPair(de.lmu.ifi.dbs.elki.utilities.pairs.DoubleIntPair)

Example 5 with SpatialComparable

use of de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable in project elki by elki-project.

the class HilbertSpatialSorter method sort.

@Override
public void sort(List<? extends SpatialComparable> objs, int start, int end, double[] minmax, int[] dims) {
    final int dim = (dims != null) ? dims.length : (minmax.length >> 1);
    List<HilbertRef> tmp = new ArrayList<>(end - start);
    int[] buf = new int[dim];
    for (int i = start; i < end; i++) {
        SpatialComparable v = objs.get(i);
        // Convert into integers
        for (int d = 0; d < dim; d++) {
            final int ed = (dims != null) ? dims[d] : d, ed2 = ed << 1;
            double val = (v.getMin(ed) + v.getMax(ed)) * .5;
            val = Integer.MAX_VALUE * ((val - minmax[ed2]) / (minmax[ed2 + 1] - minmax[ed2]));
            buf[d] = (int) val;
        }
        tmp.add(new HilbertRef(v, coordinatesToHilbert(buf, Integer.SIZE - 1, 1)));
    }
    // Sort and copy back
    Collections.sort(tmp);
    // Hack, to allow reordering.
    @SuppressWarnings("unchecked") List<SpatialComparable> cobjs = (List<SpatialComparable>) objs;
    for (int i = start; i < end; i++) {
        cobjs.set(i, tmp.get(i - start).vec);
    }
}
Also used : SpatialComparable(de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

SpatialComparable (de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable)12 HyperBoundingBox (de.lmu.ifi.dbs.elki.data.HyperBoundingBox)3 DoubleIntPair (de.lmu.ifi.dbs.elki.utilities.pairs.DoubleIntPair)2 ModifiableHyperBoundingBox (de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox)1 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)1 ArrayDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs)1 DBIDArrayIter (de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter)1 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)1 Relation (de.lmu.ifi.dbs.elki.database.relation.Relation)1 SpatialEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)1 DoubleMinMax (de.lmu.ifi.dbs.elki.math.DoubleMinMax)1 EvaluationResult (de.lmu.ifi.dbs.elki.result.EvaluationResult)1 MeasurementGroup (de.lmu.ifi.dbs.elki.result.EvaluationResult.MeasurementGroup)1 TopBoundedHeap (de.lmu.ifi.dbs.elki.utilities.datastructures.heap.TopBoundedHeap)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1