Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Neural Networks

  • 17-05-2004 11:17AM
    #1
    Closed Accounts Posts: 25,848 ✭✭✭✭


    Anyone got a link to a good practical tutorial in C/C++ on programming a simple perceptron neural network?

    I can find lots and lots on the theory behind them, and I have a fair idea how they work, but I am a little lost when it comes to the actual implimentation (ie code).

    cheers


Comments

  • Registered Users, Registered Users 2 Posts: 1,722 ✭✭✭Thorbar


    would it not just be a case of having variables with the correct weights and the threshold and then multiplying the inputs with the weights and comparing the activation with the threshold to get the output? Something like:

    float AndPerceptron(int P, int Q){

    float weight1, weight 2, threshold, A, Y;

    weight1 = weight2 = 0.5;

    A = weight1*P + weight2*Q;

    threshold = 1;

    If (A < threshold){
    Y = 0;
    } else {
    Y = 1;
    }


    return Y
    }

    I'm not sure if that will run or not, haven't done anything in C in ages but it roughly what you want to be doing.

    [edit]changed ints to floats[/edit]


  • Registered Users, Registered Users 2 Posts: 95 ✭✭Mr.StRiPe


    Something like this should do the job! just supply whatever activation function you want.
    
    class Perceptron
    {
    
    private:
    
         int num_inputs;
         float Sum;
         float Weight[];
         float Output;
    
    public:
    
         Perceptron(int num_inputs, float weights[]);
         float ActivationFunction(float Sum);
         void Input(float Input[]);
         float Get_Output() { return Output;}
    
    };
    
    Perceptron::Perceptron(int num_inputs, float weights[])
    {
          this->num_inputs = num_inputs;
          Weight = weights;
    }
    
    void Perceptron::Input(float Input[])
    {
         Sum = 0.0;
    
         for(int i = 0; i < num_inputs; i++)
              Sum += (Input[i] * Weight[i]);
    
         Output = ActivationFunction(Sum);
    }
    
    float Perceptron::ActivationFunction(float Sum)
    {
          float Result = 0.0;
    //Just define whatever function you need here and return the Result!
          return Result;
    }
    
    
         
    


Advertisement