From 33a722132491ebdd31722f0cada0f81f6b082282 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 3 Feb 2019 18:36:52 -0500 Subject: cluster init refactoring, fix best sort, add km_score() --- km-set.c | 83 ---------------------------------------------------------------- 1 file changed, 83 deletions(-) (limited to 'km-set.c') diff --git a/km-set.c b/km-set.c index 535b46b..69ae6c0 100644 --- a/km-set.c +++ b/km-set.c @@ -265,86 +265,3 @@ km_set_get_row( const size_t num_floats = set->shape.num_floats; return set->floats + i * num_floats; } - -// init a set with num_clusters clusters of shape num_floats by picking -// random cluster centers -bool -km_set_init_rand_clusters( - km_set_t * const cs, - const size_t num_floats, - const size_t num_clusters, - km_rand_t * const rs -) { - // init cluster shape - const km_shape_t shape = { - .num_floats = num_floats, - .num_ints = 1, - }; - - // generate random cluster centers - float floats[num_floats * num_clusters]; - if (!km_rand_fill(rs, num_floats * num_clusters, floats)) { - // return failure - return false; - } - - // FIXME: should probably be heap-allocated - int ints[num_clusters]; - memset(ints, 0, sizeof(ints)); - - // init cluster set - if (!km_set_init(cs, &shape, num_clusters)) { - // return failure - return false; - } - - // add data, return result - return km_set_push(cs, num_clusters, floats, ints); -} - -// init a set with num_clusters clusters of shape num_floats by picking -// random initial points from the set -bool -km_set_init_rand_points( - km_set_t * const cs, - const km_set_t * const set, - const size_t num_clusters, - km_rand_t * const rs -) { - const size_t num_floats = set->shape.num_floats, - stride = sizeof(float) * num_floats; - - // init cluster shape - const km_shape_t shape = { - .num_floats = num_floats, - .num_ints = 1, - }; - - // get random row offsets - size_t rows[num_clusters]; - if (!km_rand_fill_sizes(rs, num_clusters, rows)) { - // return failure - return false; - } - - // generate random cluster centers - float floats[num_floats * num_clusters]; - for (size_t i = 0; i < num_clusters; i++) { - const size_t row_num = rows[i] % set->num_rows; - const float * const row_floats = km_set_get_row(set, row_num); - memcpy(floats + i * num_floats, row_floats, stride); - } - - // FIXME: should probably be heap-allocated - int ints[num_clusters]; - memset(ints, 0, sizeof(ints)); - - // init cluster set - if (!km_set_init(cs, &shape, num_clusters)) { - // return failure - return false; - } - - // add data, return result - return km_set_push(cs, num_clusters, floats, ints); -} -- cgit v1.2.3