Search in sources :

Example 6 with XMLNodeIterator

use of de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator 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 XMLNodeIterator

use of de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator in project elki by elki-project.

the class GeneratorXMLDatabaseConnection method processElementClipping.

/**
 * Process a 'clipping' Element in the XML stream.
 *
 * @param cluster
 * @param cur Current document nod
 */
private void processElementClipping(GeneratorSingleCluster cluster, Node cur) {
    double[] cmin = null, cmax = null;
    String minstr = ((Element) cur).getAttribute(ATTR_MIN);
    if (minstr != null && minstr.length() > 0) {
        cmin = parseVector(minstr);
    }
    String maxstr = ((Element) cur).getAttribute(ATTR_MAX);
    if (maxstr != null && maxstr.length() > 0) {
        cmax = parseVector(maxstr);
    }
    if (cmin == null || cmax == null) {
        throw new AbortException("No or incomplete clipping vectors given.");
    }
    // *** set clipping
    cluster.setClipping(cmin, cmax);
    // 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 : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) XMLNodeIterator(de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)

Example 8 with XMLNodeIterator

use of de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator in project elki by elki-project.

the class GeneratorXMLDatabaseConnection method processElementTranslate.

/**
 * Process a 'translate' Element in the XML stream.
 *
 * @param cluster
 * @param cur Current document nod
 */
private void processElementTranslate(GeneratorSingleCluster cluster, Node cur) {
    double[] offset = null;
    String vstr = ((Element) cur).getAttribute(ATTR_VECTOR);
    if (vstr != null && vstr.length() > 0) {
        offset = parseVector(vstr);
    }
    if (offset == null) {
        throw new AbortException("No translation vector given.");
    }
    // *** add new translation
    cluster.addTranslation(offset);
    // 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 : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) XMLNodeIterator(de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)

Example 9 with XMLNodeIterator

use of de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator 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 10 with XMLNodeIterator

use of de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator 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)

Aggregations

XMLNodeIterator (de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)11 Element (org.w3c.dom.Element)11 Node (org.w3c.dom.Node)11 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)6 Random (java.util.Random)5 Distribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.Distribution)4 GammaDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.GammaDistribution)4 HaltonUniformDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.HaltonUniformDistribution)4 NormalDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.NormalDistribution)4 UniformDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution)4 GeneratorSingleCluster (de.lmu.ifi.dbs.elki.data.synthetic.bymodel.GeneratorSingleCluster)1 GeneratorStatic (de.lmu.ifi.dbs.elki.data.synthetic.bymodel.GeneratorStatic)1 RandomFactory (de.lmu.ifi.dbs.elki.utilities.random.RandomFactory)1 ArrayList (java.util.ArrayList)1