GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
c_sig.c
Go to the documentation of this file.
1 #include <grass/cluster.h>
2 int I_cluster_signatures(struct Cluster *C)
3 {
4  int c, p, band1, band2;
5  int n;
6  double m1, m2;
7  double p1, p2;
8  double dn;
9 
10  /*
11  fprintf (stderr, "c_sig: 1\n");
12  fprintf (stderr, " nclasses %d\n", C->nclasses);
13  fprintf (stderr, " npoints %d\n", C->npoints );
14  fprintf (stderr, " nbands %d\n", C->nbands );
15  */
16  for (n = 0; n < C->nclasses; n++) {
17  I_new_signature(&C->S);
18  }
19 
20  for (p = 0; p < C->npoints; p++) {
21  c = C->class[p];
22  if (c < 0)
23  continue;
24  /*
25  if (c >= C->nclasses)
26  fprintf (stderr, " class[%d]=%d ** illegal **\n", p, c);
27  */
28  dn = n = C->count[c];
29  if (n < 2)
30  continue;
31  for (band1 = 0; band1 < C->nbands; band1++) {
32  m1 = C->sum[band1][c] / dn;
33  p1 = C->points[band1][p];
34  for (band2 = 0; band2 <= band1; band2++) {
35  m2 = C->sum[band2][c] / dn;
36  p2 = C->points[band2][p];
37  C->S.sig[c].var[band1][band2] += (p1 - m1) * (p2 - m2);
38  }
39  }
40  }
41 
42  for (c = 0; c < C->nclasses; c++) {
43  dn = n = C->S.sig[c].npoints = C->count[c];
44  if (n == 0)
45  dn = 1.0;
46  for (band1 = 0; band1 < C->nbands; band1++)
47  C->S.sig[c].mean[band1] = C->sum[band1][c] / dn;
48  dn = n = C->count[c] - 1;
49  if (n < 1)
50  continue;
51  for (band1 = 0; band1 < C->nbands; band1++)
52  for (band2 = 0; band2 <= band1; band2++)
53  C->S.sig[c].var[band1][band2] /= dn;
54  C->S.sig[c].status = 1;
55  }
56 
57  return 0;
58 }
int I_new_signature(struct Signature *S)
Definition: sig.c:16
#define C
Definition: intr_char.c:17
if(!YY_CURRENT_BUFFER)
Definition: lex.yy.c:799
int n
Definition: dataquad.c:291
int I_cluster_signatures(struct Cluster *C)
Definition: c_sig.c:2