diff --git a/Makefile b/Makefile index ea7ec8e..82c0aaf 100644 --- a/Makefile +++ b/Makefile @@ -1 +1,6 @@ -default : executable +send : + git add . + git commit + git push + + diff --git a/exe b/exe new file mode 100755 index 0000000..8a3772d Binary files /dev/null and b/exe differ diff --git a/main.c b/main.c index 00e4e26..6d6fab7 100644 --- a/main.c +++ b/main.c @@ -1,11 +1,19 @@ #include #include #include +#include "randomness.h" #include "neurons.h" #include "network.h" int main(int argc, char *argv[]) { + init_randomness(); + printf("Bonjour et bienvenu ;)\n"); + int i; + for(i=1 ; i<= 30 ; i++) + { + printf("%dth generated fload = %f\n", i, random_float(0.0 , 1.0)); + } return 0; } \ No newline at end of file diff --git a/network.c b/network.c index 7aef52c..aebd110 100644 --- a/network.c +++ b/network.c @@ -1,10 +1,19 @@ #include #include #include +#include "randomness.h" #include "neurons.h" #include "network.h" Neuron *generate_layer(int n_neurons, int n_neurons_prev_layer) { +} + +Network *init_network(int n_neurons_per_layer[]) +{ + /* initialize the network based on array n_neurons_per_layer : + - size of n_neurons_per_layer is the number of layers + - each ith number in array n_neurons_per_layer is the number of neurons in ith layer + */ } \ No newline at end of file diff --git a/network.h b/network.h index 4111437..31c78f6 100644 --- a/network.h +++ b/network.h @@ -9,5 +9,7 @@ struct network int number_layers; //keeps track of layers' number }; +Neuron *generate_layer(int n_neurons, int n_neurons_prev_layer); +Network *init_network(int n_neurons_per_layer[]); #endif \ No newline at end of file diff --git a/neurons.c b/neurons.c index c0a4f7a..e16ba86 100644 --- a/neurons.c +++ b/neurons.c @@ -1,19 +1,37 @@ #include #include #include +#include "randomness.h" #include "neurons.h" Neuron *init_neuron(int n_weights) { Neuron *neuron = (Neuron*)malloc(sizeof(Neuron)); - neuron->weights = (float*)malloc(n_weights*sizeof(float)); + if(n_weights == 0) + { + neuron->weights = NULL; + }else + { + neuron->weights = (float*)malloc(n_weights*sizeof(float)); + int i; + for(i=1 ; i<=n_weights ; i++) + { + neuron->weights[i] = random_float(0.0 , 1.0); + } + } + neuron->bias = random_float(0.0 , 1.0); neuron->output = 0.0; neuron->delta_error = 0.0; neuron->same_layer_next_neuron = NULL; + + return neuron; } void destroy_neuron(Neuron *neuron) { - free(neuron->weights); + if(neuron->weights != NULL) + { + free(neuron->weights); + } free(neuron); } \ No newline at end of file diff --git a/neurons.h b/neurons.h index 83668f4..3fe3200 100644 --- a/neurons.h +++ b/neurons.h @@ -4,7 +4,8 @@ typedef struct neuron Neuron; struct neuron { - float *weights; //weights associated to the neuron + neuron's bias + float *weights; //weights associated to the neuron + float bias; //neuron's bias float output; //output of the neuron float delta_error; //the delta error for updating current weights Neuron *same_layer_next_neuron; diff --git a/randomness.c b/randomness.c new file mode 100644 index 0000000..9366c79 --- /dev/null +++ b/randomness.c @@ -0,0 +1,15 @@ +#include +#include +#include +#include "randomness.h" + +void init_randomness(void) //to be called only one time in main function +{ + srand(time(NULL)); +} + +float random_float(float min, float max) +{ + //generate a random float number in [min ; max] inclusive + return min + ((float)rand()/(float)RAND_MAX) * (max-min); +} \ No newline at end of file diff --git a/randomness.h b/randomness.h new file mode 100644 index 0000000..c3e1839 --- /dev/null +++ b/randomness.h @@ -0,0 +1,7 @@ +#ifndef RANDOMNESS_H +#define RANDOMNESS_H + +void init_randomness(void); +float random_float(float min, float max); + +#endif \ No newline at end of file