|
"astro mmi" <pyarsa_madhu@yahoo.co.in> wrote in message <he9kgd$qr3$1@fred.mathworks.com>...
> %perceptron to emulate AND function
> %Madhumitha Iyer
> 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];
> %yarray=[0;0;0;0;0;0;0;0];
> y=[0;0;0;0;0;0;0;0];
> wc=0;
> count=0;
> totalwc=1;
> wcarray=[0;0;0;0;0;0;0;0];
> while(totalwc~=0)
> totalwc=0;
> for i=1:8
> y=x*w';
> if y(i,1)>theta
> yt(i,1)=1;
> elseif y(i,1)<-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;
> wc=sum(abs(delw));
> w=wnew;
> wcarray(i,1)=wc;
> end
> totalwc=totalwc+sum(wcarray);
> totalwc
> count=count+1
> end
>
> Hi everyone,
> The above code is for implementing a perceptron. The program gets struck in an infinite loop when I execute it.I am noticing this is happening because the totalwc variable is not changing at all and is remaining a constant at 12 which is what is making the loop to run indefinitely.Pls help me rectify the code so that i may get the right answer.
==================
At the bottom of the loop, insert a breakpoint or a keyboard statement, e.g.,
count=count+1, keyboard
This will stop execution of the code after each iteration of the loop so that you can inspect all the variables and determine if they're evolving as you expect.
> I also want to know how a goto or do-while can be implemented in matlab
goto is not available in MATLAB. Coding using goto is also unnecessary and emphatically discouraged.
do-while can be implemented using a while structure as follows:
FirstIter=true;
while condition|FirstIter
%blablabla
FirstIter=false;
end
|