Thread: I don't get it... is peceptrons output boolean?

  1. #1
    Registered User yann's Avatar
    Join Date
    Sep 2009
    Location
    Zagreb, Croatia
    Posts
    186

    I don't get it... is peceptrons output boolean?

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

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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.

  3. #3
    Registered User yann's Avatar
    Join Date
    Sep 2009
    Location
    Zagreb, Croatia
    Posts
    186

    Question

    Quote Originally Posted by tabstop View Post
    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;
    }

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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.

  5. #5
    Registered User yann's Avatar
    Join Date
    Sep 2009
    Location
    Zagreb, Croatia
    Posts
    186

    Unhappy

    Quote Originally Posted by tabstop View Post
    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.
    yes... but i think that i need to solve this first...maybe? ;D i really don't know, i just read the theory and decided to program a perceptron...i did it...i dont get this learning quite, could you explain it to me little more please(maybe some examples, i'm desperate )

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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.

  7. #7
    Registered User yann's Avatar
    Join Date
    Sep 2009
    Location
    Zagreb, Croatia
    Posts
    186
    Quote Originally Posted by tabstop View Post
    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!

  8. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    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.

  9. #9
    Registered User yann's Avatar
    Join Date
    Sep 2009
    Location
    Zagreb, Croatia
    Posts
    186
    Quote Originally Posted by King Mir View Post

    This isn't C, this is AI. You'll get better help elsewhere.
    ok...but this IS C, and on AI board no one answered my questions for days(actually they never did...) but i need some examples please, i really dont get this, how to make neuron calculate? please...
    Arduino rocks!

  10. #10
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    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.

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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;
    }

  12. #12
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    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.

  13. #13
    Registered User yann's Avatar
    Join Date
    Sep 2009
    Location
    Zagreb, Croatia
    Posts
    186

    thanks

    Quote Originally Posted by tabstop View Post
    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;
    }
    thank you...now, what do we teach perceptron here? (still getting that code to work in my head )
    Arduino rocks!

  14. #14
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    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.

  15. #15
    Registered User yann's Avatar
    Join Date
    Sep 2009
    Location
    Zagreb, Croatia
    Posts
    186
    Quote Originally Posted by King Mir View Post
    You're teaching it the target function, conveniently called "target" in the code.
    ok...what does it actually do, the target function?...i will apply memory then, so i don't have to teach my perceptron
    all over again...
    Arduino rocks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Novice needs help
    By ghaasemi in forum C++ Programming
    Replies: 9
    Last Post: 05-30-2009, 08:20 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM