Example usage for org.jdom2 Element getParentElement

List of usage examples for org.jdom2 Element getParentElement

Introduction

In this page you can find the example usage for org.jdom2 Element getParentElement.

Prototype

final public Element getParentElement() 

Source Link

Document

A convenience method that returns any parent element for this element, or null if the element is unattached or is a root element.

Usage

From source file:TrainNet.java

License:Apache License

public void adjustWeights(Element node) throws JDOMException {
    //each backward connection's weight to equal current weight + LEARNING_RATE * output of neuron at other end of connection * this neuron's errorGradient
    int lock = java.lang.Integer
            .parseInt(node.getParentElement().getParentElement().getAttributeValue("ADJUST_LOCK"));
    Iterator synapses = node.getChildren().iterator(); //iterate through incoming synapses and adjust weights
    do {//from w w w .j av a  2s .  c  o  m
        Element currentSynapse = (Element) synapses.next();
        String OrgNodeID = currentSynapse.getAttributeValue("ORG_NEURODE");
        //if OrgNode !=input then continue else abort/return
        if (!"INPUT".equals(OrgNodeID) && lock != 1) {
            Element OrgNode = (Element) XPath.selectSingleNode(Erudite_gui.NNetMap,
                    "/NNETWORK/SUBNET/LAYER/NEURODE[@N_ID='" + OrgNodeID + "']");
            double weight = java.lang.Double.parseDouble(currentSynapse.getAttributeValue("WEIGHT"))
                    + (learningRate * (java.lang.Double.parseDouble(OrgNode.getAttributeValue("ACTIVITY"))
                            * java.lang.Double.parseDouble(node.getAttributeValue("NNET_V4"))));
            currentSynapse.setAttribute("WEIGHT", String.valueOf(weight));
        }
    } while (synapses.hasNext());
}

From source file:TrainNet.java

License:Apache License

public void adjustBias(Element node) throws JDOMException {
    //adjusted bias = current bias + LEARNING_RATE * errorGradient
    int lock = java.lang.Integer
            .parseInt(node.getParentElement().getParentElement().getAttributeValue("ADJUST_LOCK"));
    Element currentSynapse = (Element) node.getChild("SYNAPSE");
    String OrgNodeID = currentSynapse.getAttributeValue("ORG_NEURODE");
    if (!"INPUT".equals(OrgNodeID) && lock != 1) {
        double bias = java.lang.Double.parseDouble(node.getAttributeValue("BIAS"))
                + (learningRate * java.lang.Double.parseDouble(node.getAttributeValue("NNET_V4"))); //original ver
        node.setAttribute("BIAS", String.valueOf(bias));
    }//from  w w w .j  av  a  2s.  c o m
}

From source file:Erudite_SW_trainCmd.java

License:Apache License

private void getErrorGradient(Element node) throws JDOMException {
    //if-then-else for output/hidden/input layers, if-then for transfer functions, compute error gradient and update nnet map
    String layerType = node.getParentElement().getAttributeValue("LAYER_NAME").toString();
    int xfer = Integer.parseInt(node.getParentElement().getAttributeValue("TRANSFER_FUNCTION"));
    String nid = node.getAttributeValue("N_ID").toString();
    if (layerType.equals("OUTPUT")) { //if computing output neurode error gradient
        if (xfer == 1) { //if hyperbolic tangent transfer function
            for (int i = 0; i < Erudite_gui.outputNID.length; i++) {
                if (nid.equals(Erudite_gui.outputNID[i])) {
                    double error = Erudite_gui.desiredOutput[i] - Erudite_gui.output[i];
                    double errorGradient = error * ((1 - Erudite_gui.output[i]) * (1 + Erudite_gui.output[i]));
                    node.setAttribute("NNET_V4", String.valueOf(errorGradient));
                }/* w w  w .  j ava2 s  .com*/
            }
        } else if (xfer == 2) { //if sigmoid transfer function function
            for (int i = 0; i < Erudite_gui.outputNID.length; i++) {
                if (nid.equals(Erudite_gui.outputNID[i])) {
                    double error = Erudite_gui.desiredOutput[i] - Erudite_gui.output[i];
                    double errorGradient = error * (Erudite_gui.output[i] * (1 - Erudite_gui.output[i]));
                    node.setAttribute("NNET_V4", String.valueOf(errorGradient));
                }
            }
        }
    } else if (layerType.equals("HIDDEN") || layerType.equals("INPUT")) { //if computing hidden or input neurode error gradient
        if (xfer == 1) {
            double sumWouts = 0.0;
            double nodeActivity = java.lang.Double.parseDouble(node.getAttributeValue("ACTIVITY"));
            java.util.List outputs = XPath.newInstance("//SYNAPSE[@ORG_NEURODE = '" + nid + "']")
                    .selectNodes(Erudite_gui.NNetMap);
            Iterator synapseO = outputs.iterator();
            do {
                Element currentNode = (Element) synapseO.next();
                sumWouts += java.lang.Double.parseDouble(currentNode.getAttributeValue("WEIGHT"))
                        * java.lang.Double
                                .parseDouble(currentNode.getParentElement().getAttributeValue("NNET_V4"));
            } while (synapseO.hasNext());
            double errorGradient = sumWouts * ((1 - nodeActivity) * (1 + nodeActivity));
            node.setAttribute("NNET_V4", String.valueOf(errorGradient));
        } else if (xfer == 2) {
            double sumWouts = 0.0;
            double nodeActivity = java.lang.Double.parseDouble(node.getAttributeValue("ACTIVITY"));
            java.util.List outputs = XPath.newInstance("//SYNAPSE[@ORG_NEURODE = '" + nid + "']")
                    .selectNodes(Erudite_gui.NNetMap);
            Iterator synapseO = outputs.iterator();
            do {
                Element currentNode = (Element) synapseO.next();
                sumWouts += java.lang.Double.parseDouble(currentNode.getAttributeValue("WEIGHT"))
                        * java.lang.Double
                                .parseDouble(currentNode.getParentElement().getAttributeValue("NNET_V4"));
            } while (synapseO.hasNext());
            double errorGradient = sumWouts * (nodeActivity * (1 - nodeActivity));
            node.setAttribute("NNET_V4", String.valueOf(errorGradient));
        }

    }

}

From source file:EvaluateNeurode.java

License:Apache License

public synchronized void output(Element node, double summedInputs) throws JDOMException {
    int xfer = Integer.parseInt(node.getParentElement().getAttributeValue("TRANSFER_FUNCTION"));
    if (xfer == 1) {
        double output = transferFunction(summedInputs);
        node.setAttribute("ACTIVITY", String.valueOf(output));
        node.setAttribute("ACTIVE", "1");
    } else if (xfer == 2) {
        double output = transferFunction2(summedInputs);
        node.setAttribute("ACTIVITY", String.valueOf(output));
        node.setAttribute("ACTIVE", "1");
    }/*from   w  w w.  ja  v  a2  s . c o m*/

}

From source file:AL_gui.java

License:Apache License

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here:
    try {//from w w  w .j  ava 2s .  c om
        jLabel2.setForeground(Color.BLACK);
        jLabel2.setText("Randomizing synpase weights.");
        java.util.List synapses = XPath.newInstance("//SYNAPSE").selectNodes(AL_gui.NNetMap);

        for (Iterator SynIt = synapses.iterator(); SynIt.hasNext();) {
            Element synapse = (Element) SynIt.next();
            String layerType = synapse.getParentElement().getParentElement().getAttributeValue("LAYER_NAME")
                    .toString();
            if (layerType.equals("INPUT")) {
                synapse.setAttribute("WEIGHT", "1.00");
            } else {
                Random rnd = new Random();
                synapse.setAttribute("WEIGHT", getRandomValue(rnd, low, high, decpl));
            }
        }
        jLabel2.setForeground(Color.BLACK);
        jLabel2.setText("Randomizing neurode biases.");
        java.util.List nodes = XPath.newInstance("//NEURODE").selectNodes(AL_gui.NNetMap);
        for (Iterator It = nodes.iterator(); It.hasNext();) {
            Element node = (Element) It.next();
            String layerType = node.getParentElement().getAttributeValue("LAYER_NAME").toString();
            if (layerType.equals("INPUT")) {
                node.setAttribute("BIAS", "0.00");
            } else {
                Random rnd = new Random();
                node.setAttribute("BIAS", getRandomValue(rnd, low, high, decpl));
            }
        }
        jLabel2.setForeground(Color.BLACK);
        jLabel2.setText("All Done.");

    } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(AL_gui.this, "Problem encountered while saving file\n" + e.toString(),
                "Warning", JOptionPane.WARNING_MESSAGE);
    }
}

From source file:ataraxis.passwordmanager.XMLHandler.java

License:Open Source License

/**
 * Get a AccountEntry with the given id.
 * //from  w  w  w . j a v  a 2  s . c om
 * @param id
 * @return the requested AccountEntry
 * @throws EntryDoesNotExistException
 */
public AccountEntry getAccountEntry(String id) throws EntryDoesNotExistException {
    AccountEntry accountEntry = null;

    try {
        Element accountElement = getElement(id);
        if (accountElement != null) {
            if (!isGroupElement(id)) {
                String entryId = accountElement.getAttributeValue("id");
                accountEntry = new AccountEntry(entryId);
                accountEntry.setName(accountElement.getChildText("name"));
                accountEntry.setPassword(accountElement.getChildText("password"));
                accountEntry.setLink(accountElement.getChildText("link"));
                accountEntry.setComment(accountElement.getChildText("comment"));

                String parentId = accountElement.getParentElement().getAttributeValue("id");

                if (parentId != null && isGroupElement(parentId)) {
                    GroupEntry group = new GroupEntry(parentId);
                    accountEntry.setParentEntry(group);
                }
            }
        }
        /*else
        {
           throw new EntryDoesNotExistException("entry not found");
        }*/
    } catch (JDOMException e) {
        logger.fatal(e);
        throw new EntryDoesNotExistException("entry not found");
    }

    return accountEntry;
}

From source file:com.ardor3d.extension.model.collada.jdom.ColladaAnimUtils.java

License:Open Source License

/**
 * Gather up all animation channels based on what nodes they affect.
 * //from  ww w  .  j a  v  a 2  s.c o m
 * @param channelMap
 * @param animationRoot
 * @param animationItemRoot
 */
@SuppressWarnings("unchecked")
private void parseAnimations(final Multimap<Element, TargetChannel> channelMap, final Element animationRoot,
        final AnimationItem animationItemRoot) {
    if (animationRoot.getChild("animation") != null) {
        Attribute nameAttribute = animationRoot.getAttribute("name");
        if (nameAttribute == null) {
            nameAttribute = animationRoot.getAttribute("id");
        }
        final String name = nameAttribute != null ? nameAttribute.getValue() : "Default";

        final AnimationItem animationItem = new AnimationItem(name);
        animationItemRoot.getChildren().add(animationItem);

        for (final Element animationElement : animationRoot.getChildren("animation")) {
            parseAnimations(channelMap, animationElement, animationItem);
        }
    }
    if (animationRoot.getChild("channel") != null) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("\n-- Parsing animation channels --");
        }
        final List<Element> channels = animationRoot.getChildren("channel");
        for (final Element channel : channels) {
            final String source = channel.getAttributeValue("source");

            final String targetString = channel.getAttributeValue("target");
            if (targetString == null || targetString.isEmpty()) {
                return;
            }

            final Target target = processTargetString(targetString);
            if (logger.isLoggable(Level.FINE)) {
                logger.fine("channel source: " + target.toString());
            }
            final Element targetNode = findTargetNode(target);
            if (targetNode == null || !_dataCache.getTransformTypes().contains(targetNode.getName())) {
                // TODO: pass with warning or exception or nothing?
                // throw new ColladaException("No target transform node found for target: " + target, target);
                continue;
            }
            if ("rotate".equals(targetNode.getName())) {
                target.accessorType = AccessorType.Vector;
                target.accessorIndexX = 3;
            }

            channelMap.put(targetNode.getParentElement(),
                    new TargetChannel(target, targetNode, source, animationItemRoot));
        }
    }
}

From source file:com.bc.fiduceo.reader.airs.EosCoreMetaParser.java

License:Open Source License

Element parseFromString(String text) {

    Element rootElem = new Element("odl");
    Element current = rootElem;
    StringTokenizer lineFinder = new StringTokenizer(text, "\n");

    while (lineFinder.hasMoreTokens()) {
        String line = lineFinder.nextToken();
        line = line.trim();//from  www.  java2  s . com
        if (line.isEmpty()) {
            continue;
        }
        if (line.startsWith("GROUP")) {
            if (line.contains("GROUPTYPE")) {
                continue;
            }
            current = this.startGroup(current, line);
        } else if (line.startsWith("OBJECT")) {
            current = this.startObject(current, line);
        } else if (line.startsWith("END_OBJECT")) {
            this.endObject(current, line);
            current = current.getParentElement();
        } else if (line.startsWith("END_GROUP")) {
            this.endGroup(current, line);
            current = current.getParentElement();
        } else {
            this.addField(current, line);
        }
    }
    return rootElem;
}

From source file:com.c4om.utils.xmlutils.XPathUtils.java

License:Apache License

/**
 * It returns a path to a single element. The element (and its ancestors) is distinguished via its 
 * attributes set./*from   w w  w. j a va 2 s . c o m*/
 * @param currentElement the element whose path is to be calculated
 * @param contextElement the element to which a relative path will be calculated (null for an absolute path).
 * @return the path.
 * @throws IllegalArgumentException if the currentElement is not descendant of the contextElement
 * 
 */
public static String generateAttributeBasedPath(Element currentElement, Element contextElement) {
    StringBuilder builder = new StringBuilder();
    Element parent = currentElement.getParentElement();
    if (contextElement != null) {
        IteratorIterable<Element> descendants = contextElement.getDescendants(Filters.element());
        Set<Element> descendantsSet = ImmutableSet.copyOf((Iterable<Element>) descendants);
        if (!descendantsSet.contains(currentElement)) {
            throw new IllegalArgumentException("The provided element is not descendant of the stopElement");
        }
    }
    if (parent != contextElement) {
        String pathToParent = generateAttributeBasedPath(parent, contextElement);
        builder.append(pathToParent);
    } else if (contextElement != null) {
        builder.insert(0, ".");
    }
    builder.append("/");
    builder.append(currentElement.getQualifiedName());
    String filter = "[" + generateAttributesFilter(currentElement.getAttributes()) + "]";
    builder.append(filter);
    String result = builder.toString();
    return result;
}

From source file:com.lapis.jsfexporter.xml.XMLExportType.java

License:Apache License

@Override
public Element exportRow(IExportRow row) {
    Element currentElement = (Element) row.getParentRowId();
    if (currentElement == null) {
        currentElement = rootElement;//  w  w  w . jav  a2 s  .co  m
    }

    for (String namePart : row.getName()) {
        Element subElement = new Element(cleanElementName(namePart));
        currentElement.addContent(subElement);
        currentElement = subElement;
    }

    for (IExportCell cell : row.getCells()) {
        Element cellElement = currentElement;
        for (String namePart : cell.getName()) {
            Element subElement = cellElement.getChild(namePart);
            if (subElement == null) {
                subElement = new Element(cleanElementName(namePart));
                cellElement.addContent(subElement);
            }
            cellElement = subElement;
        }

        if (!cellElement.getText().equals("")) {
            String cellName = cellElement.getName();
            cellElement = cellElement.getParentElement();
            Element newCellElement = new Element(cellName);
            cellElement.addContent(newCellElement);
            cellElement = newCellElement;
        }
        cellElement.setText(cell.getValue());
    }

    return currentElement;
}