Sawy3R11

SI_2_warstwowa

May 22nd, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.92 KB | None | 0 0
  1.  
  2.  
  3. clear all
  4. format compact
  5. nntwarn off
  6.  
  7. P=-1:0.1:-0.5;
  8. T=[-0.9602 -0.5770 0.0729 0.3771 0.6405 0.66];
  9. [R, Q] = size(P);[S1, Q] = size(T);
  10.  
  11. S1 = 15;
  12. [S2, Q] = size(T);
  13.  
  14. [W1,B1]=nwtan(S1,R);
  15. [W2, B2] = rands(S2, S1);
  16.  
  17. disp_freq=100;
  18. max_epoch=50000;
  19. err_goal=1e-20;
  20. lr=0.03;
  21.  
  22. A1=tansig(W1*P,B1);
  23. A2=purelin(W2*A1, B2);
  24. E=T-A2;
  25. SSE=sumsqr(E);
  26. error=[];
  27.  
  28.  
  29. for epoch=1:max_epoch
  30.     if SSE<err_goal, epoch=epoch-1;
  31.         break
  32.     end;
  33.     D2 = deltalin(A2, E);
  34.     D1 = deltatan(A1, D2, W2);
  35.    
  36.     [dW2, dB2]=learnbp(A1, D2, lr);
  37.     [dW1, dB1] =learnbp(P, D1, lr);
  38.     W1=W1+dW1;
  39.     B1=B1+dB1;
  40.    
  41.     W2=W2+dW2;
  42.     B2=B2+dB2;
  43.    
  44.     A1=tansig(W1*P,B1);
  45.     A2=purelin(W2*A1, B2);
  46.    
  47.     E=T-A2;
  48.     SSE=sumsqr(E);
  49.     error=[error SSE];
  50.    
  51.     if(rem(epoch,disp_freq)==0)
  52.         epoch
  53.         SSE
  54.         plot(P,T,'r',P,A2,'g')
  55.         pause(1e-120)
  56.     end
  57. end;
Add Comment
Please, Sign In to add comment