use of de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution in project elki by elki-project.
the class GeneratorXMLDatabaseConnection method processElementUniform.
/**
* Process a 'uniform' Element in the XML stream.
*
* @param cluster
* @param cur Current document nod
*/
private void processElementUniform(GeneratorSingleCluster cluster, Node cur) {
double min = 0.0;
double max = 1.0;
String minstr = ((Element) cur).getAttribute(ATTR_MIN);
if (minstr != null && minstr.length() > 0) {
min = ParseUtil.parseDouble(minstr);
}
String maxstr = ((Element) cur).getAttribute(ATTR_MAX);
if (maxstr != null && maxstr.length() > 0) {
max = ParseUtil.parseDouble(maxstr);
}
// *** new uniform generator
Random random = cluster.getNewRandomGenerator();
Distribution generator = new UniformDistribution(min, max, random);
cluster.addGenerator(generator);
// TODO: check for unknown attributes.
XMLNodeIterator iter = new XMLNodeIterator(cur.getFirstChild());
while (iter.hasNext()) {
Node child = iter.next();
if (child.getNodeType() == Node.ELEMENT_NODE) {
LOG.warning("Unknown element in XML specification file: " + child.getNodeName());
}
}
}
use of de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution in project elki by elki-project.
the class AttributeWiseCDFNormalization method filter.
@Override
public MultipleObjectsBundle filter(MultipleObjectsBundle objects) {
if (objects.dataLength() == 0) {
return objects;
}
for (int r = 0; r < objects.metaLength(); r++) {
SimpleTypeInformation<?> type = (SimpleTypeInformation<?>) objects.meta(r);
final List<?> column = (List<?>) objects.getColumn(r);
if (!TypeUtil.NUMBER_VECTOR_FIELD.isAssignableFromType(type)) {
continue;
}
@SuppressWarnings("unchecked") final List<V> castColumn = (List<V>) column;
// Get the replacement type information
@SuppressWarnings("unchecked") final VectorFieldTypeInformation<V> castType = (VectorFieldTypeInformation<V>) type;
factory = FilterUtil.guessFactory(castType);
// Scan to find the best
final int dim = castType.getDimensionality();
dists = new ArrayList<>(dim);
// Scratch space for testing:
double[] test = estimators.size() > 1 ? new double[castColumn.size()] : null;
// We iterate over dimensions, this kind of filter needs fast random
// access.
Adapter adapter = new Adapter();
for (int d = 0; d < dim; d++) {
adapter.dim = d;
Distribution dist = findBestFit(castColumn, adapter, d, test);
// We want them to remain 0, instead of - usually - becoming constant .5
if (dist instanceof UniformDistribution) {
dist = constantZero(castColumn, adapter) ? new UniformDistribution(0., 1.) : dist;
}
dists.add(dist);
}
// Normalization scan
double[] buf = new double[dim];
for (int i = 0; i < objects.dataLength(); i++) {
final V obj = castColumn.get(i);
for (int d = 0; d < dim; d++) {
buf[d] = dists.get(d).cdf(obj.doubleValue(d));
}
castColumn.set(i, factory.newNumberVector(buf));
}
}
return objects;
}
Aggregations