Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all;
- nntwarn off;
- format compact;
- file = dlmread ('data2.txt');
- P = file(:, 1:34)';
- T = file(:, 35)';
- size(P)
- size(T)
- clear file;
- [R,Q] = size(P);
- [S3,Z] = size(T);
- max_epoch = 500; %liczba epok uczenia 20000 - 40000 nie zwiekszac, tylko zmniejszac np 500
- err_goal = 0.25; %blad docelowy
- disp_freq=100; %czestotliwosc wyswietlania nie uzywac!!!
- error = [];
- S1 = [5:1:50]; %2:1:30
- S2 = S1;
- lr = [0.002 0.001 0.0009 0.0006 0.0003 0.00001];
- for ind_S1=1:length(S1),
- for ind_S2=1:ind_S1,
- for ind_lr=1:length(lr),
- [W1,B1] = nwtan(S1(ind_S1), R); %wagi
- [W2,B2] = nwtan(S2(ind_S2), S1(ind_S1)); %wagi
- [W3,B3] = rands(S3, S2(ind_S2)); % 1 bo S1 ma wymiar 1
- correct = 0;
- for epoch=1:max_epoch,
- A1 = tansig(W1*P,B1);
- A2 = tansig(W2*A1,B2);
- A3 = purelin(W3*A2,B3);
- E = T -A3;
- D3 = deltalin(A3,E);
- D2 = deltatan(A2,D3,W3);
- D1 = deltatan(A1,D2,W2);
- [dW1,dB1] = learnbp(P,D1,lr(ind_lr));
- W1 = W1 + dW1;
- B1 = B1 + dB1;
- [dW2,dB2] = learnbp(A1,D2,lr(ind_lr));
- W2 = W2 + dW2;
- B2 = B2 + dB2;
- [dW3,dB3] = learnbp(A2,D3,lr(ind_lr));
- W3 = W3 + dW3;
- B3 = B3 + dB3;
- SSE = sumsqr(E);
- error = [error SSE];
- if SSE < err_goal,
- epoch = epoch - 1;
- break;
- end
- correct = 100*(1-sum((abs(T-A3)>=.5)')/length(T));
- if(rem(epoch,disp_freq)==0)
- %plot([1:length(T)],T,'r',[1:length(T)],A3,'g')
- %plot([1:length(T)],T,'r',[1:length(T)],A3,'g')
- %[S1(ind_S1) S2(ind_S2) lr(ind_lr) epoch SSE (100*(1-sum((abs(T-A3)>=.5)')/length(T)))]
- %pause(1e-100)
- end
- if(correct == 100)
- break,
- end
- end
- rekord = [S1(ind_S1) S2(ind_S2) lr(ind_lr) SSE correct];
- rekord
- fid = fopen('pabloducatozmiananeuronow.txt','a+');
- for i=1:size(rekord,1),
- fprintf(fid, '%g\t', rekord(i,:));
- end
- fprintf(fid, '\r\n');
- fclose(fid);
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement