Thread Subject: infinite

Subject: infinite

From: astro mmi

Date: 19 Nov, 2009 22:45:23

Message: 1 of 3

%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.

Subject: infinite

From: Matt Fig

Date: 20 Nov, 2009 03:58:03

Message: 2 of 3

I don't know what is going on with your code, but one thing I think you may be doing unintentionally is the following:

        if y>theta
            yt = 1;
        elseif y<-theta
            yt(i,1) = -1;
        else
            yt(i,1) = 0;
        end

since y is a vector, the comparisons in your statement will only pass if ALL of the values of the comparison are true. Is that what you meant to do?

Subject: infinite

From: astro mmi

Date: 21 Nov, 2009 01:28:19

Message: 3 of 3

Thank you for the valuable suggestion. I tried what you were saying as well with y(i,1)>theta and this loop is working fine but the while loop is still running into an infinite loop.Pls suggest an alternative.Thanks

"Matt Fig" <spamanon@yahoo.com> wrote in message <he544b$h9d$1@fred.mathworks.com>...
> I don't know what is going on with your code, but one thing I think you may be doing unintentionally is the following:
>
> if y>theta
> yt = 1;
> elseif y<-theta
> yt(i,1) = -1;
> else
> yt(i,1) = 0;
> end
>
> since y is a vector, the comparisons in your statement will only pass if ALL of the values of the comparison are true. Is that what you meant to do?

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com