bp 이용한 매트랩코딩
데이터 x를 받아서 t랑 비교후 글자를 인식하느냐안하느냐를 프밍하고 있는데
계속 오류가 나네요 ..뭐가 잘못된건지...도와주세요 ㅠㅠ
x=zeros(7,63);
% Input from Font1
x =[0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 1 1 1 0 1 1 1; % A
1 1 1 1 1 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 1 1 1 1 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 1 1 1 1 1 1 1 0; % B
0 0 1 1 1 1 1 0 1 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1 1 1 0; % C
1 1 1 1 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 1 0 1 1 1 1 1 0 0; % D
1 1 1 1 1 1 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 1 1 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 1 1; % E
0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 1 1 0 0; % J
1 1 1 0 0 1 1 0 1 0 0 1 0 0 0 1 0 1 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 1 1 1 0 0 1 1]; % K
t=[1 -1 -1 -1 -1 -1 -1; % A
-1 1 -1 -1 -1 -1 -1; % B
-1 -1 1 -1 -1 -1 -1; % C
-1 -1 -1 1 -1 -1 -1; % D
-1 -1 -1 -1 1 -1 -1; % E
-1 -1 -1 -1 -1 1 -1; % J
-1 -1 -1 -1 -1 -1 1]; % K
iv=rand(63,63)-0.5;ibh=rand(1,7)-0.5;
iw=rand(1,7)-0.5;ibo=rand(1,1)-0.5;
w=iw;v=iv;bh=ibh;bo=ibo;
st=1;ct=0;alpa=0.05;th=0.2;
count=0; mse=0;
while st == 1 && count < 5000
mse=0;st=0;
for m=1:7
% net input to the hidden unit
zin=zeros(7,63);z=zeros(7,63);
for i=1:7
for j=1:63
temp=x(m,j)*v(j,i);
zin(i)=zin(i)+temp;
end
zin(i)=zin(i)+bh(i);
z(i)=2/(1+exp(-zin(i)))-1;
end
% net input to the output unit
yin=0;
for i=1:7
temp=w(i)*z(i);
yin=yin+temp;
end
yin=yin+bo;
yta=2/(1+exp(-yin))-1;
% error portion
e=t(m)-yta;
do=e*(1-yta^2)/2;
dh=zeros(7,63);
for i=1:7
dh(i)=do*w(i)*(1-z(i)^2)/2;
end
% weight changes
for i=1:7
w(i)=w(i)+alpa*do*z(i);
end
bo=bo+alpa*do;
for i=1:7
for j=1:63
v(j,i)=v(j,i)+alpa*dh(i)*x(m,j);
end
bh(i)=bh(i)+alpa*dh(i);
end
% stopping condition
mse=mse+e^2;
if abs(e) > 0.1
st=1;
end
end
count=count+1;
msee(count)=mse/4;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% if rem(count,1000) == 0 & st == 1
% count
% disp('system response');
% for m=1:7
% zin=zeros(7,63);z=zeros(7,63);
% for i=1:7
% for j=1:63
% temp=x(m,j)*v(j,i);
% zin(i)=zin(i)+temp;
% end
% zin(i)=zin(i)+bh(i);
% z(i)=2/(1+exp(-zin(i)))-1;
% end
% yin=0;
% for i=1:7
% temp=w(i)*z(i);
% yin=yin+temp;
% end
% yin=yin+bo;
% yta=2/(1+exp(-yin))-1;
% [x(m,1) x(m,2) yta]
% end
% end
end
댓글 달기