diff options
author | Paul Duncan <pabs@pablotron.org> | 2019-02-05 19:51:31 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2019-02-05 19:51:31 -0500 |
commit | ea56aca669d38f9f810d48f83556fe02c66d54c1 (patch) | |
tree | ce5d9a0aa67943cb0914e1eab150d96e2d626b31 /src | |
parent | 524d4c9b225f185c90392f206992ea7e53cb4f1c (diff) | |
download | kmeans-ea56aca669d38f9f810d48f83556fe02c66d54c1.tar.bz2 kmeans-ea56aca669d38f9f810d48f83556fe02c66d54c1.zip |
add bounds to training output
Diffstat (limited to 'src')
-rw-r--r-- | src/km-set-print.c | 33 | ||||
-rw-r--r-- | src/km.h | 1 | ||||
-rw-r--r-- | src/main.c | 5 |
3 files changed, 33 insertions, 6 deletions
diff --git a/src/km-set-print.c b/src/km-set-print.c index aa93f96..de394b5 100644 --- a/src/km-set-print.c +++ b/src/km-set-print.c @@ -3,21 +3,46 @@ #include "util.h" #include "km.h" +static bool +km_set_print_bounds( + const float * const bounds, + const size_t num_floats, + FILE * const fh +) { + if (bounds) { + fprintf(fh, "2 0\n"); + for (size_t i = 0; i < num_floats; i++) { + fprintf(fh, "%f %f\n", bounds[i], bounds[num_floats + i]); + } + } + + // return success + return true; +} + bool km_set_print( const km_set_t * const set, + const float * const bounds, FILE * const fh ) { + const size_t num_floats = set->shape.num_floats; + + if (!km_set_print_bounds(bounds, num_floats, fh)) { + // return failure + return false; + } + // print shape - fprintf(fh, "%zu %zu\n", set->shape.num_floats, set->shape.num_ints); + fprintf(fh, "%zu %zu\n", num_floats, set->shape.num_ints); // print rows for (size_t i = 0; i < set->num_rows; i++) { - if (set->shape.num_floats > 0) { + if (num_floats > 0) { const float * const vals = km_set_get_row(set, i); // print floats - for (size_t j = 0; j < set->shape.num_floats; j++) { + for (size_t j = 0; j < num_floats; j++) { fprintf(fh, "%s%f", (j > 0) ? " ": "", vals[j]); } } @@ -27,7 +52,7 @@ km_set_print( const int * const vals = km_set_get_row_ints(set, i); for (size_t j = 0; j < set->shape.num_ints; j++) { - const bool need_space = (set->shape.num_floats > 0) || (j > 0); + const bool need_space = (num_floats > 0) || (j > 0); fprintf(fh, "%s%d", need_space ? " ": "", vals[j]); } } @@ -199,6 +199,7 @@ km_load( _Bool km_set_print( const km_set_t * const, + const float * const, FILE * const fh ); @@ -241,9 +241,10 @@ ctx_save_png( static void ctx_best_print( const ctx_t * const ctx, + const float * const bounds, FILE * const fh ) { - if (!km_set_print(&(ctx->best[ctx_get_max_best(ctx) - 1].set), fh)) { + if (!km_set_print(&(ctx->best[ctx_get_max_best(ctx) - 1].set), bounds, fh)) { die("km_set_print()"); } } @@ -301,7 +302,7 @@ int main(int argc, char *argv[]) { ctx_best_sort(&ctx); // print best - ctx_best_print(&ctx, stdout); + ctx_best_print(&ctx, set.bounds, stdout); if (png_path) { // save png of normalized data set and best clusters |