Hi, about perceptron learning, why does it learn anyway, because the Cprograming.com says it is and i don't see the logic of perceptron making his output eg. 6, if it just gonna be 0 or 1...
Hi, about perceptron learning, why does it learn anyway, because the Cprograming.com says it is and i don't see the logic of perceptron making his output eg. 6, if it just gonna be 0 or 1...
If what you mean by perceptron is what I think perceptron means, the learning happens by the adjustment of the parameters in the perceptron. The goal of a (single) perceptron is to a yes/no classification (or decision, or boolean, or whatever you want to call it) as accurately as possible.
ok...now, heres my perceptrons learning code and why it cant learn if the correct output that he should be is higher than weight(s)
Code:#include <stdio.h> #define LR 0.1 int wantedout; int out; int input1=0; int input2=1; long weight1=50; long weight2=50; int error; educate_net() { out = ((input1*weight1) + (input2*weight2)); error = out - wantedout; weight1 = weight1 - (error*LR); weight2 = weight2 - (error*LR); } int main(){ printf("wanted output:"); while(1==1){ scanf("%d", &wantedout); while(wantedout != out){ educate_net(); printf("%d\n", out); } } return 0; }
I would be surprised if you could get much learning from using the same input every time, with different desired outputs, since that would be pretty much teaching the thing to do nothing at all but "guess".
The idea is that you have some function you want the perceptron to learn how to do, and so you give it an input, see what it gives you for output, and if it doesn't match then you adjust the weights.
So I think what you need to do is brush up on what a function is. So you appear to have two inputs. You need to decide on a boolean function that you want to train your perceptron to do -- to classify inputs somehow. For instance you might want to train your perceptron to return true if x+y < 3 and false otherwise. So each training loop, you would pick an input (not the same one each time), see whether your perceptron gets it right (you have to know what you want the function to be), and if not, adjust.
oh...i tought its just making his output a certain number...anyway, i now i alredy asked too much, but could you give me a code example ii really don't undersstand, first they tell me its just to make his output a certain number and now this...now im confused(look, i know this sounds stupid but im only 13...and this is my first time facing AI)
Arduino rocks!
In general, neural net output can any function applied to the weighted sum of the inputs. But Perceptrons are used to classify into two states, so yes the output is boolean.
This isn't C, this is AI. You'll get better help elsewhere.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
So here's the algorithm:
1) Initialize the weights and threshold random number to in the range [−0.5, 0.5].
2) Apply inputs to the perceptron, and compute the output, which is the weighted sum applied to the step function.
3) update the weights. These are a function of the iteration number and the output error.
4) test if the result converges, or if you've tried enough times. If not, increase the iteration number, and go to step 2.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
So I coded up the example from Wikipedia and it looks kinda like this, except I'm picking random inputs each time instead of going through the cycle:
Code:#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <time.h> bool target(int x, int y, int z) { //What we're trying to teach our perceptron //Remember that x is the bias and therefore doesn't count return (!(y&&z)); } int main() { //set up some initial values srand(time(NULL)); float weight_x = 0.0f, weight_y = 0.0f, weight_z = 0.0f; float threshold = 0.5f; int successive_right = 0; int total_go_round = 1; const float learning_rate = 0.1f; while (total_go_round < 575) { //way too many, but whatever //pick an input int input_x = 1; //essentially the bias, and therefore always on int input_y = rand() % 2; int input_z = rand() % 2; bool goal = target(input_x, input_y, input_z); bool percept = (weight_x*input_x+weight_y*input_y+weight_z*input_z > threshold); if (percept == goal) { successive_right++; } else { successive_right = 0; int sign = goal ? 1 : -1; //sign of (y-f(x)) weight_x += learning_rate*sign*input_x; weight_y += learning_rate*sign*input_y; weight_z += learning_rate*sign*input_z; } total_go_round++; } printf("Perceptron: (%.2f, %.2f, %.2f, %.2f)\n", weight_x, weight_y, weight_z, threshold); return 0; }
Of course the point of a perceptron is to compute an unknown function. So your target will probably be a look-up table, and your inputs would have to match it.
Also, with numeral networks, if you don't get the result you want, it's often best to restart. To make this effective, you really need the initial weights to be random.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
You're teaching it the target function, conveniently called "target" in the code.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.