GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
c_means.c
Go to the documentation of this file.
1 #include <math.h>
2 #include <grass/cluster.h>
3 
4 int I_cluster_means(struct Cluster *C)
5 {
6  int band;
7  int class;
8  double m, v; /* m=mean, v=variance then std dev */
9  double s;
10 
11  /*
12  fprintf(stderr,"I_cluster_means(nbands=%d,nclasses=%d)\n",C->nbands, C->nclasses);
13  */
14  for (band = 0; band < C->nbands; band++) {
15  s = C->band_sum[band];
16  m = s / C->npoints;
17  v = C->band_sum2[band] - s * m;
18  v = sqrt(v / (C->npoints - 1));
19  for (class = 0; class < C->nclasses; class++)
20  C->mean[band][class] = m;
21  if (C->nclasses > 1)
22  for (class = 0; class < C->nclasses; class++)
23  C->mean[band][class] +=
24  ((2.0 * class) / (C->nclasses - 1) - 1.0) * v;
25  }
26 
27  return 0;
28 }
int I_cluster_means(struct Cluster *C)
Definition: c_means.c:4
#define C
Definition: intr_char.c:17
if(!YY_CURRENT_BUFFER)
Definition: lex.yy.c:799