public void format(AbstractNeuralNet source, XmlElement xml) { // Marshal input layer xml.add(source.inputLayer, "input-layer"); // Marshal hidden layers xml.add(source.hiddenLayers, "hidden-layers"); // Marshal output layers xml.add(source.outputLayer, "output-layer"); }
public AbstractNeuralNet parse(XmlElement xml) { // Resulting object AbstractNeuralNet result = (AbstractNeuralNet) xml.object(); // Unmarshal input layer result.inputLayer = xml.<InputLayer>get("input-layer"); // Unmarshal hidden layers result.hiddenLayers = xml.<ArrayList<LinkedLayer>>get("hidden-layers"); // Update neuron references ILayer<? extends INeuron> previousLayer = result.inputLayer; for (LinkedLayer hiddenLayer : result.hiddenLayers) { for (int i = 0; i < hiddenLayer.getNofneurons(); i++) { Link[] links = hiddenLayer.getNeuron(i).getLinks(); for (int j = 0; j < links.length; j++) { links[j].setTarget(hiddenLayer.getNeuron(i)); if (!links[j].isBroken() && j < previousLayer.getMaxnofneurons()) links[j].setOrigin(previousLayer.getNeuron(j)); else links[j].setOrigin(null); } } previousLayer = hiddenLayer; } // Unmarshal output layer result.outputLayer = xml.<LinkedLayer>get("output-layer"); // Update neuron references for (int i = 0; i < result.outputLayer.getNofneurons(); i++) { Link[] links = ((LinkedNeuron) result.outputLayer.getNeuron(i)).getLinks(); for (int j = 0; j < links.length; j++) { links[j].setTarget(result.outputLayer.getNeuron(i)); if (!links[j].isBroken() && j < previousLayer.getMaxnofneurons()) links[j].setOrigin(previousLayer.getNeuron(j)); else links[j].setOrigin(null); } } // Return result return result; }