## سوال در مورد کد نوشته شده در برنامه متلب

سلام
برنامه زیر کد شمارش تعداد انگشتان باز یک دست با استفاده از شبکه عصبی پرسپترون است
[code=matlab]
%% initializeing the program
clc;
clear all;
close all;
%%
n=16;

l0=rgb2gray(l0);
l0=im2bw(l0,0.5);

%%
l1=rgb2gray(l1);
l1=im2bw(l1,0.5);

%%
l2=rgb2gray(l2);
l2=im2bw(l2,0.5);

%%
l3=rgb2gray(l3);
l3=im2bw(l3,0.5);

%%
l4=rgb2gray(l4);
l4=im2bw(l4,0.5);

%%
l5=rgb2gray(l5);
l5=im2bw(l5,0.5);

%%
l44=rgb2gray(l44);
l44=im2bw(l44,0.5);

%%
l33=rgb2gray(l33);
l33=im2bw(l33,0.5);

%%
r0=rgb2gray(r0);
r0=im2bw(r0,0.5);

%%
r1=rgb2gray(r1);
r1=im2bw(r1,0.5);

%%
r2=rgb2gray(r2);
r2=im2bw(r2,0.5);

%%
r3=rgb2gray(r3);
r3=im2bw(r3,0.5);

%%
r4=rgb2gray(r4);
r4=im2bw(r4,0.5);

%%
r5=rgb2gray(r5);
r5=im2bw(r5,0.5);

%%
r11=rgb2gray(r11);
r11=im2bw(r11,0.5);

%%
r22=rgb2gray(r22);
r22=im2bw(r22,0.5);
%%
r33=rgb2gray(r33);
r33=im2bw(r33,0.5);

%%
r44=rgb2gray(r44);
r44=im2bw(r44,0.5);

subplot(2,6,1);
imshow(l0);
subplot(2,6,2);
imshow(l1);
subplot(2,6,3);
imshow(l2);
subplot(2,6,4);
imshow(l3);
subplot(2,6,5);
imshow(l4);
subplot(2,6,6);
imshow(l5);

subplot(2,6,7);
imshow(r0);
subplot(2,6,8);
imshow(r1);
subplot(2,6,9);
imshow(r2);
subplot(2,6,10);
imshow(r3);
subplot(2,6,11);
imshow(r4);
subplot(2,6,12);
imshow(r5);

figure;

% x[n,10000]
x=[reshape(l0,1,&#91;]);reshape(l1,1,&#91;]);reshape(l2,1,&#91;]);reshape(l3,1,&#91;]);reshape(l4,1,&#91;]);reshape(l5,1,&#91;]);
reshape(r0,1,&#91;]);reshape(r1,1,&#91;]);reshape(r2,1,&#91;]);reshape(r3,1,&#91;]);reshape(r4,1,&#91;]);reshape(r5,1,&#91;]);
reshape(r11,1,&#91;]);reshape(r22,1,&#91;]);reshape(r33,1,&#91;]);reshape(r44,1,&#91;]);
];

% t[n,6]
t=[1 -1 -1 -1 -1 -1;
-1 1 -1 -1 -1 -1;
-1 -1 1 -1 -1 -1;
-1 -1 -1 1 -1 -1;
-1 -1 -1 -1 1 -1;
-1 -1 -1 -1 -1 1;
1 -1 -1 -1 -1 -1;
-1 1 -1 -1 -1 -1;
-1 -1 1 -1 -1 -1;
-1 -1 -1 1 -1 -1;
-1 -1 -1 -1 1 -1;
-1 -1 -1 -1 -1 1;

-1 1 -1 -1 -1 -1;
-1 -1 1 -1 -1 -1;
-1 -1 -1 1 -1 -1;
-1 -1 -1 -1 1 -1;
];

%%

b=zeros(1,6);
b_old=zeros(1,6);

y_in=zeros(1,6);
y=zeros(1,6);
w=zeros(10000,6);
w_old=zeros(10000,6);
s=0;
epoch=0;
%%

while s==0
epoch=epoch+1;
for i=1:n
for k=1:6
y_in(k)=0;
for j=1 : 10000
y_in(k)=y_in(k)+ w(j,k)*x(i,j);
end
y_in(k)=y_in(k)+b(k);

if(y_in(k)&gt;0)
y(k)=1;
elseif (y_in(k)&lt;0)
y(k)=-1;
else
y(k)=0;
end

if(t(i,k)~=y(k))
for z=1:10000
w(z,k)=w(z,k)+x(i,z)*t(i,k);
end
b(k)=b(k)+t(i,k);
end
end

end
if ((w_old==w))
s=1;
else
w_old=w;
b_old=b;
end
end
%%

[fn,path]=uigetfile(&#039;*.jpg&#039;,&#039;select your hand to count its finger&#039;
test=imresize(test,[100 100]);
test=rgb2gray(test);
test=im2bw(test,0.5);
test=reshape(test,1,&#91;]);
% test
y=0;
%r=randi(20)+1

result=zeros(1,6);
for k=1:6
for i=1:10000

y=y+test(i)*w(i,k);

end
y=y+b(k);
if(y&gt;=0)
result(k)=1;
else
result(k)=-1;
end
y=0;
end

disp(&#91;&#039;Your Output array is : &#039;]);
disp(result);

if result== [ 1 -1 -1 -1 -1 -1]
disp(&#039;&lt;moch maste&gt;&#039;
imshow (l0);
elseif result== [ -1 1 -1 -1 -1 -1]
disp(&#039;1 finger&#039;
imshow(l1);
elseif result==[-1 -1 1 -1 -1 -1]
disp(&#039;2 finger&#039;
imshow(l2);

elseif result==[ -1 -1 -1 1 -1 -1]
disp(&#039;3 finger&#039;
imshow(l3)
elseif result== [ -1 -1 -1 -1 1 -1]
disp(&#039;4 finger&#039;
imshow(l4);
elseif result==[ -1 -1 -1 -1 -1 1 ]
disp(&#039;5 finger&#039;
imshow(l9)
else
disp(&#039;Im sorry&#039;
end
[/code]
میشه توضیح بیشتری بدید قسمتهای زیر از کد بالایی دقیقا چکار می کند.

مقادیر اولیه شبکه عصبی شامل y , b , w
[code=matlab]b=zeros(1,6);
b_old=zeros(1,6);

y_in=zeros(1,6);
y=zeros(1,6);
w=zeros(10000,6);
w_old=zeros(10000,6);
s=0;
epoch=0;[/code]

میشه توضیح بدین این حلقه دقیقا چطور کار می کند؟
در این حلقه هر کدام از تصاویر به شبکه عصبی آموزش داده می شود تازمانی که کامل یاد بگیرد
[code=matlab]while s==0
epoch=epoch+1;
for i=1:n
for k=1:6
y_in(k)=0;
for j=1 : 10000
y_in(k)=y_in(k)+ w(j,k)*x(i,j);
end
y_in(k)=y_in(k)+b(k);

if(y_in(k)&gt;0)
y(k)=1;
elseif (y_in(k)&lt;0)
y(k)=-1;
else
y(k)=0;
end

if(t(i,k)~=y(k))
for z=1:10000
w(z,k)=w(z,k)+x(i,z)*t(i,k);
end
b(k)=b(k)+t(i,k);
end
end

end
if ((w_old==w))
s=1;
else
w_old=w;
b_old=b;
end
end[/code]