Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. void NN::BackProp(){
  2. ForwardProp();
  3. for(int i = 0; i < nOutputs; i++){//same size as nOutputs
  4. deltaOutput[i] = d_activation(netOutput[i]) * currentError[i];//δ = σ(z) · (1 − σ(z)) · (y − t)
  5. d_biasOutput[i] = deltaOutput[i];//biases are changed
  6. //derroe/dbj = δj derivative of error in respect to output is delta output slide 67
  7.  
  8. for(int j = 0; j < nHiddenNeurons;j++){
  9. d_weightsOutput[i*nHiddenNeurons+j] = deltaOutput[i] * outHidden[j]; //changing the direvatives of the weights vias biases * hidden outputs
  10. }
  11.  
  12. }
  13. //check code with arthur
  14.  
  15. //working on the nhidden
  16. for(int x = 0; x < nHiddenNeurons; x++){//x is all hidden neutrons
  17.  
  18. deltaHidden[x] = 0.0;
  19. double sumOutput =0; //suming up (Xiδi· wouti,j)
  20. for(int i = 0; i < nOutputs; i++){
  21. //getting all z = netHidden all in respect to nHiddenN dw
  22. sumOutput += deltaOutput[i] * weightsOutput[x*nOutputs+i];
  23. //deltaHidden[x] += currentInputs[x] * deltaOutput[i] * weightsOutput[x*nOutputs + i] * d_activation(netOutput[x]);//delta outputs kinda a constant sums itup δ · xi
  24. //de/wi
  25.  
  26. //need += because it adds up other wise it'll be useless
  27. //deltaHidden[nHiddenNeurons] = d_activation(netHidden[nHiddenNeurons]);//direvative of the error in respect to the hidden weights
  28.  
  29. }
  30. double z = netHidden[x];//z is hidden net for that formula
  31. deltaHidden[x] = sumOutput * d_activation(z); // (1 − σ(zj))
  32. d_biasHidden[x] = deltaHidden[x]; //tweaking biases of hidden neurons, propagating backwards
  33.  
  34. for(int i = 0; i < nInputs; i++){
  35. d_weightsHidden[x*nInputs+i] = deltaHidden[x] * currentInputs[i];//changing hiddens weighhts for the inputs (last step of propagation)
  36. }
  37.  
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement