Java Code Examples for org.neuroph.core.NeuralNetwork#setOutputNeurons()
The following examples show how to use
org.neuroph.core.NeuralNetwork#setOutputNeurons() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackPropagationTest.java From NeurophFramework with Apache License 2.0 | 6 votes |
@Test public void testCalculateErrorAndUpdateOutputNeurons() { NeuralNetwork<BackPropagation> nn = new NeuralNetwork<>(); nn.setInputNeurons(new ArrayList<Neuron>() { { add(new Neuron()); add(new Neuron()); } }); nn.setOutputNeurons(new ArrayList<Neuron>() { { add(new Neuron()); } }); nn.setLearningRule(instance); nn.getOutputNeurons().get(0).setDelta(1); instance.calculateErrorAndUpdateOutputNeurons(new double[]{0}); assertTrue(nn.getOutputNeurons().get(0).getDelta() == 0); instance.calculateErrorAndUpdateOutputNeurons(new double[]{0.5}); assertTrue(nn.getOutputNeurons().get(0).getDelta() == 0.5); }
Example 2
Source File: BackPropagationTest.java From NeurophFramework with Apache License 2.0 | 6 votes |
@Test public void testUpdateNetworkWeights() { NeuralNetwork<BackPropagation> nn = new NeuralNetwork<>(); nn.setInputNeurons(new ArrayList<Neuron>() { { add(new Neuron()); add(new Neuron()); } }); nn.setOutputNeurons(new ArrayList<Neuron>() { { add(new Neuron()); } }); nn.setLearningRule(instance); BackPropagation bp1 = Mockito.spy(new BackPropagation()); nn.setLearningRule(bp1); double[] weigths = {1, 2}; bp1.calculateWeightChanges(weigths); Mockito.verify(bp1).calculateErrorAndUpdateOutputNeurons(weigths); Mockito.verify(bp1).calculateErrorAndUpdateHiddenNeurons(); }
Example 3
Source File: NeuralNetworkFactory.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Sets default input and output neurons for network (first layer as input, * last as output) */ public static void setDefaultIO(NeuralNetwork nnet) { ArrayList<Neuron> inputNeuronsList = new ArrayList<>(); Layer firstLayer = nnet.getLayerAt(0); for (Neuron neuron : firstLayer.getNeurons() ) { if (!(neuron instanceof BiasNeuron)) { // dont set input to bias neurons inputNeuronsList.add(neuron); } } List<Neuron> outputNeurons = ((Layer) nnet.getLayerAt(nnet.getLayersCount()-1)).getNeurons(); nnet.setInputNeurons(inputNeuronsList); nnet.setOutputNeurons(outputNeurons); }
Example 4
Source File: BackPropagationTest.java From NeurophFramework with Apache License 2.0 | 5 votes |
@Test public void testCalculateErrorAndUpdateHiddenNeurons() { NeuralNetwork<BackPropagation> nn = new NeuralNetwork<>(); nn.setInputNeurons(new ArrayList<Neuron>() { { add(new Neuron()); add(new Neuron()); } }); nn.setOutputNeurons(new ArrayList<Neuron>() { { add(new Neuron()); } }); nn.setLearningRule(instance); Layer l1 = new Layer(); Layer l2 = new Layer(); Layer l3 = new Layer(); Neuron n = new Neuron(); n.setDelta(0.5); Neuron n1 = new Neuron(); Linear transfer = new Linear(); n1.setTransferFunction(transfer); double weigth = 2; n.addInputConnection(new Connection(n1, n, weigth)); assertTrue(0 == n1.getDelta()); nn.addLayer(l1); nn.addLayer(l2); nn.addLayer(l3); l2.addNeuron(n1); instance.calculateErrorAndUpdateHiddenNeurons(); assertTrue(instance.calculateHiddenNeuronError(n1) == n1.getDelta()); }
Example 5
Source File: NeurophXOR.java From tutorials with MIT License | 5 votes |
public static NeuralNetwork assembleNeuralNetwork() { Layer inputLayer = new Layer(); inputLayer.addNeuron(new Neuron()); inputLayer.addNeuron(new Neuron()); Layer hiddenLayerOne = new Layer(); hiddenLayerOne.addNeuron(new Neuron()); hiddenLayerOne.addNeuron(new Neuron()); hiddenLayerOne.addNeuron(new Neuron()); hiddenLayerOne.addNeuron(new Neuron()); Layer hiddenLayerTwo = new Layer(); hiddenLayerTwo.addNeuron(new Neuron()); hiddenLayerTwo.addNeuron(new Neuron()); hiddenLayerTwo.addNeuron(new Neuron()); hiddenLayerTwo.addNeuron(new Neuron()); Layer outputLayer = new Layer(); outputLayer.addNeuron(new Neuron()); NeuralNetwork ann = new NeuralNetwork(); ann.addLayer(0, inputLayer); ann.addLayer(1, hiddenLayerOne); ConnectionFactory.fullConnect(ann.getLayerAt(0), ann.getLayerAt(1)); ann.addLayer(2, hiddenLayerTwo); ConnectionFactory.fullConnect(ann.getLayerAt(1), ann.getLayerAt(2)); ann.addLayer(3, outputLayer); ConnectionFactory.fullConnect(ann.getLayerAt(2), ann.getLayerAt(3)); ConnectionFactory.fullConnect(ann.getLayerAt(0), ann.getLayerAt(ann.getLayersCount() - 1), false); ann.setInputNeurons(inputLayer.getNeurons()); ann.setOutputNeurons(outputLayer.getNeurons()); ann.setNetworkType(NeuralNetworkType.MULTI_LAYER_PERCEPTRON); return ann; }