Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #jednowarstwowa
- clear off
- nntwarn off
- format compact
- P=-1:.1:-.5;
- T=[-.9602, -.5770, -.0729, .3771, .6405, .6600];
- [R,Q]=size(P);
- [S1,Q]=size(T);
- [W1,B1]=nwtan(S1,R);
- disp_freq=10;
- max_epoch=20000;
- err_goal=1e-30;
- lr=0.1;
- error=[];
- A1=tansig(W1*P,B1);
- E=T-A1;
- SSE=sumsqr(E);
- for epoch=1:max_epoch
- if SSE<err_goal
- epoch=epoch-1;
- break
- end
- D1=deltatan(A1,E);
- [dW1,dB1]=learnbp(P,D1,lr);
- W1=W1+dW1; B1=B1+dB1;
- A1=tansig(W1*P,B1);
- E=T-A1;
- SSE=sumsqr(E);
- error=[error SSE];
- if(rem(epoch,disp_freq)==0)
- epoch
- SSE
- plot(P,T,'r',P,A1,'g')
- pause(1e-50)
- end
- end
- #dwuwarstwowa
- clear off
- nntwarn off
- format compact
- P=-1:.1:-.5;
- T=[-.9602, -.5770, -.0729, .3771, .6405, .6600];
- [R,Q]=size(P);
- S1=3;
- [S2,Q]=size(T);
- [W1,B1]=nwtan(S1,R);
- [W2,B2]=rands(S2,S1);
- disp_freq=10;
- max_epoch=20000;
- err_goal=1e-30;
- lr=0.1;
- error=[];
- A1=tansig(W1*P,B1);
- A2=purelin(W2*A1,B2);
- E=T-A2;
- SSE=sumsqr(E);
- for epoch=1:max_epoch
- if SSE<err_goal
- epoch=epoch-1;
- break
- end
- D2=deltalin(A2,E);
- D1=deltatan(A1,D2,W2);
- [dW1,dB1]=learnbp(P,D1,lr);
- [dW2,dB2]=learnbp(A1,D2,lr);
- W1=W1+dW1; B1=B1+dB1;
- W2=W2+dW2; B2=B2+dB2;
- A1=tansig(W1*P,B1);
- A2=purelin(W2*A1,B2);
- E=T-A2;
- SSE=sumsqr(E);
- error=[error SSE];
- if(rem(epoch,disp_freq)==0)
- epoch
- SSE
- plot(P,T,'r',P,A2,'g')
- pause(1e-50)
- end
- end
- #trojwarstwowa
- clear off
- nntwarn off
- format compact
- P=-1:.1:-.5;
- T=[-.9602, -.5770, -.0729, .3771, .6405, .6600];
- [R,Q]=size(P);
- S1=3;
- S2=2;
- [S2,Q]=size(T);
- [S3,Q]=size(T);
- [W1,B1]=nwtan(S1,R);
- [W2,B2]=nwtan(S2,S1);
- [W3,B3]=rands(S3,S2);
- disp_freq=10;
- max_epoch=20000;
- err_goal=1e-30;
- lr=0.1;
- error=[];
- A1=tansig(W1*P,B1);
- A2=tansig(W2*A1,B2);
- A3=purelin(W3*A2,B3);
- E=T-A3;
- SSE=sumsqr(E);
- for epoch=1:max_epoch
- if SSE<err_goal
- epoch=epoch-1;
- break
- end
- D3=deltalin(A2,E);
- D2=deltatan(A2,D3,W3);
- D1=deltatan(A1,D2,W2);
- [dW1,dB1]=learnbp(P,D1,lr);
- [dW2,dB2]=learnbp(A1,D2,lr);
- [dW3,dB3]=learnbp(A2,D3,lr);
- 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-50)
- end
- end
- #porownanie
- s_jednowarstwowa
- save wynik_1w
- s_dwuwarstwowa
- save wynik_2w
- s_trojwarstwowa
- save wynik_3w
- plot([1:length(error)],error,'g')
- hold on
- load wynik_2w
- plot([1:length(error)],error,'b')
- load wynik_1w
- plot([1:length(error)],error,'r')
- hold off
Add Comment
Please, Sign In to add comment