|
%perceptron to emulate AND function
%Madhumitha
x=[0 0 0 1;0 0 1 1;0 1 0 1;0 1 1 1;1 0 0 1;1 0 1 1;1 1 0 1;1 1 1 1];
t=[-1 -1 -1 -1 -1 -1 -1 1];
w=[0 0 0 0];
wnew=[0 0 0 0];
theta=0.2;
alpha=1;
delw=[0 0 0 0];
yt=[0;0;0;0;0;0;0;0];
wc=0;
count=0;
totalwc=1;
while(1)
totalwc=0;
for i=1:8
y=x*w';
if y>theta
yt=1;
elseif y<-theta
yt(i,1)=-1;
else
yt(i,1)=0;
end
if yt(i,1)==t(1,i)
wnew=w;
else
wnew=w+alpha*t*x;
end
delw=wnew-w;
totalwc=sum(abs(delw));
totalwc=totalwc+wc;
w=wnew;
end
totalwc
count=count+1
if (totalwc==0)
break;
end
end
Hi everyone,
I have written the above code to test the working of a single layer perceptron learning algorithm. The totalwc variable is always struck at 12 and it runs into an infinite loop. I am not able to find out where the error is occurring. I think the while loop is causing all the problem. Pls help me regarding this.
Thanx.
|