PostGIS  2.5.7dev-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.

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  if (weights[i])
89  {
90  centers[i]->x /= weights[i];
91  centers[i]->y /= weights[i];
92  }
93  }
94 }
#define KMEANS_NULL_CLUSTER
Definition: lwkmeans.c:17
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331
unsigned int uint32_t
Definition: uthash.h:78

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

Referenced by kmeans().

Here is the caller graph for this function: