Search in sources :

Example 31 with DBIDIter

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

the class KMeansElkan method updateBounds.

/**
 * Update the bounds for k-means.
 *
 * @param relation Relation
 * @param assignment Cluster assignment
 * @param upper Upper bounds
 * @param lower Lower bounds
 * @param move Movement of centers
 */
private void updateBounds(Relation<V> relation, WritableIntegerDataStore assignment, WritableDoubleDataStore upper, WritableDataStore<double[]> lower, double[] move) {
    for (DBIDIter it = relation.iterDBIDs(); it.valid(); it.advance()) {
        upper.increment(it, move[assignment.intValue(it)]);
        double[] l = lower.get(it);
        for (int i = 0; i < k; i++) {
            l[i] -= move[i];
        }
    }
}
Also used : DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 32 with DBIDIter

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

the class RelationUtil method computeMinMax.

/**
 * Determines the minimum and maximum values in each dimension of all objects
 * stored in the given database.
 *
 * @param relation the database storing the objects
 * @return Minimum and Maximum vector for the hyperrectangle
 */
public static double[][] computeMinMax(Relation<? extends NumberVector> relation) {
    int dim = RelationUtil.dimensionality(relation);
    double[] mins = new double[dim], maxs = new double[dim];
    for (int i = 0; i < dim; i++) {
        mins[i] = Double.MAX_VALUE;
        maxs[i] = -Double.MAX_VALUE;
    }
    for (DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
        final NumberVector o = relation.get(iditer);
        for (int d = 0; d < dim; d++) {
            final double v = o.doubleValue(d);
            mins[d] = (v < mins[d]) ? v : mins[d];
            maxs[d] = (v > maxs[d]) ? v : maxs[d];
        }
    }
    return new double[][] { mins, maxs };
}
Also used : NumberVector(de.lmu.ifi.dbs.elki.data.NumberVector) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 33 with DBIDIter

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

the class RelationUtil method variances.

/**
 * Determines the variances in each dimension of the specified objects stored
 * in the given database.
 *
 * @param database the database storing the objects
 * @param ids the ids of the objects
 * @param centroid the centroid or reference vector of the ids
 * @return the variances in each dimension of the specified objects
 */
public static double[] variances(Relation<? extends NumberVector> database, NumberVector centroid, DBIDs ids) {
    final int size = ids.size();
    double[] variances = new double[centroid.getDimensionality()];
    for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
        NumberVector o = database.get(iter);
        for (int d = 0; d < centroid.getDimensionality(); d++) {
            final double diff = o.doubleValue(d) - centroid.doubleValue(d);
            variances[d] += diff * diff / size;
        }
    }
    return variances;
}
Also used : NumberVector(de.lmu.ifi.dbs.elki.data.NumberVector) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 34 with DBIDIter

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

the class ArrayModifiableIntegerDBIDs method addDBIDs.

@Override
public boolean addDBIDs(DBIDs ids) {
    ensureSize(size + ids.size());
    for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
        store[size] = iter.internalGetIndex();
        ++size;
    }
    return true;
}
Also used : DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 35 with DBIDIter

use of de.lmu.ifi.dbs.elki.database.ids.DBIDIter 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)

Aggregations

DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)329 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)78 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)76 DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)72 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)70 ArrayList (java.util.ArrayList)61 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)56 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)56 MaterializedDoubleRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation)55 OutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta)55 DoubleMinMax (de.lmu.ifi.dbs.elki.math.DoubleMinMax)54 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)53 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)42 ArrayModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs)40 DoubleDBIDListIter (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)34 MeanVariance (de.lmu.ifi.dbs.elki.math.MeanVariance)31 BasicOutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.BasicOutlierScoreMeta)30 ArrayDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs)25 ModifiableDoubleDBIDList (de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList)24 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)21