Search in sources :

Example 6 with UniformDistribution

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());
        }
    }
}
Also used : Random(java.util.Random) Element(org.w3c.dom.Element) Distribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.Distribution) NormalDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.NormalDistribution) UniformDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution) GammaDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.GammaDistribution) HaltonUniformDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.HaltonUniformDistribution) Node(org.w3c.dom.Node) UniformDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution) HaltonUniformDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.HaltonUniformDistribution) XMLNodeIterator(de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)

Example 7 with UniformDistribution

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;
}
Also used : UniformDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution) SimpleTypeInformation(de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation) NumberArrayAdapter(de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.NumberArrayAdapter) VectorFieldTypeInformation(de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation) Distribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.Distribution) UniformDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

UniformDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution)7 Test (org.junit.Test)4 Distribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.Distribution)2 SimpleTypeInformation (de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation)1 VectorFieldTypeInformation (de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation)1 StatisticalMoments (de.lmu.ifi.dbs.elki.math.StatisticalMoments)1 GammaDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.GammaDistribution)1 HaltonUniformDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.HaltonUniformDistribution)1 NormalDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.NormalDistribution)1 NumberArrayAdapter (de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.NumberArrayAdapter)1 XMLNodeIterator (de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1