pabloducato

learnbp

Jun 13th, 2018
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.15 KB | None | 0 0
  1. clear all
  2. nntwarn off
  3. format compact
  4.  
  5. P = -1:.1:-.5;
  6. T = [-.9602 -.5770 -.0729 .3771 .6405 .6600];
  7.  
  8. [R,Q] = size(P);
  9. [S1,Q] = size(T);
  10. [S2,Q] = size(T);
  11. [S3,Q] = size(T);
  12. [W1,B1] = nwtan(S1,R);
  13. [W2,B2] = nwtan(S2,S1);
  14. [W3,B3] = rands(S3,S2);
  15.  
  16. disp_freq = 100;
  17. max_epoch = 10000;
  18. err_goal = 0.01;
  19. lr = 0.001;
  20. error = [];
  21. A1 = tansig(W1*P,B1);
  22. A2 = tansig(W2*A1,B2);
  23. A3 = purelin(W3*A2,B3);
  24. E = T - A3;
  25. SSE = sumsqr(E);
  26. save wagi
  27.  
  28. for (epoch=1:max_epoch)
  29.     if (SSE < err_goal)
  30.         epoch = epoch - 1;
  31.         break
  32.     end
  33.    
  34.     D3 = deltalin(A3,E);
  35.     D2 = deltatan(A2,D3,W3);
  36.     D1 = deltatan(A1,D2,W2);
  37.     [dW1,dB1] = learnbp(P,D1,lr);
  38.     [dW2,dB2] = learnbp(A1,D2,lr);
  39.     [dW3,dB3] = learnbp(A2,D3,lr);
  40.     W1 = W1 + dW1;
  41.     B1 = B1 + dB1;
  42.     W2 = W2 + dW2;
  43.     B2 = B2 + dB2;
  44.     W3 = W3 + dW3;
  45.     B3 = B3 + dB3;
  46.    
  47.     A1 = tansig(W1*P,B1);
  48.     A2 = tansig(W2*A1,B2);
  49.     A3 = purelin(W3*A2,B3);
  50.    
  51.     E = T-A3;
  52.     SSE = sumsqr(E);
  53.     error = [error SSE];
  54.    
  55.     if (rem(epoch,disp_freq)==0)
  56.         epoch
  57.         SSE
  58.         plot(P,T,'r',P,A3,'g')
  59.         pause(1e-5)
  60.     end
  61. end
  62. epoch
  63. SSE
Add Comment
Please, Sign In to add comment