PostGIS  2.3.7dev-r@@SVN_REVISION@@
static void update_r ( kmeans_config config)
static

Definition at line 24 of file kmeans.c.

References kmeans_config::centers, kmeans_config::clusters, distance(), kmeans_config::distance_method, kmeans_config::k, KMEANS_NULL_CLUSTER, kmeans_config::num_objs, and kmeans_config::objs.

Referenced by kmeans().

25 {
26  int i;
27 
28  for (i = 0; i < config->num_objs; i++)
29  {
30  double distance, curr_distance;
31  int cluster, curr_cluster;
32  Pointer obj;
33 
34  assert(config->objs != NULL);
35  assert(config->num_objs > 0);
36  assert(config->centers);
37  assert(config->clusters);
38 
39  obj = config->objs[i];
40 
41  /*
42  * Don't try to cluster NULL objects, just add them
43  * to the "unclusterable cluster"
44  */
45  if (!obj)
46  {
47  config->clusters[i] = KMEANS_NULL_CLUSTER;
48  continue;
49  }
50 
51  /* Initialize with distance to first cluster */
52  curr_distance = (config->distance_method)(obj, config->centers[0]);
53  curr_cluster = 0;
54 
55  /* Check all other cluster centers and find the nearest */
56  for (cluster = 1; cluster < config->k; cluster++)
57  {
58  distance = (config->distance_method)(obj, config->centers[cluster]);
59  if (distance < curr_distance)
60  {
61  curr_distance = distance;
62  curr_cluster = cluster;
63  }
64  }
65 
66  /* Store the nearest cluster this object is in */
67  config->clusters[i] = curr_cluster;
68  }
69 }
int * clusters
Definition: kmeans.h:120
void * Pointer
Definition: kmeans.h:59
#define KMEANS_NULL_CLUSTER
Definition: kmeans.h:37
Pointer * centers
Definition: kmeans.h:107
Datum distance(PG_FUNCTION_ARGS)
size_t num_objs
Definition: kmeans.h:100
unsigned int k
Definition: kmeans.h:110
Pointer * objs
Definition: kmeans.h:97
kmeans_distance_method distance_method
Definition: kmeans.h:85

Here is the call graph for this function:

Here is the caller graph for this function: