HolyFuckItsAlive #13

Merged
jastornig merged 105 commits from Delta-Error-Test into main 2023-09-23 22:27:54 +02:00
3 changed files with 65 additions and 11 deletions
Showing only changes of commit af81566c45 - Show all commits

View file

@ -248,21 +248,29 @@ Matrix* transpose(Matrix* matrix) {
//file operations
void matrix_save(Matrix* matrix, char* file_string){
FILE *fptr = fopen(file_string, "w+");
if(!fptr){
printf("Unable to get handle for \"%s\"", file_string);
// open the file in append mode
FILE *file = fopen(file_string, "a");
// check if the file could be found
if(file == NULL) {
printf("ERROR: Unable to get handle for \"%s\"! (matrix_save)", file_string);
exit(1);
}
fprintf(fptr, "%d\n", matrix->rows);
fprintf(fptr, "%d\n", matrix->columns);
// save the size of the matrix
fprintf(file, "%d\n", matrix->rows);
fprintf(file, "%d\n", matrix->columns);
// save all the numbers of the matrix into the file
for(int i = 0; i < matrix->rows; i++){
for(int j = 0; j < matrix->columns; j++){
fprintf(fptr, "%.10f\n", matrix->numbers[i][j]);
fprintf(file, "%.10f\n", matrix->numbers[i][j]);
}
}
printf("saved matrix to %s", file_string);
fclose(fptr);
// close the file
fclose(file);
}
Matrix* matrix_load(char* file_string){

View file

@ -1,12 +1,58 @@
#include "neuronal_network.h"
#include <stdio.h>
#include <time.h>
Neural_Network* new_network(int input_size, int hidden_size, int output_size, double learning_rate);
void print_network(Neural_Network* network);
void free_network(Neural_Network* network);
void save_network(Neural_Network* network, char* file);
Neural_Network* load_network(char* file);
void save_network(Neural_Network* network) {
// create file name and file string
time_t seconds;
time(&seconds);
char* file_name = "../networks/";
sprintf(file_name, "%ld", seconds);
// create file
FILE* save_file = fopen(file_name, "w");
// check if file is successfully opened
if(save_file == NULL) {
printf("ERROR: Something went wrong in file creation! (save_network)");
exit(1);
}
// save network size to first line of the file
fprintf(save_file, "%d\n", network->input_size);
fprintf(save_file, "%d\n", network->hidden_size);
fprintf(save_file, "%d\n", network->output_size);
// close the file
fclose(file_name);
// save first layer
matrix_save(network->bias_1, file_name);
matrix_save(network->weights_1, file_name);
// save second layer
matrix_save(network->bias_2, file_name);
matrix_save(network->weights_2, file_name);
// save third layer
matrix_save(network->bias_3, file_name);
matrix_save(network->weights_3, file_name);
// save output weights
matrix_save(network->weights_output, file_name);
printf("Network Saved!");
}
Neural_Network* load_network(char* file) {
}
double predict_images(Neural_Network* network, Image** images, int amount);
Matrix* predict_image(Neural_Network* network, Image*);

View file

@ -29,7 +29,7 @@ Neural_Network* new_network(int input_size, int hidden_size, int output_size, do
void print_network(Neural_Network* network);
void free_network(Neural_Network* network);
void save_network(Neural_Network* network, char* file);
void save_network(Neural_Network* network);
Neural_Network* load_network(char* file);
double predict_images(Neural_Network* network, Image** images, int amount);