diff options
Diffstat (limited to 'src/benchmark.c')
| -rw-r--r-- | src/benchmark.c | 134 |
1 files changed, 11 insertions, 123 deletions
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; -} |
