You are on page 1of 6

EXPERIMENT NO:2

ACTIVITY1:Design a neural network for approximation of xor problem in matlab and compare the

performance index(RMSE)based on following parameters.
1]Learning rate
2]Momentum
3]Number of hidden neurons.
SOFTWARE TOOLS USED: MATLAB 7
CODING:1]Learning rate versus rmse

clear all;close all;
n=2;m=1;
h=4;N=4;
v=[0.197 0.3191 -0.1448 0.3394;0.3099,0.1904 -0.0347 -0.4861];
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);
for i=1:n
zin(j)=zin(j)+x(i,I)*v(i,j);
end
z(j)=bipsig(zin(j));
end
yin= b2+ z*w;
y(I)=bipsig(yin);
delK=(t(I)-y(I))*bipsig1(yin);
delw=alpha*delK*z'+mf*(w-w1);
delb2=alpha*delK;
delinj=delK*w;
for j=1:h
delj(j,1)=delinj(j,1)*bipsig1(zin(j));

ROOPAM PAWAR 112013

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;
end
end
disp('rmse')
disp(rmse)
plot(alpha,rmse,'p')
disp('c');
disp(c);
c=c+1;
hold on;

v1=v.1401.197 0.0.9 2]Momentum clear all.0347 0. epoch=epoch+1. while con c=0.3099 0.4861].1 0. end end disp('rmse') disp(rmse) plot(mf.rmse. epoch=0. for mf=0. t=[0 1 1 0].3394.2771. b1=[-0.m). if epoch==5000 con=0. h=4. b2=b2+delb2.3378 0. 6 5 4 3 2 0. alpha=0. v=v+delv.end -3 8 x 10 Bipsig: function y=bipsig(x) y=(1-exp(-x))/(1+exp(-x)). 7 bipsig1: function y= bipsig1(x) y=0.2859. w1=zeros(h.1 0 1 0].8 0. e=e+(t(I)-y(I))^2. b1=b1+delb1'. for I=1:N for j=1:h delb1=alpha*delj.1904 -0.5 0.1:1.3329]. x11(epoch)=epoch. b2=-0.6 0. end rmse=(sqrt(e))/N.'p') ROOPAM PAWAR 112013 1 .N=4.6.3329].h). v1=zeros(n.5*(1+bipsig(x))*(1-bipsig(x)).2859 -0.e=0.4 0.2 0.3 0. w1=w.0.7 0.1448 0. w=[-0.close all. end if(epoch<60000) y11(epoch)=rmse.3191 -0. w=w+delw.2771 0.m=1.3378. x=[1 1 0 0. EE=0. v=[0. -0. n=2.0 con=1.1:0. 0.

end for j=1:h for i=1:n delv(i.I)*v(i.1)=delinj(j. for i=1:n zin(j)=zin(j)+x(i. c=c+1. j)-v1(i. disp(c). end z(j)=bipsig(zin(j)).3 0.5 0.8 0. for j=1:h delj(j.6 0. end end disp('c').7 0. delK=(t(I)-y(I))*bipsig1(yin).zin(j)=b1(j). delw=alpha*delK*z'+mf*(w-w1).1)*x(i.9 1 . y(I)=bipsig(yin).j). end yin= b2+ z*w.2 ROOPAM PAWAR 112013 0. delb2=alpha*delK. delinj=delK*w.1)*bipsig1(zin(j)).1 0. hold on. end -3 9 x 10 8 7 6 5 4 3 2 1 0 0.I)+mf*(v(i.j)).4 0.j)=alpha*delj(j.

w1=w.1. b=linspace(0. v_save=v. end yin=b2+z*w. end end delb1=alpha*delj. ylabel('y axis'). SOFTWARE TOOLS USED: MATLAB 7 CODING: clear all. m=1. p1=20.0. epoch=epoch+1.n.b. end end surfc(a. a=linspace(0.5.2*pi. y(I)=bipsig(yin).08. for j=1:p1 for i=1:p1 aj(:.5. alpha=0.y)').5. end z(j)=bipsig(zin(j)). end SSE=e.j)). w_save=w. zlabel('z axis').1)*x(i. n=2. v1=zeros(n.h). e=e+(t(I)-y(I))^2. ROOPAM PAWAR 112013 . end end disp('rmse') disp(rmse) figure() plot(x11. b1_save=b1.5. for i=1:n zin(j)=zin(j)+x(i. v1=v.j)=alpha*delj(j. rmse=(sqrt(e))/N. t=T. v=v+delv.j)=sin(a(i))*cos(b(j)).EXPERIMENT NO:3 ACTIVITY1: Design a neural network for approximation of F(X. N=p1*p1. b2_save=b2. x11(epoch)=epoch. h=10.h).m).p1*p1).m). end if(epoch<60000) y11(epoch)=SSE.close all. w=w+delw.5.5. count1=1.Y)=sin(x)*cos(y) problem using back propagation algorithm.p1). b2=b2+delb2.5.y11.I)+mf*(v(i. title('plot of function f(x.2*pi. w=unifrnd(-0. for i=1:p1 for j=1:p1 p(i. b1=b1+delb1'.h).5.p). v=unifrnd(-0. x=aj. xlabel('x axis'). if epoch==250 con=0.j).'-+b') for I=1:N for j=1:h zin(j)=b1(j).m).1.0.0.count1)=[a(i).0. w1=zeros(h.j)-v1(i.p1).h. count1=count1+1.1. b1=unifrnd(-0.I)*v(i. b2=unifrnd(-0. end end T=reshape(p.b(j)]. for j=1:h for i=1:n delv(i.

delb2=alpha*delK.1)*bipsig1(zin(j)). zlabel('z axis'). e1=0.5 50 -1 8 40 6 8 4 2 y axis 30 6 4 2 0 0 20 0 x axis ROOPAM PAWAR 112013 50 100 150 200 250 . end end z=reshape(y.b.mf=0. plot of function f(x. delinj=delK*w. end yin=b2+z*w.y) 2 0 y axis 1 0 x axis 90 80 0. ylabel('y axis').y) 1 z axis 0. EE=0. title('plot of function f(x. for i=1:n zin(j)=zin(j)+x(i. figure() surfc(a. end z(j)=bipsig(zin(j)).j). delK=(t(I)-y(I))*bipsig1(yin). epoch=0.sqrt(N)).5 -1 8 6 8 6 4 4 2 plot of function f(x.z).I)*v(i. for j=1:h delj(j. while con e=0. con=1. delw=alpha*delK*z'+mf*(w-w1).y)').7.5 0 -0. for I=1:N for j=1:h zin(j)=b1(j). xlabel('x axis').5 z axis 70 0 60 -0.1)=delinj(j. y(I)=bipsig(yin).sqrt(N).

ROOPAM PAWAR 112013 .