From ce66110173c9868dc49c892d315a364abd82b8d9 Mon Sep 17 00:00:00 2001 From: chabisik Date: Sat, 27 Nov 2021 11:16:46 +0100 Subject: [PATCH] Updating/Adding functions --- neurons.c | 13 +++++++++++-- neurons.h | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/neurons.c b/neurons.c index 1b47129..c0a4f7a 100644 --- a/neurons.c +++ b/neurons.c @@ -3,8 +3,17 @@ #include #include "neurons.h" -Neuron *init_neuron() +Neuron *init_neuron(int n_weights) { - + Neuron *neuron = (Neuron*)malloc(sizeof(Neuron)); + neuron->weights = (float*)malloc(n_weights*sizeof(float)); + neuron->output = 0.0; + neuron->delta_error = 0.0; + neuron->same_layer_next_neuron = NULL; } +void destroy_neuron(Neuron *neuron) +{ + free(neuron->weights); + free(neuron); +} \ No newline at end of file diff --git a/neurons.h b/neurons.h index a4ca2f9..83668f4 100644 --- a/neurons.h +++ b/neurons.h @@ -4,11 +4,14 @@ typedef struct neuron Neuron; struct neuron { - float output; //output of the neuron float *weights; //weights associated to the neuron + neuron's bias + float output; //output of the neuron float delta_error; //the delta error for updating current weights Neuron *same_layer_next_neuron; }; +Neuron *init_neuron(int n_weights); +void destroy_neuron(Neuron *neuron); + #endif \ No newline at end of file