C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C++ Expert!

Join 300,331 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,809 people online right now. Registration is fast and FREE... Join Now!




Can somebody please explain Back Propagation

 

Can somebody please explain Back Propagation

enigma-paradox

18 Mar, 2009 - 07:35 AM
Post #1

New D.I.C Head
*

Joined: 16 Jun, 2008
Posts: 16

I don't understand back propagation, I just started trying to teach my self about neural netwoks. I believe I unserstand the concept of what a neuron is and how they work. The problem is that with out a way to train the network, the following code that I've written doesn't do much good. I also looked through the tutorials section, but all of the tutorials seem like they are geared towards learning a language(python, java, ruby,etc.) as opposed to learning a topic(cryptology, AI, data compression, etc.) If anybody could give me a thorough explanation of back propagation or any other way to train an ANN I would really appreciate it.

CODE

#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int get_input(void);
double sigmoid(double x);


int main()
{
    int nodes_in_input = 0;//This declares the number of nodes in the input layer
    int nodes_in_hidden = 0;//This declares the number of nodes in the hidden layer
    int nodes_in_output = 0;//This declares the number of nodes in the output layer
    int number_of_inputs = 0;//This is equal to the number of data points in the input data file
    int i = 0;
    int j = 0;
    int k = 0;
    double activation = 0;
    
    
    
    printf("How many nodes in the input layer:\n");
    nodes_in_input = get_input();
    printf("How many nodes in the hidden layer:\n");
    nodes_in_hidden = get_input();
    printf("How many nodes in the output layer:\n");
    nodes_in_output = get_input();
    
    double input_layer[nodes_in_input];
    double hidden_layer[nodes_in_hidden];
    double output_layer[nodes_in_output];
    double input_data[];
    double weights[nodes_in_input];
    
    for(i = 0; i<nodes_in_input; i++)
    {
        weights[i] = rand()/(RAND_MAX + 1.0);
    }
    
    for(k=0; k<nodes_in_input; k++)
    {
        double output = 0.0;
        double activation = 0.0;
        
        
        for(j=0; j<number_of_inputs; j++)
        {
            activation = activation + weights[j]*input_data[j];
            output = sigmoid(activation);
        }
        input_layer[i] = output;
    }
    
    for(i=0; i<nodes_in_hidden; i++)
    {
        double output = 0.0;
        double activation = 0.0;
        
        
        for(j=0; j<nodes_in_input; j++)
        {
            activation = activation + weights[j]*input_layer[j];
            sigmoid(activation);
            output = sigmoid(activation);
        }
        hidden_layer[i] = output;
    }
    
    for(i=0; i<nodes_in_output; i++)
    {
        double output = 0.0;
        double activation = 0.0;
        
        
        for(j=0; j<nodes_in_input; j++)
        {
            activation = activation + weights[j]*hidden_layer[j];
            sigmoid(activation);
            output = sigmoid(activation);
        }
        output_layer[i] = output;
    }
    return 0;
}

int get_input(void)
{
    while(1)
    {
        int number = 0;        
        if ( scanf("%d", &number) == 1 && number > 0)
        {
            return  number;          
        }              
            printf("Invalid input!\n");
            printf("Please try again\n");
            while (getchar() != '\n'); //Clears the input buffer
              
    }
}

double sigmoid(double x)
{
    double p = 1.0;
    double output = 0.0;
    output = 1/(1+ exp(-x/p));
    return output;
}


User is offlineProfile CardPM
+Quote Post


enigma-paradox

RE: Can Somebody Please Explain Back Propagation

18 Mar, 2009 - 09:13 PM
Post #2

New D.I.C Head
*

Joined: 16 Jun, 2008
Posts: 16

Does nobody understand how back propagation works?!?

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 11/7/09 04:22PM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month