Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1.     private void backpropagation(){
  2.         do {
  3.             // Increment number of epochs
  4.             currentEpoch++;
  5.             for (DataTuple tuple : dataTuples) {
  6.                 // Set values of input neuron to current data tuple
  7.                 setInput(tuple);
  8.                 //Forward propagation by recursion
  9.                 for (Neuron n : outputNeurons) {
  10.                     n.calculateOutput();
  11.                 }
  12.                 // Calculate error for each output neuron with their corresponding target value
  13.                 for (Neuron n : outputNeurons) {
  14.                     // Calculate error for output neuron UP
  15.                     if(n==outputUp)
  16.                         outputUp.calculateError(tuple.normalizeMoveUp(tuple.DirectionChosen));
  17.                     // Calculate error for output neuron RIGHT
  18.                     else if(n==outputRight)
  19.                         outputRight.calculateError(tuple.normalizeMoveRight(tuple.DirectionChosen));
  20.                     // Calculate error for output neuron DOWN
  21.                     else if(n==outputDown)
  22.                         outputDown.calculateError(tuple.normalizeMoveDown(tuple.DirectionChosen));
  23.                     // Calculate error for output neuron LEFT
  24.                     else if(n==outputLeft)
  25.                         outputLeft.calculateError(tuple.normalizeMoveLeft(tuple.DirectionChosen));
  26.                     // Calculate error for output neuron NEUTRAL
  27.                     else if(n==outputNeutral)
  28.                         outputNeutral.calculateError(tuple.normalizeMoveNeutral(tuple.DirectionChosen));
  29.                 }
  30.                 // Calculate the error for the hidden layer
  31.                 for (Neuron n : HiddenNeurons) {
  32.                         n.calculateError(1);
  33.                 }
  34.                 // Update the weights of the edges between neurons
  35.                 for (Edge e : edges) {
  36.                     e.calculateWeights();
  37.                 }
  38.                 // Update the bias of the neurons
  39.                 for (Neuron n : network) {
  40.                     n.calculateBias();
  41.                 }
  42.             }
  43.             // continue for x amount of epochs
  44.         } while (currentEpoch<numberOfEpochs);
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement