PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ 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 65 of file lwkmeans.c.

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

Referenced by kmeans().

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