GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
cvmw2e.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include "local_proto.h"
5 
6 
7 double *Cdhc_cramer_von_mises_exp(double *x, int n)
8 {
9  static double y[2];
10  double *xcopy, mean = 0.0, fx, fn2, sum4 = 0.0;
11  int i;
12 
13  if ((xcopy = (double *)malloc(n * sizeof(double))) == NULL) {
14  fprintf(stderr, "Memory error in Cdhc_cramer_von_mises_exp\n");
15  exit(EXIT_FAILURE);
16  }
17 
18  for (i = 0; i < n; ++i) {
19  xcopy[i] = x[i];
20  mean += x[i];
21  }
22  mean /= n;
23 
24  qsort(xcopy, n, sizeof(double), Cdhc_dcmp);
25 
26  for (i = 0; i < n; ++i) {
27 
28  /*-
29  a = (2 * i + 1) * log (fx);
30  b = (2 * i + 1) * (xcopy[n-i-1] * (-1.0 / mean));
31  sum3 += a + b;
32  */
33  fx = 1 - exp(xcopy[i] * (-1.0 / mean));
34  fn2 = (double)(2.0 * i + 1) / (2 * n);
35  sum4 += (fx - fn2) * (fx - fn2);
36  }
37 
38  /*-
39  cvm = 1.0 / (n * 12) + sum4;
40  cvmod = cvm * (0.16 / n + 1.0);
41  */
42  y[0] = (1.0 / (n * 12) + sum4) * (0.16 / n + 1.0);
43 
44 #ifdef NOISY
45  fprintf(stdout, " TEST16 CVM(E) =%10.4f\n", y[0]);
46 #endif /* NOISY */
47 
48  free(xcopy);
49 
50  return y;
51 }
double * Cdhc_cramer_von_mises_exp(double *x, int n)
Definition: cvmw2e.c:7
void free(void *)
#define NULL
Definition: ccmath.h:32
#define x
void * malloc(YYSIZE_T)
int Cdhc_dcmp(const void *i, const void *j)
Definition: dcmp.c:1
float mean(IClass_statistics *statistics, int band)
Helper function for computing mean.