nural

8
EXPERIMENT NO:1 UNIPOLAR INPUTS Activity 1:Design a neural network for approximation of xor problem in matlab and compare the performance index(RMSE) based on following parameters. 1]Learning rate vs RMSE 2]Momentum 3]Number of hidden neurons. TOOLS USED: Matlab 7.1 1] Learning Rate versus RMSE clear all;close all; n=2; m=1; h=4; N=4; v=unifrnd(-0.5,0.5,n,h); v1=zeros(n,h); w=[-0.3378;0.2771; 0.2859; -0.3329]; w1=zeros(h,m); b1=[-0.3378 0.2771 0.2859 -0.3329]; b2=-0.1401; x=[1 1 0 0;1 0 1 0]; t=[0 1 1 0]; for alpha=0.1:0.1:1.0 mf=0.6;con=1; epoch=0; while con c=0;e=0; EE=0; for I=1:N for j=1:h zin(j)=b1(j);

Upload: skh1987

Post on 16-Feb-2016

216 views

Category:

Documents


0 download

DESCRIPTION

neural network

TRANSCRIPT

Page 1: nural

EXPERIMENT NO:1

UNIPOLAR INPUTS

Activity 1:Design a neural network for approximation of xor problem in matlab and compare the performance index(RMSE) based on following parameters. 1]Learning rate vs RMSE2]Momentum3]Number of hidden neurons.

TOOLS USED: Matlab 7.1

1] Learning Rate versus RMSEclear all;close all;n=2;m=1;h=4;N=4;v=unifrnd(-0.5,0.5,n,h);v1=zeros(n,h);w=[-0.3378;0.2771; 0.2859; -0.3329];w1=zeros(h,m);b1=[-0.3378 0.2771 0.2859 -0.3329];b2=-0.1401;x=[1 1 0 0;1 0 1 0];t=[0 1 1 0];for alpha=0.1:0.1:1.0mf=0.6;con=1;epoch=0;while con c=0;e=0; EE=0; for I=1:N for j=1:h zin(j)=b1(j); for i=1: zin(j)=zin(j)+x(i,I)*v(i,j); end z(j)=binsig(zin(j)); end yin=b2+z*w; y(I)=binsig(yin); delK=(t(I)-y(I))*binsig1(yin);

Page 2: nural

delw=alpha*delK*z'+mf*(w-w1); delb2=alpha*delK; delinj=delK*w; for j=1:h delj(j,1)=delinj(j,1)*binsig1(zin(j)); end for j=1:h for i=1:n delv(i,j)=alpha*delj(j,1)*x(i,I)+mf*(v(i,j)-v1(i,j)); end end delb1=alpha*delj; w1=w; v1=v; w=w+delw; b2=b2+delb2; v=v+delv; b1=b1+delb1'; e=e+(t(I)-y(I))^2; end rmse=(sqrt(e))/N; epoch=epoch+1; x11(epoch)=epoch; if epoch==5000 con=0; end if(epoch<60000) y11(epoch)=rmse; endenddisp('rmse')disp(rmse)plot(alpha,rmse,'p')disp('c')disp(c)c=c+1;hold on;end

Page 3: nural

2] Momentum Factor versus RMSE

clear all;close all;n=2;m=1;h=4;N=4;v=unifrnd(-0.5,0.5,n,h);v1=zeros(n,h);w=[-0.3378;0.2771; 0.2859; -0.3329];w1=zeros(h,m);b1=[-0.3378 0.2771 0.2859 -0.3329];b2=-0.1401;x=[1 1 0 0;1 0 1 0];t=[0 1 1 0];alpha=0.6;for mf=0.1:0.1:1.0con=1;epoch=0;while con c=0; e=0; EE=0; for I=1:N for j=1:h zin(j)=b1(j); for i=1:n zin(j)=zin(j)+x(i,I)*v(i,j); end z(j)=binsig(zin(j)); end yin=b2+z*w; y(I)=binsig(yin); delK=(t(I)-y(I))*binsig1(yin); delw=alpha*delK*z'+mf*(w-w1); delb2=alpha*delK; delinj=delK*w; for j=1:h delj(j,1)=delinj(j,1)*binsig1(zin(j)); end for j=1:h for i=1:n delv(i,j)=alpha*delj(j,1)*x(i,I)+mf*(v(i,j)-v1(i,j)); end end delb1=alpha*delj;

Page 4: nural

w1=w; v1=v; w=w+delw; b2=b2+delb2; v=v+delv; b1=b1+delb1'; e=e+(t(I)-y(I))^2; end rmse=(sqrt(e))/N; epoch=epoch+1; x11(epoch)=epoch; if epoch==5000 con=0; end if(epoch<60000) y11(epoch)=rmse; endenddisp('rmse')disp(rmse)plot(mf,rmse,'p')disp('c')disp(c)c=c+1;hold on;xlabel('Momentum Factor')ylabel('rmse')end

Page 5: nural

3. RMSE vs Hidden Neurons

close all;clear all;n=2;m=1;h=10;N=4;v=unifrnd(-0.5,0.5,n,h);v1=zeros(n,h);w=unifrnd(-0.5,0.5,h,m);w1=zeros(h,m);b1=unifrnd(-0.5,0.5,1,h);b2=-0.1401;x=[1 1 0 0;1 0 1 0];t=[0 1 1 0];alpha=0.6;mf=0.6;con=1;epoch=0;while con c=0; e=0; EE=0; for I=1:N for j=1:h zin(j)=b1(j); for i=1:n zin(j)=zin(j)+x(i,I)*v(i,j); end z(j)=binsig(zin(j)); end yin=b2+z*w; y(I)=binsig(yin); delK=(t(I)-y(I))*binsig1(yin); delw=alpha*delK*z'+mf*(w-w1); delb2=alpha*delK; delinj=delK*w; for j=1:h delj(j,1)=delinj(j,1)*binsig1(zin(j)); end for j=1:h for i=1:n delv(i,j)=alpha*delj(j,1)*x(i,I)+mf*(v(i,j)-v1(i,j)); end end delb1=alpha*delj;

Page 6: nural

w1=w; v1=v; w=w+delw; b2=b2+delb2; v=v+delv; b1=b1+delb1'; e=e+(t(I)-y(I))^2; end rmse=(sqrt(e))/N; epoch=epoch+1; x11(epoch)=epoch; if epoch==5000 con=0; end if(epoch<60000) y11(epoch)=rmse; endenddisp('rmse')disp(rmse)plot(x11,y11,'-+b')xlabel('Number of hidden layers')ylabel('rmse')end

Page 7: nural