GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
kotz.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <math.h>
3 
4 
5 double *Cdhc_kotz_families(double *x, int n)
6 {
7  static double y[2];
8  int i;
9  double a1, b1, a2, b3, c1, c2, c3, c4, c5, c6, lx;
10  double sum1 = 0.0, sum2 = 0.0, sum4 = 0.0;
11 
12  for (i = 0; i < n; ++i) {
13  sum1 += x[i];
14  sum2 += log(x[i]);
15  }
16 
17  b1 = sum1 / n;
18  a1 = sum2 / n;
19 
20  for (i = 0; i < n; ++i) {
21  lx = log(x[i]);
22  sum4 += (lx - a1) * (lx - a1);
23  }
24 
25  a2 = sum4 / n;
26  b3 = exp(a1 * 2 + a2) * (exp(a2) - 1);
27  c1 = log(a2 / b3);
28  c2 = (exp(a2 * 4) + exp(a2 * 3) * 2 - 4) / 4 - a2 + exp(a2) * 0.75;
29  c3 = a2 * (exp(a2) * 2 - 1) * (exp(a2) * 2 - 1);
30  c4 = (exp(a2) - 1) * 2 * (exp(a2) - 1);
31  c5 = c3 / c4;
32 
33  if (c2 < c5) {
34 #ifdef NOISY
35  fprintf(stdout, " WARNING!!! STATISTICS FOR THE NEXT TEST WILL\n");
36  fprintf(stdout, " NOT BE CALCULATED DUE TO SMALL LOGVARIANCE\n");
37 #endif /* NOISY */
38  y[0] = 999999999.;
39  }
40  else {
41  c6 = sqrt(c2 - c5) * 2.0 * sqrt((double)n);
42  y[0] = c1 / c6;
43  }
44 
45 #ifdef NOISY
46  fprintf(stdout, " TEST24 KT(LN) =%10.4f\n", y[0]);
47 #endif /* NOISY */
48 
49  return y;
50 }
double * Cdhc_kotz_families(double *x, int n)
Definition: kotz.c:5
#define x