SHARE
TWEET

learbpm

pabloducato Jun 25th, 2018 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. clear all
  2. close all
  3. format compact
  4. nntwarn off
  5.  
  6. P = -1:0.1:-0.5;
  7. T = [-.9602 -.5770 -.0729 .3771 .6405 .6600];
  8.  
  9. [R, Q] = size(P);
  10. [S3,Q] = size(T);
  11. for S1 = 1: 1: 5;
  12. for S2 = 1: 1: S1;
  13. [W1, B1] = nwtan(S1, R);
  14. [W2, B2] = nwtan(S2, S1);
  15. [W3, B3] = rands(S3, S2);
  16.  
  17. load wagi %zaladowanie wag zapisanych poprzednio w learnbp
  18.  
  19. A1 = tansig(W1 * P, B1);
  20. A2 = tansig(W2 * A1, B2);
  21. A3 = purelin(W3 * A2, B3);
  22. E = T - A3;
  23.  
  24. disp_freq = 100;
  25. max_epoch = 10000;
  26. err_goal = 0.001;
  27. lr = 0.001;
  28. error = [];
  29. mc = 0.99; % 0.1 - 0.9, 0.95, 0.99
  30. SSE = sumsqr(E);
  31. %inicjalizowanie poprzednich wag
  32. dW1 = zeros(size(W1));
  33. dW2 = zeros(size(W2));
  34. dW3 = zeros(size(W3));
  35. dB1 = zeros(size(B1));
  36. dB2 = zeros(size(B2));
  37. dB3 = zeros(size(B3));
  38.  
  39. for epoch= 1 : max_epoch
  40.     if SSE < err_goal, epoch=epoch-1;
  41.         epoch
  42.         SSE
  43.         break
  44.     end
  45.    
  46.     D3 = deltalin(A3, E);
  47.     D2 = deltatan(A2, D3, W3);
  48.     D1 = deltatan(A1, D2, W2);
  49.    
  50.     [dW1, dB1] = learnbpm(P, D1, lr, mc, dW1, dB1);
  51.     [dW2, dB2] = learnbpm(A1, D2, lr, mc, dW2, dB2);
  52.     [dW3, dB3] = learnbpm(A2, D3, lr, mc, dW3, dB3);
  53.    
  54.     W1 = W1 + dW1;
  55.     B1 = B1 + dB1;
  56.     W2 = W2 + dW2;
  57.     B2 = B2 + dB2;
  58.     W3 = W3 + dW3;
  59.     B3 = B3 + dB3;
  60.    
  61.     A1 = tansig(W1 * P, B1);
  62.     A2 = tansig(W2 * A1, B2);
  63.     A3 = purelin(W3 * A2, B3);
  64.     E = T - A3;
  65.     SSE=sumsqr(E);
  66.     error=[error SSE];
  67.     if(rem(epoch,disp_freq)==0)
  68.         epoch
  69.         SSE
  70.         S1
  71.         S2
  72.         lr
  73.         plot(P, T, 'r', P, A3, 'g')
  74.         pause(1e-100)
  75.     end
  76. end
  77. nauczanie = 100*(1-sum((abs(T-A3)>=.5)')/length(T))
  78.  
  79. %Zapisanie parametrów oraz wyników do pliku .txt
  80. wyniki  = [S1 S2 lr epoch 100*(1-sum((abs(T-A3)>=.5)')/length(T)) SSE]
  81.  
  82. fid = fopen('kod.txt','a+');%Odtworzenia pliku
  83.  
  84. for i=1:size(wyniki,1)
  85. fprintf(fid, '%g\t' ,wyniki(i,:));
  86. end
  87.  
  88. fprintf(fid,'\r\n');
  89. fclose(fid);%Tu zamykanie pliku
  90. end
  91. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top