diff options
author | jvech <jmvalenciae@unal.edu.co> | 2023-07-27 09:24:50 -0500 |
---|---|---|
committer | jvech <jmvalenciae@unal.edu.co> | 2023-07-27 09:24:50 -0500 |
commit | d8905e0ef4c05f5cea9c6c00cede7492c770e152 (patch) | |
tree | e53094b7c0481a135ca3192233a90a75c5b0b105 /src/nn.c | |
parent | 7710efc305682f35cbc8d69d9b1e5739dbb89f0d (diff) |
fix: random weights generator bug fixed
Diffstat (limited to 'src/nn.c')
-rw-r--r-- | src/nn.c | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -32,7 +32,7 @@ void nn_layer_forward(Layer layer, double *out, size_t out_shape[2], double *inp } } -void nn_layer_init_weights(Layer layers[], size_t nmemb, size_t n_inputs) +void nn_network_init_weights(Layer layers[], size_t nmemb, size_t n_inputs) { int i; size_t prev_size = n_inputs; @@ -57,11 +57,11 @@ nn_layers_calloc_weights_error: exit(1); } -void nn_layer_free_weights(Layer *layer, size_t nmemb) +void nn_network_free_weights(Layer layers[], size_t nmemb) { for (int i = 0; i < nmemb; i++) { - free(layer[i].weights); - free(layer[i].bias); + free(layers[i].weights); + free(layers[i].bias); } } @@ -87,10 +87,10 @@ void fill_random_weights(double *weights, double *bias, size_t rows, size_t cols size_t weights_size = rows * cols; int64_t *random_weights = calloc(weights_size, sizeof(int64_t)); - int64_t *random_bias = calloc(rows, sizeof(int64_t)); + int64_t *random_bias = calloc(cols, sizeof(int64_t)); - fread(random_weights, sizeof(double), weights_size, fp); - fread(random_bias, sizeof(double), rows, fp); + fread(random_weights, sizeof(int64_t), weights_size, fp); + fread(random_bias, sizeof(int64_t), cols, fp); if (!random_weights || !random_bias) goto nn_fill_random_weights_error; @@ -98,7 +98,7 @@ void fill_random_weights(double *weights, double *bias, size_t rows, size_t cols weights[i] = (double)random_weights[i] / (double)INT64_MAX * 2; } - for (size_t i = 0; i < weights_size; i++) { + for (size_t i = 0; i < cols; i++) { bias[i] = (double)random_bias[i] / (double)INT64_MAX * 2; } |