Example usage for org.jdom2.xpath XPath selectSingleNode

List of usage examples for org.jdom2.xpath XPath selectSingleNode

Introduction

In this page you can find the example usage for org.jdom2.xpath XPath selectSingleNode.

Prototype

public static Object selectSingleNode(Object context, String path) throws JDOMException 

Source Link

Document

Evaluates the wrapped XPath expression and returns the first entry in the list of selected nodes (or atomics).

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 {// w  w w .  j  a  v a 2  s .c  om
        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:Erudite_SW_runCmd.java

License:Apache License

private void loadInputs(Document NNetMap) {
    try {//  w w w.  j a v  a2 s  .  co  m
        //use XPath to find all synapse elements recieving input data
        int iN = 0;
        do {
            String inNodeID = Erudite_gui.inputNID[iN];
            Element inNode = (Element) XPath.selectSingleNode(Erudite_gui.NNetMap,
                    "/NNETWORK/SUBNET/LAYER/NEURODE[@N_ID='" + inNodeID + "']");
            inNode.setAttribute("ACTIVE", "1");
            inNode.setAttribute("ACTIVITY", String.valueOf(Erudite_gui.input[iN]));
            iN++;
        } while (iN < Erudite_gui.input.length);

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Erudite_SW_runCmd.java

License:Apache License

public void getOutputs(Document NNetMap) throws JDOMException {
    Erudite_gui.output = new double[Erudite_gui.outputNID.length];
    int oN = 0;/*from w  w  w.j a v a2 s.  co  m*/
    do {
        String outNodeID = Erudite_gui.outputNID[oN];
        Element outNode = (Element) XPath.selectSingleNode(Erudite_gui.NNetMap,
                "/NNETWORK/SUBNET/LAYER/NEURODE[@N_ID='" + outNodeID + "']");
        Erudite_gui.output[oN] = java.lang.Double.parseDouble(outNode.getAttributeValue("ACTIVITY"));
        oN++;
    } while (oN < Erudite_gui.output.length);

}

From source file:EvaluateNeurode.java

License:Apache License

public synchronized double sumInput(Element node) throws JDOMException {
    List SynIns = node.getChildren("SYNAPSE");
    double bias = java.lang.Double.parseDouble(node.getAttributeValue("BIAS"));
    double sumInputs = 0 + bias;
    for (Iterator itSI = SynIns.iterator(); itSI.hasNext();) {
        Element SynapseI = (Element) itSI.next();
        double weight = java.lang.Double.parseDouble(SynapseI.getAttributeValue("WEIGHT"));
        String OrgNodeID = SynapseI.getAttributeValue("ORG_NEURODE");
        Element OrgNode = (Element) XPath.selectSingleNode(Erudite_gui.NNetMap,
                "/NNETWORK/SUBNET/LAYER/NEURODE[@N_ID='" + OrgNodeID + "']");
        int activeTF = java.lang.Integer.parseInt(OrgNode.getAttributeValue("ACTIVE"));
        if (activeTF == 1) {
            double value = java.lang.Double.parseDouble(OrgNode.getAttributeValue("ACTIVITY"));
            sumInputs += weight * value;
        } else if (activeTF == -1) {
            int TFcheck = java.lang.Integer.parseInt(OrgNode.getAttributeValue("ACTIVE"));
            while (TFcheck != 1) {
                TFcheck = java.lang.Integer.parseInt(OrgNode.getAttributeValue("ACTIVE"));
            }/*from   ww  w  .  jav a2  s  .  c o  m*/
            double value = java.lang.Double.parseDouble(OrgNode.getAttributeValue("ACTIVITY"));
            sumInputs += weight * value;
        } else if (activeTF == 0) {
            sumInputs += 0;
        }

    }
    return sumInputs;

}