From 048e1cee613ae9edec9a2a3ba096c430dda91d58 Mon Sep 17 00:00:00 2001 From: chabisik Date: Sat, 27 Nov 2021 14:37:40 +0100 Subject: [PATCH] Updating/Adding functions --- Makefile | 7 ++++++- exe | Bin 0 -> 8872 bytes main.c | 8 ++++++++ network.c | 9 +++++++++ network.h | 2 ++ neurons.c | 22 ++++++++++++++++++++-- neurons.h | 3 ++- randomness.c | 15 +++++++++++++++ randomness.h | 7 +++++++ 9 files changed, 69 insertions(+), 4 deletions(-) create mode 100755 exe create mode 100644 randomness.c create mode 100644 randomness.h 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 0000000000000000000000000000000000000000..8a3772dc9e19f3ba2a72943b81fabbca361e5df8 GIT binary patch literal 8872 zcmdT}du&_P89$EuNK0e8P@t5KdZm@xqPk7#BhYrlX`J3v>0@nL9(`P#_&V|MquAGw zbZeI>(BXx$Okz_vF|E=z1bb-gA=XVuBnxV(hEUivHbKw=Dx1SYlm%EArQYv5_k8yC zjWd|Ee|Dnl?|i@SalZ3@!3F1a)SV+ARbY816AoZe7%);+y#6m%8 z(n#GQl_r#Hrqv2}gOXicl?6EILZ!!)BP2Rq$tscIITp%P2)_i#j$(bFMzWxO znJH2gN57(MM=aT$RCXto9n%XcFs58TsvCW+%Ab=qLPm)x=~CMDx*4JT!?PtjiN-Bh zFlD>X!%lUX()iEBr^LHec~iAZmx`aMs;*cSkF~8|yDA=88IL8iT`Rll)~{T@HjqgL z*2sF3f70E$W3McU`kR}UVxEVOFp^JPzwe_JkN$f0$QSS2JpRJZo}ZmR^Elb^hwP_L z+n{-Q1?~O7{1x!Iz$)p}aIb{dO@UuF1%5AZKR#!=3P2_Qi>JVk1NY-|rsV+0#+l{- zsN`Ru-`c60){9I!oQ#OWSu-QdSi%s8)3Kx(6^U>>o@y7m-rg0~qp@T-9y?-yB||-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}>MO9>beusL1f~{NpHSu3`IOlR% SckUGSQMGVhVns!r_WuTcXv*dQ literal 0 HcmV?d00001 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