diff options
| author | Your Name <[email protected]> | 2026-08-12 12:21:01 -0700 |
|---|---|---|
| committer | Your Name <[email protected]> | 2026-08-12 12:21:01 -0700 |
| commit | 43c2a6f3f9cc442eb9c0e69157d11348c80d4149 (patch) | |
| tree | 90d8798b16beff4733c0fdc7deb817854586e1a9 /src/application.c | |
| parent | 9286b2dd9bd198d40017ca18a74f5d0449d4c0c4 (diff) | |
Cleaned up main loop
Setting up for a public api
Diffstat (limited to 'src/application.c')
| -rw-r--r-- | src/application.c | 81 |
1 files changed, 49 insertions, 32 deletions
diff --git a/src/application.c b/src/application.c index bda6aa7..879919b 100644 --- a/src/application.c +++ b/src/application.c @@ -26,46 +26,28 @@ int main(void) { - // get number of files in model directory - // This can be replaced later in for loop with number of models to test - // size_t model_count = 0; - // DIR *dirp; - // struct dirent *entry; - // - // dirp = opendir("models"); - // while ((entry = readdir(dirp)) != NULL) { - // if (entry->d_type == DT_REG) { - // model_count++; - // } - // } - // closedir(dirp); - /* ---------- LIST ALL MODELS HERE ----------*/ MemModel models[] = { { + .model_path = "models/fixed_resistor.cir", + .subcircuit_name = "fixed_resistor", + }, + { .model_path = "models/hp_memristor.cir", .subcircuit_name = "memristor", }, { - .model_path = "models/fixed_resistor.cir", - .subcircuit_name = "fixed_resistor", + .model_path = "models/yakopcic_memristor.cir", + .subcircuit_name = "MEM_YAKOPCIC", + }, + { + .model_path = "models/Pershin_DiVentra_memristor.cir", + .subcircuit_name = "memristor", }, }; size_t model_count = sizeof(models) / sizeof(models[0]); - // MemModel hp_memristor = {.model_path = "models/hp_memristor.cir", - // .subcircuit_name = "memristor"}; - // - // MemModel normal_resistor = {.model_path = - // "models/fixed_resistor.cir", .subcircuit_name = "fixed_resistor"}; - // - // MemModel *models = calloc(model_count, sizeof(MemModel)); - // if (models == NULL) { - // fprintf(stderr, "Failed to allocate for model list"); - // return -1; - // } - /* ---------- SPIRES SET UP ----------*/ // discrete LIF parameters for spires double lif_config[] = { @@ -145,17 +127,52 @@ int main(void) } /* ---------- Run Benchmark on each model ----------*/ - for (size_t i = 0; i < model_count; i++) { - printf("Running benchmark on %s\n", models[i].model_path); + size_t predictions_per_model = + state_matrix.num_samples * config.num_outputs; + + double *predictions = malloc(model_count * NUM_OUTPUTS * + NUM_TRAINING_STEPS * sizeof(double)); + if (predictions == NULL) { + fprintf(stderr, "Failed to allocate memroy for predictions"); + free_reservoir_state_matrix(&state_matrix); + spires_reservoir_destroy(reservoir); + return -1; + } + + double mean_squared_error[model_count]; + + for (size_t model = 0; model < model_count; model++) { + double *model_predictions = + predictions + model * predictions_per_model; + printf("\n\nRunning benchmark on %s\n", + models[model].model_path); + if (run_benchmark(&config, reservoir, &state_matrix, - target_outputs, models[i].model_path, - models[i].subcircuit_name) < 0) { + models[model].model_path, + models[model].subcircuit_name, + model_predictions) < 0) { fprintf(stderr, "Failed to run benchmark"); + free(predictions); + free_reservoir_state_matrix(&state_matrix); spires_reservoir_destroy(reservoir); return -1; } + + plot_reservoir_predictions( + target_outputs, model_predictions, state_matrix.num_samples, + config.num_outputs, 0, models[model].model_path); + + mean_squared_error[model] = + calculate_MSE(target_outputs, model_predictions, + state_matrix.num_samples, config.num_outputs); + } + + for (size_t model = 0; model < model_count; model++) { + printf("Model: %s, MSE: %.17g\n", models[model].model_path, + mean_squared_error[model]); } + free(predictions); free_reservoir_state_matrix(&state_matrix); spires_reservoir_destroy(reservoir); |
