GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
c_means.c
Go to the documentation of this file.
1 /*!
2  \file cluster/c_means.c
3 
4  \brief Cluster library - Means value
5 
6  (C) 2001-2009 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Original author CERL
12 */
13 
14 #include <math.h>
15 #include <grass/cluster.h>
16 
17 /*!
18  \brief Calculate means value
19 
20  \param C pointer to Cluster structure
21 
22  \return 0
23 */
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 }
if(!(yy_init))
Definition: sqlp.yy.c:775
int nbands
Definition: cluster.h:9
double ** mean
Definition: cluster.h:24
double * band_sum
Definition: cluster.h:14
int nclasses
Definition: cluster.h:27
Definition: cluster.h:7
int I_cluster_means(struct Cluster *C)
Calculate means value.
Definition: c_means.c:24
int npoints
Definition: cluster.h:10
double * band_sum2
Definition: cluster.h:15
int G_debug(int, const char *,...) __attribute__((format(printf