Search in sources :

Example 11 with Distribution

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);
}
Also used : UniformDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution) Distribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.Distribution) NormalDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.NormalDistribution) Test(org.junit.Test)

Example 12 with Distribution

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());
        }
    }
}
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 13 with Distribution

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());
        }
    }
}
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) GammaDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.GammaDistribution) XMLNodeIterator(de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)

Example 14 with Distribution

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());
        }
    }
}
Also used : Random(java.util.Random) HaltonUniformDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.HaltonUniformDistribution) 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) XMLNodeIterator(de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)

Example 15 with Distribution

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

Distribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.Distribution)15 UniformDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution)12 NormalDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.NormalDistribution)11 Test (org.junit.Test)6 Random (java.util.Random)5 GammaDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.GammaDistribution)4 HaltonUniformDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.HaltonUniformDistribution)4 XMLNodeIterator (de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)4 Element (org.w3c.dom.Element)4 Node (org.w3c.dom.Node)4 ArrayList (java.util.ArrayList)3 Model (de.lmu.ifi.dbs.elki.data.model.Model)2 GeneratorSingleCluster (de.lmu.ifi.dbs.elki.data.synthetic.bymodel.GeneratorSingleCluster)2 SimpleTypeInformation (de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation)2 VectorFieldTypeInformation (de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation)2 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)2 List (java.util.List)2 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)1 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)1 DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)1