aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2019-02-03 21:25:26 -0500
committerPaul Duncan <pabs@pablotron.org>2019-02-03 21:25:26 -0500
commit4a4373f113b607f715badd2ea06cba461fe3bbcf (patch)
treeee8d55af91cc87351ad6bcb3a6afb4b874ed100c
parent0f544be878f72b09d516a64c60e3cbd66f7cfd81 (diff)
downloadkmeans-4a4373f113b607f715badd2ea06cba461fe3bbcf.tar.bz2
kmeans-4a4373f113b607f715badd2ea06cba461fe3bbcf.zip
clean up csv code
-rw-r--r--main.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/main.c b/main.c
index 6acaf60..bc8df45 100644
--- a/main.c
+++ b/main.c
@@ -213,47 +213,44 @@ FIND_CBS = {
};
static void
-print_csv_row(
+ctx_csv_print_row(
const ctx_t * const ctx,
+ FILE * const fh,
const size_t i
) {
const size_t num_clusters = i + 2;
const float mean_distance = ctx->rows[i].distance / NUM_TESTS,
mean_variance = ctx->rows[i].variance / NUM_TESTS,
mean_cluster_size = ctx->rows[i].cluster_size / NUM_TESTS,
- mean_empty_clusters = 1.0 * ctx->rows[i].num_empty_clusters / NUM_TESTS,
- score = km_score(mean_distance, mean_empty_clusters);
+ mean_empty = 1.0 * ctx->rows[i].num_empty_clusters / NUM_TESTS,
+ score = km_score(mean_distance, mean_empty);
// print result
- printf("%zu,%0.3f,%0.3f,%0.3f,%0.3f,%0.3f\n",
+ fprintf(fh, "%zu,%0.3f,%0.3f,%0.3f,%0.3f,%0.3f\n",
num_clusters,
score,
mean_distance,
mean_variance,
mean_cluster_size,
- mean_empty_clusters
+ mean_empty
);
}
static void
-print_csv(
- const ctx_t * const ctx
+ctx_csv_print(
+ const ctx_t * const ctx,
+ FILE * const fh
) {
// print headers
- printf(
- "#,"
- "score,"
- "distance,"
- "variance,"
- "cluster_size,"
- "empty_clusters\n"
- );
+ fprintf(fh, "#,score,distance,variance,cluster_size,empty_clusters\n");
+ // print rows
for (size_t i = 0; i < MAX_CLUSTERS - 2; i++) {
- print_csv_row(ctx, i);
+ ctx_csv_print_row(ctx, fh, i);
}
}
+// static image data buffer
static uint8_t im_data[3 * IM_WIDTH * IM_HEIGHT];
static void
@@ -347,7 +344,7 @@ int main(int argc, char *argv[]) {
}
// print csv
- print_csv(&ctx);
+ ctx_csv_print(&ctx, stdout);
// sort best results from lowest to highest
ctx_best_sort(&ctx);