diff options
| author | Your Name <[email protected]> | 2026-08-24 12:18:29 -0700 |
|---|---|---|
| committer | Your Name <[email protected]> | 2026-08-24 12:18:29 -0700 |
| commit | e2738f53a462393a75be9d54fa73e7a231014b71 (patch) | |
| tree | b038acaacb8beb2dd0c7cee29bfe4b2ee091d554 | |
| parent | 02660d79603efa793313de4e1f83343da9448f31 (diff) | |
added const to a few parameters
| -rwxr-xr-x | bin/benchmark | bin | 273408 -> 267872 bytes | |||
| -rw-r--r-- | build/application.o | bin | 17152 -> 16688 bytes | |||
| -rw-r--r-- | build/benchmark.o | bin | 36064 -> 31232 bytes | |||
| -rw-r--r-- | src/application.c | 8 | ||||
| -rw-r--r-- | src/benchmark.c | 134 | ||||
| -rw-r--r-- | src/benchmark.h | 18 |
6 files changed, 20 insertions, 140 deletions
diff --git a/bin/benchmark b/bin/benchmark Binary files differindex ec95cd4..5eeebe0 100755 --- a/bin/benchmark +++ b/bin/benchmark diff --git a/build/application.o b/build/application.o Binary files differindex d8ec691..6c47157 100644 --- a/build/application.o +++ b/build/application.o diff --git a/build/benchmark.o b/build/benchmark.o Binary files differindex 874e059..bd9f548 100644 --- a/build/benchmark.o +++ b/build/benchmark.o diff --git a/src/application.c b/src/application.c index 9bb18e7..b2105ce 100644 --- a/src/application.c +++ b/src/application.c @@ -20,7 +20,7 @@ #define PI 3.14159265358979323846 #define LAMBDA 1.0e-4 -#define NUM_TRAINING_STEPS 50000 +#define NUM_TRAINING_STEPS 50 #define NUM_CROSSBAR_COLUMNS (NUM_OUTPUTS * 2) // #define NUM_STEPS 2000 @@ -181,12 +181,6 @@ int main(void) } } - if (plot_all_model_deltas(predictions, models, model_count, - state_matrix.num_samples, config.num_outputs, - 0) < 0) { - fprintf(stderr, "Failed to plot model delta comparison\n"); - } - for (size_t model = 0; model < model_count; model++) { printf("Model: %s, MSE: %.17g\n", models[model].model_path, mean_squared_error[model]); diff --git a/src/benchmark.c b/src/benchmark.c index d5e743f..0e667f2 100644 --- a/src/benchmark.c +++ b/src/benchmark.c @@ -131,16 +131,16 @@ double calculate_MSE(const double *expected, const double *predicted, return full_mse; } -int plot_raster(const Reservoir_State_Matrix *matrix, size_t neurons_to_plot, - double spike_threshold) +int plot_raster(const Reservoir_State_Matrix *matrix, + const size_t neurons_to_plot, const double spike_threshold) { if (!matrix || !matrix->states || matrix->num_samples == 0) { return -1; } - if (neurons_to_plot > matrix->num_features) { - neurons_to_plot = matrix->num_features; - } + // if (neurons_to_plot > matrix->num_features) { + // neurons_to_plot = matrix->num_features; + // } // count spikes size_t spike_count = 0; @@ -219,8 +219,10 @@ int plot_raster(const Reservoir_State_Matrix *matrix, size_t neurons_to_plot, } int plot_reservoir_predictions(const double *expected, const double *predicted, - size_t num_samples, size_t num_outputs, - size_t output_to_plot, const char *model_path) + const size_t num_samples, + const size_t num_outputs, + const size_t output_to_plot, + const char *model_path) { PLFLT *x; PLFLT *y_expected; @@ -355,8 +357,8 @@ int plot_reservoir_predictions(const double *expected, const double *predicted, } int plot_model_delta(const double *fixed, const double *model, - size_t num_samples, size_t num_outputs, - size_t output_to_plot, const char *model_path) + const size_t num_samples, const size_t num_outputs, + const size_t output_to_plot, const char *model_path) { PLFLT *x; PLFLT *delta; @@ -459,117 +461,3 @@ int plot_model_delta(const double *fixed, const double *model, return 0; } - -int plot_all_model_deltas(const double *predictions, const MemModel *models, - size_t model_count, size_t num_samples, - size_t num_outputs, size_t output_to_plot) -{ - PLFLT *x; - PLFLT *delta; - PLFLT max_delta = 0.0; - size_t predictions_per_model; - - if (!predictions || !models || model_count < 2 || num_samples == 0 || - output_to_plot >= num_outputs) - return -1; - - predictions_per_model = num_samples * num_outputs; - - x = malloc(num_samples * sizeof(*x)); - delta = malloc(num_samples * sizeof(*delta)); - - if (!x || !delta) { - free(x); - free(delta); - return -1; - } - - for (size_t sample = 0; sample < num_samples; sample++) - x[sample] = (PLFLT)sample; - - /* - * Find the maximum deviation across every model so all curves - * use exactly the same y-axis. - */ - for (size_t model = 1; model < model_count; model++) { - const double *fixed; - const double *model_predictions; - - fixed = predictions; - model_predictions = predictions + model * predictions_per_model; - - for (size_t sample = 0; sample < num_samples; sample++) { - size_t index; - double difference; - - index = sample * num_outputs + output_to_plot; - - difference = - fabs(model_predictions[index] - fixed[index]); - - if (difference > max_delta) - max_delta = (PLFLT)difference; - } - } - - if (max_delta == 0.0) - max_delta = 1.0e-6; - - max_delta *= 1.1; - - plsdev("svg"); - plsfnam("output/model_delta_comparison.svg"); - plsetopt("geometry", "1600x1000"); - - plscolbg(255, 255, 255); - plinit(); - - plscol0(1, 0, 0, 0); - plscol0(2, 200, 50, 50); - plscol0(3, 30, 90, 200); - plscol0(4, 40, 150, 70); - plscol0(5, 160, 80, 180); - plscol0(6, 220, 130, 30); - - plcol0(1); - plwidth(1.0); - - plenv(0.0, (PLFLT)(num_samples - 1), 0.0, max_delta, 0, 0); - - pllab("Timestep", "Absolute prediction difference", - "Deviation from Fixed Resistor"); - - for (size_t model = 1; model < model_count; model++) { - const double *fixed; - const double *model_predictions; - PLINT color; - - fixed = predictions; - model_predictions = predictions + model * predictions_per_model; - - for (size_t sample = 0; sample < num_samples; sample++) { - size_t index; - - index = sample * num_outputs + output_to_plot; - - delta[sample] = (PLFLT)fabs(model_predictions[index] - - fixed[index]); - } - - color = (PLINT)(model + 1); - - if (color > 6) - color = 2 + (PLINT)((model - 1) % 5); - - plcol0(color); - plwidth(2.0); - plline((PLINT)num_samples, x, delta); - } - - plend(); - - free(x); - free(delta); - - return 0; -} diff --git a/src/benchmark.h b/src/benchmark.h index 588fb3a..57156cc 100644 --- a/src/benchmark.h +++ b/src/benchmark.h @@ -19,19 +19,17 @@ int run_benchmark(const spires_reservoir_config *config, double calculate_MSE(const double *expected, const double *predicted, const size_t num_steps, const size_t num_outputs); -int plot_raster(const Reservoir_State_Matrix *matrix, size_t neurons_to_plot, - double spike_threshold); +int plot_raster(const Reservoir_State_Matrix *matrix, + const size_t neurons_to_plot, const double spike_threshold); int plot_reservoir_predictions(const double *expected, const double *predicted, - size_t num_samples, size_t num_outputs, - size_t output_to_plot, const char *model_path); + const size_t num_samples, + const size_t num_outputs, + const size_t output_to_plot, + const char *model_path); int plot_model_delta(const double *fixed, const double *model, - size_t num_samples, size_t num_outputs, - size_t output_to_plot, const char *model_path); - -int plot_all_model_deltas(const double *predictions, const MemModel *models, - size_t model_count, size_t num_samples, - size_t num_outputs, size_t output_to_plot); + const size_t num_samples, const size_t num_outputs, + const size_t output_to_plot, const char *model_path); #endif |
