Sie sind auf Seite 1von 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));

MEGHA CHITRANSHI 112006

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;

end
-3

x 10

Bipsig:
function y=bipsig(x)
y=(1-exp(-x))/(1+exp(-x));

bipsig1:
function y= bipsig1(x)
y=0.5*(1+bipsig(x))*(1-bipsig(x));

2
0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

2]Momentum

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];
alpha=0.6;
for mf=0.1:0.1:1.0
con=1;
epoch=0;
while con
c=0;e=0;
EE=0;
for I=1:N
for j=1:h

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(mf,rmse,'p')

MEGHA CHITRANSHI 112006

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));
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

disp('c');
disp(c);
c=c+1;
hold on;
end
-3

x 10

8
7
6
5
4
3
2
1
0
0.1

0.2

MEGHA CHITRANSHI 112006

0.3

0.4

0.5

0.6

0.7

0.8

0.9

EXPERIMENT NO:3
ACTIVITY1: Design a neural network for approximation of F(X,Y)=sin(x)*cos(y) problem using back

propagation algorithm.
SOFTWARE TOOLS USED: MATLAB 7
CODING:

clear all;close all;


p1=20;
a=linspace(0,2*pi,p1);
b=linspace(0,2*pi,p1);
for i=1:p1
for j=1:p1
p(i,j)=sin(a(i))*cos(b(j));
end
end
surfc(a,b,p);
title('plot of function f(x,y)');
xlabel('x axis');
ylabel('y axis');
zlabel('z axis');
count1=1;
for j=1:p1
for i=1:p1
aj(:,count1)=[a(i);b(j)];
count1=count1+1;
end
end
T=reshape(p,1,p1*p1);
n=2;
m=1;
h=10;
N=p1*p1;
x=aj;
t=T;
v=unifrnd(-0.5,0.5,n,h);
v_save=v;
v1=zeros(n,h);
w=unifrnd(-0.5,0.5,h,m);
w_save=w;
w1=zeros(h,m);
b1=unifrnd(-0.5,0.5,1,h);
b1_save=b1;
b2=unifrnd(-0.5,0.5,1,m);
b2_save=b2;
alpha=0.08;

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
SSE=e;
rmse=(sqrt(e))/N;
epoch=epoch+1;
x11(epoch)=epoch;
if epoch==250
con=0;
end
if(epoch<60000)
y11(epoch)=SSE;
end
end
disp('rmse')
disp(rmse)
figure()
plot(x11,y11,'-+b')
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);
MEGHA CHITRANSHI 112006

mf=0.7;
e1=0;
con=1;
epoch=0;
while con
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));
end

end
z=reshape(y,sqrt(N),sqrt(N));
figure()
surfc(a,b,z);
title('plot of function f(x,y)');
xlabel('x axis');
ylabel('y axis');
zlabel('z axis');

plot of function f(x,y)

z axis

0.5

-0.5

-1
8
6

8
6

plot of function f(x,y)

2
0

y axis

x axis

90

80

0.5
z axis

70

0
60

-0.5

50

-1
8

40

8
4

2
y axis

30

4
2
0 0

20

x axis

MEGHA CHITRANSHI 112006

50

100

150

200

250

MEGHA CHITRANSHI 112006

Das könnte Ihnen auch gefallen