Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void backpropagation(){
- do {
- // Increment number of epochs
- currentEpoch++;
- for (DataTuple tuple : dataTuples) {
- // Set values of input neuron to current data tuple
- setInput(tuple);
- //Forward propagation by recursion
- for (Neuron n : outputNeurons) {
- n.calculateOutput();
- }
- // Calculate error for each output neuron with their corresponding target value
- for (Neuron n : outputNeurons) {
- // Calculate error for output neuron UP
- if(n==outputUp)
- outputUp.calculateError(tuple.normalizeMoveUp(tuple.DirectionChosen));
- // Calculate error for output neuron RIGHT
- else if(n==outputRight)
- outputRight.calculateError(tuple.normalizeMoveRight(tuple.DirectionChosen));
- // Calculate error for output neuron DOWN
- else if(n==outputDown)
- outputDown.calculateError(tuple.normalizeMoveDown(tuple.DirectionChosen));
- // Calculate error for output neuron LEFT
- else if(n==outputLeft)
- outputLeft.calculateError(tuple.normalizeMoveLeft(tuple.DirectionChosen));
- // Calculate error for output neuron NEUTRAL
- else if(n==outputNeutral)
- outputNeutral.calculateError(tuple.normalizeMoveNeutral(tuple.DirectionChosen));
- }
- // Calculate the error for the hidden layer
- for (Neuron n : HiddenNeurons) {
- n.calculateError(1);
- }
- // Update the weights of the edges between neurons
- for (Edge e : edges) {
- e.calculateWeights();
- }
- // Update the bias of the neurons
- for (Neuron n : network) {
- n.calculateBias();
- }
- }
- // continue for x amount of epochs
- } while (currentEpoch<numberOfEpochs);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement