102 size_t clusters_sz =
sizeof(int) * n;
105 weights =
lwalloc(
sizeof(
int) * k);
108 clusters_last =
lwalloc(clusters_sz);
115 memcpy(clusters_last, clusters, clusters_sz);
117 update_r(objs, clusters, n, centers, k);
121 converged = memcmp(clusters_last, clusters, clusters_sz) == 0;
127 lwerror(
"%s did not converge after %d iterations", __func__, i);
void * lwalloc(size_t size)
#define LW_ON_INTERRUPT(x)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
#define KMEANS_MAX_ITERATIONS
static void update_r(POINT2D **objs, int *clusters, uint32_t n, POINT2D **centers, uint32_t k)
static void update_means(POINT2D **objs, int *clusters, uint32_t n, POINT2D **centers, uint32_t *weights, uint32_t k)