Search in sources :

Example 1 with XMLNodeIterator

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

the class GeneratorXMLDatabaseConnection method processElementRotate.

/**
 * Process a 'rotate' Element in the XML stream.
 *
 * @param cluster
 * @param cur Current document nod
 */
private void processElementRotate(GeneratorSingleCluster cluster, Node cur) {
    int axis1 = 0;
    int axis2 = 0;
    double angle = 0.0;
    String a1str = ((Element) cur).getAttribute(ATTR_AXIS1);
    if (a1str != null && a1str.length() > 0) {
        axis1 = ParseUtil.parseIntBase10(a1str);
    }
    String a2str = ((Element) cur).getAttribute(ATTR_AXIS2);
    if (a2str != null && a2str.length() > 0) {
        axis2 = ParseUtil.parseIntBase10(a2str);
    }
    String anstr = ((Element) cur).getAttribute(ATTR_ANGLE);
    if (anstr != null && anstr.length() > 0) {
        angle = ParseUtil.parseDouble(anstr);
    }
    if (axis1 <= 0 || axis1 > cluster.getDim()) {
        throw new AbortException("Invalid axis1 number given in specification file.");
    }
    if (axis2 <= 0 || axis2 > cluster.getDim()) {
        throw new AbortException("Invalid axis2 number given in specification file.");
    }
    if (axis1 == axis2) {
        throw new AbortException("Invalid axis numbers given in specification file.");
    }
    // Add rotation to cluster.
    cluster.addRotation(axis1 - 1, axis2 - 1, Math.toRadians(angle));
    // 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 2 with XMLNodeIterator

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

the class GeneratorXMLDatabaseConnection method processElementDataset.

/**
 * Process a 'dataset' Element in the XML stream.
 *
 * @param gen Generator
 * @param cur Current document nod
 */
private void processElementDataset(GeneratorMain gen, Node cur) {
    // *** get parameters
    String seedstr = ((Element) cur).getAttribute(ATTR_SEED);
    if (clusterRandom != RandomFactory.DEFAULT && seedstr != null && seedstr.length() > 0) {
        clusterRandom = new RandomFactory((long) (ParseUtil.parseIntBase10(seedstr) * sizescale));
    }
    String testmod = ((Element) cur).getAttribute(ATTR_TEST);
    if (testmod != null && testmod.length() > 0) {
        testAgainstModel = Boolean.valueOf(ParseUtil.parseIntBase10(testmod) != 0);
    }
    // TODO: check for unknown attributes.
    XMLNodeIterator iter = new XMLNodeIterator(cur.getFirstChild());
    while (iter.hasNext()) {
        Node child = iter.next();
        if (TAG_CLUSTER.equals(child.getNodeName())) {
            processElementCluster(gen, child);
        } else if (TAG_STATIC.equals(child.getNodeName())) {
            processElementStatic(gen, child);
        } else 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) RandomFactory(de.lmu.ifi.dbs.elki.utilities.random.RandomFactory) XMLNodeIterator(de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)

Example 3 with XMLNodeIterator

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

the class GeneratorXMLDatabaseConnection method processElementCluster.

/**
 * Process a 'cluster' Element in the XML stream.
 *
 * @param gen Generator
 * @param cur Current document nod
 */
private void processElementCluster(GeneratorMain gen, Node cur) {
    int size = -1;
    double overweight = 1.0;
    String sizestr = ((Element) cur).getAttribute(ATTR_SIZE);
    if (sizestr != null && sizestr.length() > 0) {
        size = (int) (ParseUtil.parseIntBase10(sizestr) * sizescale);
    }
    String name = ((Element) cur).getAttribute(ATTR_NAME);
    String dcostr = ((Element) cur).getAttribute(ATTR_DENSITY);
    if (dcostr != null && dcostr.length() > 0) {
        overweight = ParseUtil.parseDouble(dcostr);
    }
    if (size < 0) {
        throw new AbortException("No valid cluster size given in specification file.");
    }
    if (name == null || name.length() == 0) {
        throw new AbortException("No cluster name given in specification file.");
    }
    // *** add new cluster object
    Random newRand = clusterRandom.getSingleThreadedRandom();
    GeneratorSingleCluster cluster = new GeneratorSingleCluster(name, size, overweight, newRand);
    // TODO: check for unknown attributes.
    XMLNodeIterator iter = new XMLNodeIterator(cur.getFirstChild());
    while (iter.hasNext()) {
        Node child = iter.next();
        if (TAG_UNIFORM.equals(child.getNodeName())) {
            processElementUniform(cluster, child);
        } else if (TAG_NORMAL.equals(child.getNodeName())) {
            processElementNormal(cluster, child);
        } else if (TAG_GAMMA.equals(child.getNodeName())) {
            processElementGamma(cluster, child);
        } else if (TAG_HALTON.equals(child.getNodeName())) {
            processElementHalton(cluster, child);
        } else if (TAG_ROTATE.equals(child.getNodeName())) {
            processElementRotate(cluster, child);
        } else if (TAG_TRANSLATE.equals(child.getNodeName())) {
            processElementTranslate(cluster, child);
        } else if (TAG_CLIP.equals(child.getNodeName())) {
            processElementClipping(cluster, child);
        } else if (child.getNodeType() == Node.ELEMENT_NODE) {
            LOG.warning("Unknown element in XML specification file: " + child.getNodeName());
        }
    }
    gen.addCluster(cluster);
}
Also used : Random(java.util.Random) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) GeneratorSingleCluster(de.lmu.ifi.dbs.elki.data.synthetic.bymodel.GeneratorSingleCluster) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) XMLNodeIterator(de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)

Example 4 with XMLNodeIterator

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

the class GeneratorXMLDatabaseConnection method processElementNormal.

/**
 * Process a 'normal' Element in the XML stream.
 *
 * @param cluster
 * @param cur Current document nod
 */
private void processElementNormal(GeneratorSingleCluster cluster, Node cur) {
    double mean = 0.0;
    double stddev = 1.0;
    String meanstr = ((Element) cur).getAttribute(ATTR_MEAN);
    if (meanstr != null && meanstr.length() > 0) {
        mean = ParseUtil.parseDouble(meanstr);
    }
    String stddevstr = ((Element) cur).getAttribute(ATTR_STDDEV);
    if (stddevstr != null && stddevstr.length() > 0) {
        stddev = ParseUtil.parseDouble(stddevstr);
    }
    // *** New normal distribution generator
    Random random = cluster.getNewRandomGenerator();
    Distribution generator = new NormalDistribution(mean, stddev, 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) NormalDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.NormalDistribution) 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 5 with XMLNodeIterator

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

the class GeneratorXMLDatabaseConnection method processElementStatic.

/**
 * Process a 'static' cluster Element in the XML stream.
 *
 * @param gen Generator
 * @param cur Current document nod
 */
private void processElementStatic(GeneratorMain gen, Node cur) {
    String name = ((Element) cur).getAttribute(ATTR_NAME);
    if (name == null) {
        throw new AbortException("No cluster name given in specification file.");
    }
    ArrayList<double[]> points = new ArrayList<>();
    // TODO: check for unknown attributes.
    XMLNodeIterator iter = new XMLNodeIterator(cur.getFirstChild());
    while (iter.hasNext()) {
        Node child = iter.next();
        if (TAG_POINT.equals(child.getNodeName())) {
            processElementPoint(points, child);
        } else if (child.getNodeType() == Node.ELEMENT_NODE) {
            LOG.warning("Unknown element in XML specification file: " + child.getNodeName());
        }
    }
    // *** add new cluster object
    GeneratorStatic cluster = new GeneratorStatic(name, points);
    gen.addCluster(cluster);
    if (LOG.isVerbose()) {
        LOG.verbose("Loaded cluster " + cluster.name + " from specification.");
    }
}
Also used : GeneratorStatic(de.lmu.ifi.dbs.elki.data.synthetic.bymodel.GeneratorStatic) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) 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