GRASS Programmer's Manual  6.5.svn(2014)-r66266
c_sep.c
Go to the documentation of this file.
1 #include <math.h>
2 #include <grass/cluster.h>
3
4 #define FAR ((double) -1.0)
5
6 double I_cluster_separation(struct Cluster *C, int class1, int class2)
7 {
8  int band;
9  double q;
10  double d;
11  double var;
12  double a1, a2;
13  double n1, n2;
14  double m1, m2;
15  double s1, s2;
16
17  if (C->count[class1] < 2)
18  return FAR;
19  if (C->count[class2] < 2)
20  return FAR;
21  n1 = (double)C->count[class1];
22  n2 = (double)C->count[class2];
23
24  d = 0.0;
25  a1 = a2 = 0.0;
26  for (band = 0; band < C->nbands; band++) {
27  s1 = C->sum[band][class1];
28  s2 = C->sum[band][class2];
29  m1 = s1 / n1;
30  m2 = s2 / n2;
31  q = m1 - m2;
32  q = q * q;
33  d += q;
34
35
36  var = C->sum2[band][class1] - (s1 * m1);
37  var /= n1 - 1;
38  if (var)
39  a1 += q / var;
40
41  var = C->sum2[band][class2] - (s2 * m2);
42  var /= n2 - 1;
43  if (var)
44  a2 += q / var;
45  }
46  if (d == 0.0)
47  return d;
48
49  if (a1 < 0 || a2 < 0)
50  return FAR;
51  if (a1)
52  a1 = sqrt(6 * d / a1);
53  if (a2)
54  a2 = sqrt(6 * d / a2);
55  q = a1 + a2;
56  if (q == 0.0)
57  return FAR;
58
59  return (sqrt(d) / q);
60 }
tuple q
Definition: forms.py:2019
#define C
Definition: intr_char.c:17
double I_cluster_separation(struct Cluster *C, int class1, int class2)
Definition: c_sep.c:6
#define FAR
Definition: c_sep.c:4