diff --git a/matrix.c b/matrix.c index be1a530..570eef0 100644 --- a/matrix.c +++ b/matrix.c @@ -2,8 +2,10 @@ #include #include #include +#include #define MAX_BYTES 100 +static int RANDOMIZED = 0; // operational functions Matrix* matrix_create(int rows, int columns) { @@ -17,7 +19,7 @@ Matrix* matrix_create(int rows, int columns) { // allocate memory for the numbers (2D-Array) matrix->numbers = malloc(sizeof(double*) * rows); for (int i = 0; i < rows; i++) { - matrix->numbers[i] = malloc(sizeof(double) * columns); + matrix->numbers[i] = calloc(sizeof(double), columns); } // return the pointer to the allocated memory @@ -189,7 +191,8 @@ Matrix* apply(double (*function)(double), Matrix* matrix) { // apply the function to all values in the matrix for (int i = 0; i < matrix->rows; i++) { for (int j = 0; j < matrix->columns; j++) { - matrix->numbers[i][j] = (*function)(matrix->numbers[i][j]); + result_matrix->numbers[i][j] = (*function)(matrix->numbers[i][j]); + int k = 0; } } @@ -350,6 +353,10 @@ int matrix_argmax(Matrix* matrix) { void matrix_randomize(Matrix* matrix, int n) { + if(!RANDOMIZED){ + srand(time(NULL)); + RANDOMIZED = 1; + } //make a min and max double min = -1.0f / sqrt(n); double max = 1.0f / sqrt(n); diff --git a/neuronal_network.c b/neuronal_network.c index 4682233..46fc953 100644 --- a/neuronal_network.c +++ b/neuronal_network.c @@ -159,11 +159,10 @@ Matrix* predict(Neural_Network* network, Matrix* image_data) { //void batch_train_network(Neural_Network* network, Image** images, int size); double relu(double input) { - if (input < 0){ + if (input <= 0){ return 0.0; } return input; - //TODO: relu formel } Matrix* softmax(Matrix* matrix) {