From 46f8c9bed801355ecd85c14ea7a7f11d38f1e5ba Mon Sep 17 00:00:00 2001 From: jvech Date: Wed, 12 Jul 2023 10:50:32 -0500 Subject: add: weights initialization and deallocation done --- src/main.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 8c82260..4141df0 100644 --- a/src/main.c +++ b/src/main.c @@ -3,13 +3,19 @@ #include #include -#include "neural.h" +#include "nn.h" +const size_t MAX_FILE_SIZE = 1<<29; // 0.5 GiB typedef struct Array { double *data; size_t shape[2]; } Array; +Layer neural[] = { + [0] = {.neurons = 3, .activation = relu}, + [1] = {.neurons = 1, .activation = sigmoid}, +}; + static Array json_read(const char *filepath); Array json_read(const char *filepath) @@ -28,6 +34,9 @@ Array json_read(const char *filepath) fp_size = ftell(fp); if (fp_size == -1) goto json_read_error; + if (fp_size >= MAX_FILE_SIZE) { + fprintf(stderr, "ftell Error(): '%s' size greater than '%zu'\n", filepath, MAX_FILE_SIZE); + } rewind(fp); fp_buffer = calloc(sizeof(char), fp_size); @@ -67,14 +76,9 @@ json_read_error: int main(void) { Array json_data = json_read("data/housing_rent.json"); - printf("area\tlong\tlat\tprice\n"); - for (int i = 0; i < json_data.shape[0]; i++) { - printf("%3.1lf\t%3.2lf\t%3.2lf\t%lf\n", - json_data.data[4*i], - json_data.data[4*i + 1], - json_data.data[4*i + 2], - json_data.data[4*i + 3]); - } + nn_layer_init_weights(neural, 2, 3); + printf("%lf\n", neural[0].weights[0]); + nn_layer_free_weights(neural, 2); free(json_data.data); return 0; } -- cgit v1.2.3-70-g09d2