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];
}
}
}
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 };
}
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;
}
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;
}
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;
}
Aggregations