GRASS GIS 7 Programmer's Manual  7.0.5(2016)-r00000
c_means.c
Go to the documentation of this file.
1 
14 #include <math.h>
15 #include <grass/cluster.h>
16 
24 int I_cluster_means(struct Cluster *C)
25 {
26  int band;
27  int class;
28  double m, v; /* m=mean, v=variance then std dev */
29  double s;
30 
31  G_debug(3, "I_cluster_means(nbands=%d,nclasses=%d)",
32  C->nbands, C->nclasses);
33 
34  for (band = 0; band < C->nbands; band++) {
35  s = C->band_sum[band];
36  m = s / C->npoints;
37  v = C->band_sum2[band] - s * m;
38  v = sqrt(v / (C->npoints - 1));
39  for (class = 0; class < C->nclasses; class++)
40  C->mean[band][class] = m;
41  if (C->nclasses > 1)
42  for (class = 0; class < C->nclasses; class++)
43  C->mean[band][class] +=
44  ((2.0 * class) / (C->nclasses - 1) - 1.0) * v;
45  }
46 
47  return 0;
48 }
int I_cluster_means(struct Cluster *C)
Calculate means value.
Definition: c_means.c:24
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: debug.c:65
if(!DBFLoadRecord(psDBF, hEntity)) return NULL