# Teaching perceptrons colors? [closed]

I am learning about artificial neural networks and I've decided to go with perceptrons. I already made a sample program that can learn based on the learning data, but when I tried to make it recognize the color green it stopped working. The learning data is based off of RGB values.

So at first the perceptron was learning fine. Here are the 17 initial training examples: $\{\langle(0, 250, 154), 1\rangle, \langle(0, 238, 118), 1\rangle, \langle(0, 205, 102), 1\rangle, \langle(0, 139, 69), 1\rangle, \langle(60, 179, 113), 1\rangle, \langle(84, 255, 159), 1\rangle, \langle(78, 238, 148), 1\rangle, \langle(67, 205, 128), 1\rangle, \langle(46, 139, 87), 1\rangle, \langle(0, 201, 87), 1\rangle, \langle(0, 205, 205), 0\rangle, \langle(47, 79, 79), 0\rangle, \langle(224, 255, 255), 0\rangle, \langle(0, 191, 255), 0\rangle, \langle(255, 165, 0), 0\rangle, \langle(105, 139, 34), 1\rangle, \langle(139, 139, 122), 0\rangle\},$

where $1$'s stand for green and $0$'s stand for not green. For the above training examples it worked fine and the solution that was computed for the weights was $(-18, 28.3, -34.3)$.

However, when I added $\langle (205,205,0), 0\rangle$ to the training examples, the program ran forever.

My question is, if i am teaching the perceptron correctly and it just can't find an answer or if i should try some other method? (By the way, I am not using back propagation and am also wondering if using back propagation would solve this problem.)

## closed as off-topic by D.W.♦Oct 25 '15 at 5:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

• Welcome to CS.SE! 1. You seem to be asking us to help you debug why your program doesn't work. That kind of question is not on-topic for this site. Programming and coding questions can potentially be posted on Stack Overflow, but are off-topic here. Also, I doubt there's enough information in the question to allow someone to identify what the problem is: you don't tell us anything about how your program works, so how could we tell why it doesn't work? 2. Your question is a wall of text. You might want to think about how you can make it easier to read, before posting it somewhere else. – D.W. Oct 25 '15 at 5:17
• One answer could be that introducing the new point would create a data set that is no longer linearly separable. However, this is not the case here. Without the last data point you can separate the data using the weights $(w_0, w_r, w_g, w_b) = (4, -376, 566, -686)$, while adding the last data point one can use the weights $(w_0, w_r, w_g, w_b) = (2926, -10648, 10636, -10680)$ and the data are classified again all correctly. So, to answer your question: "No, you are not teaching the perceptron correctly (which is one of your assumptions) and this approach is just fine for your problem". – MightyMouse Oct 25 '15 at 7:24
• the last point in each bracket for example {205,205,0,0} is just telling the perceptron if the RGB value is green or not. 0 is no and 1 is yes. So i have no weight for the fourth one should I? – MrQandA Oct 25 '15 at 15:00
• Well, based on your answer I can see at least two mistakes. To begin with, the "solution" $(-18, 28.3, -34.3)$ is not really a solution as it misclassifies the point $\{255, 165, 0, 0\}$. The other mistake that you are making is that you implicitly assume that the hyperplane that defines the boundary of the classification goes through the origin (as you can see, you only compute 3 weights, while in my answer I also return a $w_0$ which is the amount by which the hyperplane is shifted away from the origin). Our third difference is that you use a 0 or a 1 for the classes, while I use a -1 and 1. – MightyMouse Oct 25 '15 at 16:43
• Concluding, the general approach for performing the training when you are given data points like here $\langle (x, y, z), \pm1\rangle$ is to first translate them into $\langle (1, x, y, z), \pm1\rangle$. Having done this, then the classification rule is simply $sgn\left(\sum_{i=0}^n w_i\cdot x_i\right)$, where $x_0 = 1$ due to the transformation. This way you really have a general solution for a perceptron which may not go through the origin. – MightyMouse Oct 25 '15 at 16:47