PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ update_r()

static uint8_t update_r ( POINT4D objs,
int *  clusters,
uint32_t  n,
POINT4D centers,
uint32_t  k 
)
static

Definition at line 33 of file lwkmeans.c.

34 {
35  uint8_t converged = LW_TRUE;
36 
37  for (uint32_t i = 0; i < n; i++)
38  {
39  POINT4D obj = objs[i];
40 
41  /* Initialize with distance to first cluster */
42  double curr_distance = distance3d_sqr_pt4d_pt4d(&obj, &centers[0]);
43  int curr_cluster = 0;
44 
45  /* Check all other cluster centers and find the nearest */
46  for (int cluster = 1; cluster < (int)k; cluster++)
47  {
48  double distance = distance3d_sqr_pt4d_pt4d(&obj, &centers[cluster]);
49  if (distance < curr_distance)
50  {
51  curr_distance = distance;
52  curr_cluster = cluster;
53  }
54  }
55 
56  /* Store the nearest cluster this object is in */
57  if (clusters[i] != curr_cluster)
58  {
59  converged = LW_FALSE;
60  clusters[i] = curr_cluster;
61  }
62  }
63  return converged;
64 }
#define LW_FALSE
Definition: liblwgeom.h:108
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
static double distance3d_sqr_pt4d_pt4d(const POINT4D *p1, const POINT4D *p2)
Definition: lwkmeans.c:23
static double distance(double x1, double y1, double x2, double y2)
Definition: lwtree.c:1032

References distance(), distance3d_sqr_pt4d_pt4d(), LW_FALSE, and LW_TRUE.

Referenced by kmeans().

Here is the call graph for this function:
Here is the caller graph for this function: