rendered paste bodypackage ann;import java.util.Vector;public class Node { private TransferFunc tfunc; private double inputValue; private double outputValue; private double gradient; private double learningRate; private int layerDepth; private int layerMaxDepth; private boolean bias; private Vector <Link> links=new Vector<Link>(); private double targetValue; public Node(int layerDepth, int layerMaxDepth, TransferFunc tfunc, double learningRate, boolean bias) { this.layerDepth=layerDepth; this.layerMaxDepth=layerMaxDepth; this.learningRate=learningRate; this.tfunc=tfunc; this.bias=bias; if(bias) outputValue=1; } public void connectToNode(Node n) { Link newLink=new Link(this,n); addLink(newLink); n.addLink(newLink); } public void addLink(Link newLink) { links.add(newLink); } public double getInputValue() { return inputValue; } public void setInputValue(double value) { this.inputValue=value; this.outputValue=tfunc.f(value); } public double getOutputValue() { return outputValue; } public void updateValue() { inputValue=0; boolean gotLink=false; if(layerDepth !=0 || !bias) { for(Link link: links) { if(link.getToNode().equals(this)) { inputValue+=link.getWeight()*link.getFromNode().getOutputValue(); gotLink=true; } } if(gotLink) outputValue=tfunc.f(inputValue); } } public void updateWeightChanges() { if(layerDepth!=layerMaxDepth-1) { for(Link link: links) { if(link.getFromNode().equals(this)) { link.setWeightChange(learningRate*gradient*link.getToNode().getOutputValue()); } } } } public void updateGradient() { if(layerDepth==layerMaxDepth-1) { if(!bias) gradient=(targetValue-outputValue)*tfunc.fd(inputValue); } else { double tmpSum=0; for(Link link:links) { if(link.getFromNode().equals(this)) { tmpSum+=link.getToNode().getGradient()*link.getWeight(); } } gradient=tfunc.fd(inputValue)*tmpSum; } } private double getGradient() { return gradient; } public String toString() { return Double.toString(outputValue); } public boolean isBiasNode() { return bias; } public void applyWeightChanges() { for(Link link:links) { if(link.getFromNode().equals(this)) link.applyWeightChange(); } } public void setTargetValue(double targetValue) { this.targetValue=targetValue; } }