How to train the vectors in (P) with target vector in (T) .. the error is in code delinj=delk*w; please help
Show older comments
%Back Propagation Network for XOR function with binary input and output clc; clear; P= [0.6000 0.5200 0.3200 1.0000 0.3600 0.6800 0.6000 0.4000 1.0000 0.6000 0.5200 0.5200 0.3200 1.0000 0.4800 0.4400 0.6000 0.3600 0.6800 0.2000 0.4800 0.6000 0.3200 0.0000 0.2000;... 0.7600 0.6400 0.6000 0.8000 0.2400 0.1200 0.1200 0.5600 0.7600 0.4000 0.2800 0.4400 0.4400 0.6000 0.3600 0.3600 0.6400 1.0000 0.5600 0.0000 0.3600 0.6000 0.3600 0.0000 0.0000;... 0.4400 0.6000 0.6000 0.6000 0.4800 0.5200 0.0400 0.3200 0.6000 0.8800 0.2800 0.2000 0.4400 0.3600 0.5600 0.5600 0.4400 1.0000 0.8000 0.0000 0.1600 0.4400 0.5600 0.0400 0.0000;... %class 1 0.7200 0.7200 0.6000 0.7600 0.2400 0.2000 0.1200 0.5600 0.7600 0.5600 0.2400 0.4400 0.4000 0.6400 0.4400 0.3600 0.6800 1.0000 0.4400 0.4000 0.5200 0.6000 0.6000 0.6800 0.8000;... 0.7600 0.7200 0.6000 0.8000 0.2800 0.1200 0.1200 0.5600 0.8400 0.4800 0.2800 0.4800 0.4400 0.6800 0.2800 0.3600 0.6400 1.0000 0.4000 0.2000 0.4800 0.5200 0.3200 0.0000 0.0400];
T= [0.6400 0.8000 0.8000 0.8800 0.1200 0.3200 0.0800 0.5200 0.7600 0.4000 0.2400 0.4400 0.4400 0.7200 0.3200 0.4800 0.7200 1.0000 0.4400 0.1600 0.2800 0.4800 0.4000 0.0000 0.4400]; %No of input , hidden and output neurons n=25; h=50; m=25; a=0.3;
%Initialize the weight and bias v=rand(n,h)-0.5; v1 =zeros(n,h); b1 =rand(1,h)-0.5; b2 =rand(1,m)-0.5; w = rand(h,m)-0.5; w1 = zeros(h,m); alpha = 0.02; mf =0.9; con =1; epoch =0; while con e=0; for I=1:5 %Feed Forward for j=1:h zin(j)= b1(j); for i=1:n zin(j)= zin(j)+ P(I,i)*v(i,j); end z(j)= binsig(zin(j)); end for k= 1:m yin(k)=b2(k); for j =1:h yin(k)= yin(k)+z(j)*w(j,k); end y(k)=binsig(yin(k)); y(I,k)=y(k); end
%Backpropagation Error
for k = 1:m
delk(k)=(T(I,k)-y(I,k))*binsig1(yin(k));
end
for j=1:h
for k=1:m
delw(j,k)= alpha*delk(k)*z(j)+mf*(w(j,k)-w1(j,k));
delinj =delk*w;
end
end
delb2= alpha*delk;
for j=1:h
delj(j)= delinj(j)*binsig1(zin(j));
end
for j =1:h
for i=1:n
delv(i,j) = alpha*delj(j)*P(I,i)+mf*(v(i,j)-v1(i,j));
end
end
delb1 =alpha*delj;
w1=w;
v1=v;
%Weight Updation
w=w+delw;
b2= b2+delb2;
v =v+delv;
b1=b1+delb1;
for k =1:m
e =e+(T(I,k)-y(I,k))^2;
end
end
if e<0.005
con=0;
end
epoch =epoch+1;
if epoch==30
con=0;
end
x1(epoch)=epoch;
y1(epoch)=e;
end
disp('Total epoch performed');
disp(epoch);
disp(e);
disp('Final Weight matrix and bias');
v
b1
w
b2
Answers (1)
dpb
on 24 Dec 2013
doc times
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!