Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all
- close all
- format compact
- nntwarn off
- P = -1:0.1:-0.5;
- T = [-.9602 -.5770 -.0729 .3771 .6405 .6600];
- [R, Q] = size(P);
- [S3,Q] = size(T);
- S1 = 7;
- S2 = 7;
- [W1, B1] = nwtan(S1, R);
- [W2, B2] = nwtan(S2, S1);
- [W3, B3] = rands(S3, S2);
- load wagi %zaladowanie wag zapisanych poprzednio w learnbp
- A1 = tansig(W1 * P, B1);
- A2 = tansig(W2 * A1, B2);
- A3 = purelin(W3 * A2, B3);
- E = T - A3;
- disp_freq = 100;
- max_epoch = 10000;
- err_goal = 0.001;
- lr = 0.001;
- error = [];
- mc = 0.99; % 0.1 - 0.9, 0.95, 0.99
- SSE = sumsqr(E);
- %inicjalizowanie poprzednich wag
- dW1 = zeros(size(W1));
- dW2 = zeros(size(W2));
- dW3 = zeros(size(W3));
- dB1 = zeros(size(B1));
- dB2 = zeros(size(B2));
- dB3 = zeros(size(B3));
- for epoch= 1 : max_epoch
- if SSE < err_goal, epoch=epoch-1;
- epoch
- SSE
- break
- end
- D3 = deltalin(A3, E);
- D2 = deltatan(A2, D3, W3);
- D1 = deltatan(A1, D2, W2);
- [dW1, dB1] = learnbpm(P, D1, lr, mc, dW1, dB1);
- [dW2, dB2] = learnbpm(A1, D2, lr, mc, dW2, dB2);
- [dW3, dB3] = learnbpm(A2, D3, lr, mc, dW3, dB3);
- W1 = W1 + dW1;
- B1 = B1 + dB1;
- W2 = W2 + dW2;
- B2 = B2 + dB2;
- W3 = W3 + dW3;
- B3 = B3 + dB3;
- A1 = tansig(W1 * P, B1);
- A2 = tansig(W2 * A1, B2);
- A3 = purelin(W3 * A2, B3);
- E = T - A3;
- SSE=sumsqr(E);
- error=[error SSE];
- if(rem(epoch,disp_freq)==0)
- epoch
- SSE
- plot(P, T, 'r', P, A3, 'g')
- pause(1e-100)
- end
- end
- epoch
- SSE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement