From 95b234d7e0ec2484b16533bbcebe9983156a89e9 Mon Sep 17 00:00:00 2001 From: Ghost_Element Date: Thu, 21 Sep 2023 11:18:37 +0200 Subject: [PATCH 1/3] randomize_network --- neuronal_network.c | 5 ++++- neuronal_network.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/neuronal_network.c b/neuronal_network.c index 4682233..4ff2ac9 100644 --- a/neuronal_network.c +++ b/neuronal_network.c @@ -19,7 +19,7 @@ Neural_Network* new_network(int input_size, int hidden_size, int output_size, do network->bias_1 = matrix_create(hidden_size, 1); network->bias_2 = matrix_create(hidden_size, 1); network->bias_3 = matrix_create(hidden_size, 1); - //network.bias_output = matrix_create(output_size, 1); // do we need it? + network.bias_output = matrix_create(output_size, 1); @@ -34,6 +34,7 @@ void randomize_network(Neural_Network* network, int scope){ matrix_randomize(network->bias_1, scope); matrix_randomize(network->bias_2, scope); matrix_randomize(network->bias_3, scope); + matrix_randomize(network->bias_output, scope); } //void print_network(Neural_Network* network){}; @@ -46,6 +47,7 @@ void free_network(Neural_Network* network){ matrix_free(network->bias_1); matrix_free(network->bias_2); matrix_free(network->bias_3); + matrix_free(network->bias_output); free(network); } @@ -84,6 +86,7 @@ void save_network(Neural_Network* network) { matrix_save(network->weights_3, file_name); // save output weights + matrix_save(network->bias_output, file_name); matrix_save(network->weights_output, file_name); printf("Network Saved!"); diff --git a/neuronal_network.h b/neuronal_network.h index 9c8791d..e0e8754 100644 --- a/neuronal_network.h +++ b/neuronal_network.h @@ -18,7 +18,7 @@ typedef struct { int output_size; Matrix* weights_output; - //Matrix* bias_output; // do we need it? + Matrix* bias_output; //Matrix* output; as local variable given to function double learning_rate; From 524787c212c43d34a6020510e19b565e17d98987 Mon Sep 17 00:00:00 2001 From: Ghost_Element Date: Thu, 21 Sep 2023 11:20:44 +0200 Subject: [PATCH 2/3] randomize_network --- neuronal_network.c | 1 + 1 file changed, 1 insertion(+) diff --git a/neuronal_network.c b/neuronal_network.c index e1c6c7f..7bb0cee 100644 --- a/neuronal_network.c +++ b/neuronal_network.c @@ -122,6 +122,7 @@ Neural_Network* load_network(char* file) { saved_network->weights_2 = load_next_matrix(save_file); saved_network->bias_3 = load_next_matrix(save_file); saved_network->weights_3 = load_next_matrix(save_file); + saved_network->bias_output = load_next_matrix(save_file); saved_network->weights_output = load_next_matrix(save_file); // return saved network From 31b9a1a46ca8b916ffafe624130f1b0dfca3f84e Mon Sep 17 00:00:00 2001 From: Ghost_Element Date: Thu, 21 Sep 2023 11:22:01 +0200 Subject: [PATCH 3/3] randomize_network --- neuronal_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neuronal_network.c b/neuronal_network.c index 7bb0cee..5528750 100644 --- a/neuronal_network.c +++ b/neuronal_network.c @@ -156,7 +156,7 @@ Matrix* predict(Neural_Network* network, Matrix* image_data) { Matrix* hidden3_outputs = apply(relu, add(dot(network->weights_3, hidden2_outputs), network->bias_3)); - Matrix* final_outputs = apply(relu, dot(network->weights_output, hidden3_outputs)); + Matrix* final_outputs = apply(relu, add(dot(network->weights_output, hidden3_outputs), network->bias_output)); Matrix* result = softmax(final_outputs);