PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ update_means()

static void update_means ( POINT2D **  objs,
int *  clusters,
uint32_t  n,
POINT2D **  centers,
uint32_t *  weights,
uint32_t  k 
)
static

Definition at line 62 of file lwkmeans.c.

63{
64 uint32_t i;
65 int cluster;
66
67 memset(weights, 0, sizeof(uint32_t) * k);
68 for (i = 0; i < k; i++)
69 {
70 centers[i]->x = 0.0;
71 centers[i]->y = 0.0;
72 }
73 for (i = 0; i < n; i++)
74 {
75 cluster = clusters[i];
76 if (cluster != KMEANS_NULL_CLUSTER)
77 {
78 centers[cluster]->x += objs[i]->x;
79 centers[cluster]->y += objs[i]->y;
80 weights[cluster] += 1;
81 }
82 }
83 for (i = 0; i < k; i++)
84 {
85 if (weights[i])
86 {
87 centers[i]->x /= weights[i];
88 centers[i]->y /= weights[i];
89 }
90 }
91}
#define KMEANS_NULL_CLUSTER
Definition lwkmeans.c:14
double y
Definition liblwgeom.h:376
double x
Definition liblwgeom.h:376

References KMEANS_NULL_CLUSTER, POINT2D::x, and POINT2D::y.

Referenced by kmeans().

Here is the caller graph for this function: