Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Neural Networks

Options
  • 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 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 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