Perceptron Help

This is a discussion on Perceptron Help within the General AI Programming forums, part of the Cprogramming.com and AIHorizon.com's Artificial Intelligence Boards category; This is my first attempt at a neural network, is this even close to a single input output perceptron? Code: ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    12

    Perceptron Help

    This is my first attempt at a neural network, is this even close to a single input output perceptron?
    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>
    
    float floatrandom(float lowerbound, float upperbound)
    {
      return ((float)rand() / RAND_MAX) * (upperbound - lowerbound) + lowerbound;
    }
    
    
    int main()
    {
      int threshold = 0;
      srand ( time(NULL) );
      float weight = floatrandom( 0, 10 );
      int input;
      double activation = 0;
      double change = 0;
              while (1) {
              cin >> input; // acquire input
              activation = weight * input; // to fire or not to fire
    
              if ( activation >= threshold ) {
              cout << "FIRE!!" << endl;
              change = input * ( 5 - activation );
              weight = change + weight;
              }
              else if ( activation <= threshold ) {
              cout << "HOLD YOUR FIRE!!" << endl;
              change = input * ( 5 - activation );
              weight = change + weight;
              }
              }
    
          return 0;
    }

  2. #2
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    I'm not quite sure what you want your code to do. I can see that the thought behind it is correct: your neuron gets an input that is then tested against a certain activision threshold. Afterwards the weight is adjusted so after a while your neuron gets "smarter".

    But: What is yout neuron supposed to learn? After I compiled and ran your code, I couldn't figure it out. And the adjustment of the weight seems kind of odd. If you could explain it a little closer, I'm sure it would be more clear.

    If you take a look at the values that the weight and the activation variables take, you will see some strange behavior. For example, if you input number 3 (or any other number except for 1) about 20-30 times your activition and weight variable go out of bonds and in the end contain "nan" value.

    One more thing: What range of input values is your program supposed to receive? Any integer number?
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    12
    This programs purpose is to determine the value of a number, it is the first perceptron in a network which I hope will eventually involve many layers. Quite frankly, however, I am clueless as to how to accomplish this. This perceptrons purpose is to take in a number and determine whether is is above the given threshold, if so fire. I had intended for this perceptron to evolve into one that could determine whether a number is equal to or greater than one. However, I failed at that whenever I run this program the output seems random. The equations to change the weights were taken directly from tutorials, at least as I have interpreted them. And the learning mechanism is based, once again, on my interpretation of the delta rule. It also doesn’t help that I am a poor programmer and worse mathematician . Perhaps my problem could be my understanding of thresholds and weights, I was told that they were random, is this true?

  4. #4
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    to determine the value of a number
    A value of a number? What do you mean by that?

    whether a number is equal to or greater than one
    Like a>=1 ? I don't think that that is a problem suitable for neural networks to solve. It is simply too simple, and doesn't really involve or require any AI - it's pure mathematics. You should probably try something else, like a very simple pattern recognition.

    Another thing is: usually a neuron takes more than one input.

    It also doesn’t help that I am a poor programmer and worse mathematician
    No, it certainly doesn't. I suggest that you bring your programming skills up to a level that makes you confident of what you are doing when you are coding. Maths is really important, because many aspects of programming involve a thorough knowledge of different mathematical concepts. AI programming is no different. So before you continue, you probably should increase your mathematical understanding.

    Besides that, Neural Networks (and AI in general) are not the subject you usually want to study when you are a beginner. They are rather complex. So why not try something easier?

    But, if you want to continue anyway, you should get yourself a good book about AI. The tutorials you get online are handy, but do not give you the insight you really need. I would suggest for example "AI Techniques for Game Programming" by Mat Buckland. And you must probably study genetic algorithms before you even begin to look into neural nets. These two subjects are very often connected.

    I was told that they were random, is this true?
    Well, yes the wights are random. But after a while they are altered (or calibrated, if you wish) so that they "learn" how to solve the problem more efficiently. That is usually done with good help from genetic algorithms.
    The threshold, though, does not change. It is constant and is usually added as an additional negative weight (which you will learn if you study NN closely). But it might be that the threshold in some problems is random. Though I personally don't see purpose of that approach.
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    12
    Could you suggest any exercises that would help me better by my programming and mathematical skills with a bias towards neural networks? This might also help others in the same boat .

  6. #6
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    Well, you could try to do some genetic programming. It will be useful when you later start developing neural nets. And it's a lot of fun: for example you can create some awesome path finding programs or may be solve the famous Travelling Salesman Problem (TSP). You will probably find many tutorials on this subject, just try to google it!

    Though, again, you should get yourself a book that is not too hard to understand, but which gives you a more or less full explanation of the main concepts of AI. It must guide you from the simplest things to more complex and advanced topics. Some mathematics should be explained. I would suggest for example "AI Techniques for Game Programming" by Mat Buckland (see my last post).

    But when it comes to programming exercises, you should probably wait with AI for a while. Try something else, like writing other programs (may be simple games? - like a balloon shooter or a text adventure) or something else that you think is fun.

    Mathematics is rather hard to learn from or through programming. So you will may be want to take a general course in maths sometime. Or study some books on your own. It is the core maths you should know well. Also probability theory and the like.
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  7. #7
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    Please, understand me correctly. I'm not trying to somehow hinder your eagerness for AI programming. It is really good that you have such an interest for this subject. What I am trying to tell you is that it is better to take a more step-by-step approach. It is better to learn things from ground up than to jump into the middle of something. Some things like core programming knowledge or mathematics may seem either unneccesary or easy to you, but nevertheless they are inportant and it is highly advisable that you learn them first.
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  8. #8
    Registered User
    Join Date
    Apr 2005
    Posts
    12
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. multilayer perceptron application
    By ritchie888 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2008, 02:17 PM
  2. Well having issues with this other program here...
    By Junior89 in forum C++ Programming
    Replies: 2
    Last Post: 05-06-2007, 11:39 PM
  3. Some starting advice...
    By Junior89 in forum General AI Programming
    Replies: 9
    Last Post: 05-03-2007, 11:25 AM
  4. Perceptron Question
    By XSquared in forum Tech Board
    Replies: 9
    Last Post: 06-17-2003, 12:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21