use of de.lmu.ifi.dbs.elki.math.statistics.distribution.Distribution in project elki by elki-project.
the class BestFitEstimatorTest method testExtreme.
@Test
public void testExtreme() {
BestFitEstimator est = init();
Distribution edist = est.estimate(new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }, DoubleArrayAdapter.STATIC);
assertNotNull("Wrong class of distribution", edist);
}
use of de.lmu.ifi.dbs.elki.math.statistics.distribution.Distribution 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.Distribution in project elki by elki-project.
the class GeneratorXMLDatabaseConnection method processElementGamma.
/**
* Process a 'gamma' Element in the XML stream.
*
* @param cluster
* @param cur Current document nod
*/
private void processElementGamma(GeneratorSingleCluster cluster, Node cur) {
double k = 1.0;
double theta = 1.0;
String kstr = ((Element) cur).getAttribute(ATTR_K);
if (kstr != null && kstr.length() > 0) {
k = ParseUtil.parseDouble(kstr);
}
String thetastr = ((Element) cur).getAttribute(ATTR_THETA);
if (thetastr != null && thetastr.length() > 0) {
theta = ParseUtil.parseDouble(thetastr);
}
// *** New normal distribution generator
Random random = cluster.getNewRandomGenerator();
Distribution generator = new GammaDistribution(k, theta, 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.Distribution in project elki by elki-project.
the class GeneratorXMLDatabaseConnection method processElementHalton.
/**
* Process a 'halton' Element in the XML stream.
*
* @param cluster
* @param cur Current document nod
*/
private void processElementHalton(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 HaltonUniformDistribution(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.Distribution 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