use of de.lmu.ifi.dbs.elki.algorithm.clustering.subspace.clique.CLIQUEInterval in project elki by elki-project.
the class CLIQUE method initOneDimensionalUnits.
/**
* Initializes and returns the one dimensional units.
*
* @param database the database to run the algorithm on
* @return the created one dimensional units
*/
private Collection<CLIQUEUnit<V>> initOneDimensionalUnits(Relation<V> database) {
StringBuilder buf = LOG.isDebuggingFiner() ? new StringBuilder(1000) : null;
int dimensionality = RelationUtil.dimensionality(database);
// initialize minima and maxima
double[] minima = new double[dimensionality];
double[] maxima = new double[dimensionality];
Arrays.fill(minima, Double.MAX_VALUE);
Arrays.fill(maxima, -Double.MAX_VALUE);
// update minima and maxima
for (DBIDIter it = database.iterDBIDs(); it.valid(); it.advance()) {
updateMinMax(database.get(it), minima, maxima);
}
for (int i = 0; i < maxima.length; i++) {
maxima[i] += 0.0001;
}
// determine the unit length in each dimension
double[] unit_lengths = new double[dimensionality];
for (int d = 0; d < dimensionality; d++) {
unit_lengths[d] = (maxima[d] - minima[d]) / xsi;
}
if (buf != null) {
FormatUtil.formatTo(buf.append(" minima: "), minima, ", ", FormatUtil.NF2);
FormatUtil.formatTo(buf.append("\n maxima: "), maxima, ", ", FormatUtil.NF2);
FormatUtil.formatTo(buf.append("\n unit lengths: "), unit_lengths, ", ", FormatUtil.NF2);
}
// determine the boundaries of the units
double[][] unit_bounds = new double[xsi + 1][dimensionality];
for (int x = 0; x <= xsi; x++) {
for (int d = 0; d < dimensionality; d++) {
unit_bounds[x][d] = (x < xsi) ? minima[d] + x * unit_lengths[d] : maxima[d];
}
}
if (buf != null) {
FormatUtil.formatTo(buf.append(" unit bounds "), unit_bounds, " [", "]\n", ", ", FormatUtil.NF2);
}
// build the 1 dimensional units
List<CLIQUEUnit<V>> units = new ArrayList<>(xsi * dimensionality);
for (int x = 0; x < xsi; x++) {
for (int d = 0; d < dimensionality; d++) {
units.add(new CLIQUEUnit<V>(new CLIQUEInterval(d, unit_bounds[x][d], unit_bounds[x + 1][d])));
}
}
if (buf != null) {
LOG.debugFiner(buf.append(" total number of 1-dim units: ").append(units.size()).toString());
}
return units;
}
Aggregations