Perceptron Learning Algorithm
I'm trying to program the perceptron example but can't figure out how to assign the sign of the first step.
I drew a line between two points on the xy plane [1,1] in both directions. Then I randomly generated another 10 points, assigning them +1 if they fell above the line and 1 if they fell below the line. I stored those values in ideal function g. Then I gave each point a random first guess of +1/1 as my initial function h. If I start with all the weights as 0, then w*x = 0 for all points. At that rate, PLA will never converge. What is my conceptual error? 
Re: Perceptron Learning Algorithm
Hi
I have a question about how weighting is assigned and the meaning of the PLA . For point a1 which has assignment 1, does w(a1.y) + w(a1.x) = 1 ? ( '.' denotes subscript) And then, for point a2 which has assignment 1, would w(a1.y) + w(a1.x) + w(a1.x) + w(a2.x) = 1 , and so on? To adjust weighting of w for misclassified points, is w.x2 = w.x1 + x.2 * y.2 Thank you for the help! 
Re: Perceptron Learning Algorithm
Quote:
Either point, call it just for simplicity, is a vector that has components . Notice that bold denotes a full data point, while italic denotes a component in that data point. We add a constant 1 component to each data point and call the component to simplify the expression for the perceptron. If the weight vector of the perceptron is (where takes care of the threshold value of that perceptron), then the perceptron implements where returns if its argument is positive and returns if its argument is negative. Example: Say the first data point (two dimensional, so ). Add the constant component and you have . Therefore, the percepton's output on this point is . If this formula returns which is different from the target output , the PLA adjusts the values of the weights trying to make the perceptron output agree with the target output for this point . It uses the specific PLA update rule to achieve that. 
Re: Perceptron Learning Algorithm
Thank you for your reply!
So, y.n for point 2 has nothing to do with point 1, correct? Also, since w.0, w.1 and w.2 are different numbers, do you need multiple points to assess the values of the three w's? Further, is updated w like an array, dependent on which n is being chosen, or is it one uniform number that is applied to all x's? 
Re: Perceptron Learning Algorithm
Quote:
All three components of the weight vector are simultaneously updated by PLA at each iteration, and there is more than one data point to update depending on which points are misclassified at a given time as the algorithm runs. 
Re: Perceptron Learning Algorithm
Hello!
I have some misuderstandings with PLA. Should we update w accordings to only one misclassified point at an iteration or through all the misclassified points at the given iteration? thanks 
Re: Perceptron Learning Algorithm
Quote:

Re: Perceptron Learning Algorithm
Quote:
I think it would be interesting if we can all input our actual numbers and you later show a histogram of what people entered on their homework solutions. ;) I'm shocked by the speed with which PLA converges. I never would have guessed that until I actually coded it up. This is a very interesting and intellectually satisfying exercise! I'm having a hard time deciding how to answer the multiple choice Q 710. The answer depends upon if I use log or linear scaling. Aren't CS algorithm efficiencies usually classified in log scaling? Or am I overthinking this? If an algorithm always converges would the Pr(f(x) ne g(x)) = 0? 
Re: Perceptron Learning Algorithm
Quote:
For my code, I consider 1 iteration as a scan from beginning to end through the entire data set x and correcting any misclassified points. I have already submitted my homework and I believe I cannot resubmit. Thanks, KK. 
Re: Perceptron Learning Algorithm
Quote:
I believe you will need to generate a separate set of test data to process and determine the error rate. Don't update the weights when processing the test data, just process each data point and determine whether it was correct or not. Aggregate those results and you should have your classifier error rate. BTW: This is how I did it which I guess shouldn't necessarily be confused with the correct way of doing it :D 
Re: Perceptron Learning Algorithm
Quote:
For example: if the target function was a 45degree st. line (x2=x1), and there was only one training data say ((x1(1),x2(1)),y(1))=((1,2),+1), and if our first hypothesis function was the horizontal axis itself, the Perceptron Algorithm would stop in its first iteration, and conclude the the horizontalaxis to be close to the Target function (which was actually 45degree line through origin). But if we increase the number of data, the hypothesis function is forced to converge towards the target function, with more iterations. But there will always be some discrepancy i guess, unless you are very lucky. 
Re: Perceptron Learning Algorithm
Quote:

Re: Perceptron Learning Algorithm
Quote:
http://book.caltech.edu/bookforum/sh...31&postcount=4 
Re: Perceptron Learning Algorithm
Quote:
Quote:
Quote:
http://book.caltech.edu/bookforum/sh...31&postcount=4 Hope this helps. 
Re: Perceptron Learning Algorithm
For answering Q7 and Q9: (just as an example) is 25 closer to 5 or closer to 50?
In other words is "closest" in q7/q9 defined using the absolute or relative difference. 25/5 = 5 and 50/25=2 so 25 is closer to 50 than to 5 using relative difference, while using absolute distance, 25 is closer to 5 than to 50. Hope the course staff can confirm which definition to use in answering the question. Many thanks!:bow: 
Re: Perceptron Learning Algorithm
Quote:

Re: Perceptron Learning Algorithm
I understand how to write the code to generate a random line and random points, which are assigned +/ based on their location relative to the line. (I'm assuming that [1,1]x[1,1] means the xy plane (the typical axis that I've been seeing since middle school... correct me if I'm wrong and that notation means something like binary space...)
I understand setting the initial weights to 0. Here is where I'm getting confused: When you say "sign(w0+w1x1+w2x2)", where if the function is positive, the outcome is +1 and visa versa, does the function itself actually generate a negative number? If so, how do you get it to generate a negative number when your learning algorithm takes steps of positive 1? Let's say that my f function is something simple like y=2x. Let's say that my random points lie on each side of the line such that I end up with the following points: (1,1,3), (1,3,7), (1,2,3), and (1,4,7). These map ++ and  , since they are on opposite sides of the line. During the initial step, setting the weights equal to zero yields zero on each of these functions. So, we iterate once by setting the weights equal to 1. Plugging the weights into the first two points yields a positive value. (1+1+3) and (1+3+7) Yet, the bottom two points are still positive. As long as my iterative step is a positive 1, I can't get a negative number in the bottom rows. How does that work? Is that even how the learning is supposed to function? 
Re: Perceptron Learning Algorithm
Quote:
Quote:
Quote:
let k =<w[1], w[2]>. k is like a direction of a gradient, where it goes linearly from 0 to 1 in the length of k. w[0] is a distance along k we draw our line at. This means that the dot product of x[n] and w can be thought of as a measure of "agreement". By the 2d vector analogy from class(which holds in 3d), you can see that in one simple step we can improve this "agreement" from bad to good because we know which way in the 3space must be better (y[n]*x[n]). The miracle of the Perceptron is that just by doing this several times, we *will always* arrive at an acceptable answer. 
Re: Perceptron Learning Algorithm
Another question: My PLA converges, there's no problem with that. But given sample sizes (N = 10 and N = 100), I have to choose the same answer for both iterations questions. Is that OK?

Re: Perceptron Learning Algorithm
Quote:

Re: Perceptron Learning Algorithm
I also had mixed feelings about the choices we were given on problem #9. My result from simulation was right between two answers, and, strictly speaking, if I were to take the absolute closest answer, I got an answer that I felt was wrong, so I chose the other one. I felt that the purpose of the question was to highlight what, if any, difference N makes in the number of steps to converge. So, based on the professor's response about choosing the absolute closest answer, I think I chose poorly.

Re: Perceptron Learning Algorithm
Hello Professor,
I have a question regarding updating w on each PLA iteration. If we always assign x0 = 1, how are we reasonably updating w0? By the vector addition, it will always be updated by the value y * x0 = 1 or +1, and if the true w0 is not an integer the PLA will never be able to converge to that value. Would it be more appropriate to setup such that we divide each component of the true w by w0, so that w0 = 1 always? This way I know it is an integer and my PLA does not have to wander for a noninteger value. Or even, if I know w0 is always 1, I might not even include it in the PLA since I know it is 1 by setup. Thank you, Aaron 
Re: Perceptron Learning Algorithm
Hmm, I have the same problem. The average number of iterations for the case where N = 10 and the case where N = 100 are clearly "different" in the way that one would expect, but with respect to the answer choices they are different relatively but identical absolutely.

Re: Perceptron Learning Algorithm
Can you explain the math in terms of the points I listed?
(1,1,3), (1,3,7), (1,2,3), and (1,4,7). These map ++ and   What exactly happens? During the first iteration, what actual numbers does the computer compare? My eventual f vector should be (1,2,1),right? That represents the line y=2x when rewritten 0=2xy in matrix notation. Shouldn't my eventual result look pretty darn similar to that? I really am trying on this, and I've literally taken all of the required prereq. courses. It's just that I'm not an engineer. The notations don't make as much sense unless I see it in some sort of context. I copied a python PLA script from the net, but python isn't my "native" language, so I'm still trying to figure out exactly what it does. 
Re: Perceptron Learning Algorithm
Quote:
http://en.wikipedia.org/wiki/Perceptron In particular, look at the section called Learning Algorithm Steps. It hopefully will get you started. 
Re: Perceptron Learning Algorithm
Quote:
w_0 = w_0 + y_i However, there is usually a learning rate associated with the perceptron such as alpha, which would make the update on the intercept: w_0 = w_0 + alpha * y_i So you can see here that the algorithm would accommodate noninteger values. In our case, without a learning rate, we just have to hope it converges with an integer value intercept. I actually had one case myself where it wouldn't converge. To avoid biasing my average results, I'm going to just run the algorithm to 100k iterations and throw out anything that doesn't fully converge. 
Re: Perceptron Learning Algorithm
Quote:
Quote:

Re: Perceptron Learning Algorithm
How do you calculate the desired output (dj), as shown on the wikipedia page?

Re: Perceptron Learning Algorithm
Virginia 
Desired output is a set of 1/+1 based on the signum function on N (x,y) points compared to the original line in the xy plane. 
Re: Perceptron Learning Algorithm
Quote:
A word of warning to others (although it sounds like everyone else on the forums is already past this point): You do in fact need to include w_0 (with x_i,0 = 1). I spent quite a while wrestling with my nonconverging PLA until I realized this was the issue (and then some more time wondering why my P(f(x) != g(x)) values were so weird, until I realized that I'd failed to account for the extra w_0 when computing f(x) using a 2D x instead of the appropriate 3D version...) I'd interpreted the value of w_0 from the inclass example as a threshold set by the bank for a creditworthy customer, but now I realize that in fact it's one of the learned parameters, which makes perfect sense in retrospect. :o 
Re: Perceptron Learning Algorithm
While running through the population I first collect all the misfit points and then choose a random point to adjust the weights. The other approach could be to stop at the first misfit and correct the weights. What is practiced?

Re: Perceptron Learning Algorithm
I chose to correct the weights at the first misfit, increase the count of iterations and start the algorithm again from the first point... it works fast so far... but I'm wondering if I should continue with the algorithm without restarting again and stopping only when all points satisfy h(x)=g(x)...

Re: Perceptron Learning Algorithm
Quote:

Re: Perceptron Learning Algorithm
I think it would be interesting to obtain a detailed example with the first few steps used to initialize and train the perceptron. Or a complete example if anybody is willing to share their code.
I was unable to implement correctly the perceptron before the deadline, and after spending an additional 5h in this exercise today, I still don't have a proper implementation. Programming is not the issue, I'm a developer, but my issue is how to apply the theory. I feel it's important to successfully code this algorithm, so I can successfully apply the theories we will learn in the next few lectures. 
Re: Perceptron Learning Algorithm
Quote:

Re: Perceptron Learning Algorithm
Quote:

Re: Perceptron Learning Algorithm
Quote:
Code:
w = np.zeros( 3 ) https://gist.github.com/2395395 and the one for the experiments: https://gist.github.com/2395409 
Re: Perceptron Learning Algorithm
Quote:
Correction: My bad! Missed the 'break' statement ;) 
Re: Perceptron Learning Algorithm
Quote:
Yes, numpy is the best thing ever made for Python! Pseudoinverse of a matrix? np.pniv :) 
All times are GMT 7. The time now is 12:16 AM. 
Powered by vBulletin® Version 3.8.3
Copyright ©2000  2020, Jelsoft Enterprises Ltd.
The contents of this forum are to be used ONLY by readers of the Learning From Data book by Yaser S. AbuMostafa, Malik MagdonIsmail, and HsuanTien Lin, and participants in the Learning From Data MOOC by Yaser S. AbuMostafa. No part of these contents is to be communicated or made accessible to ANY other person or entity.