#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;
}
Can somebody please explain Back Propagation
Page 1 of 1
Can somebody please explain Back Propagation
#1
Posted 18 March 2009 - 07:35 AM
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.
Page 1 of 1

Start a new topic
Add Reply




MultiQuote
| 


