[GRASS-SVN] r53741 - grass/trunk/lib/cdhc

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 8 15:35:44 PST 2012


Author: neteler
Date: 2012-11-08 15:35:44 -0800 (Thu, 08 Nov 2012)
New Revision: 53741

Modified:
   grass/trunk/lib/cdhc/Makefile
   grass/trunk/lib/cdhc/test.c
Log:
tests updated from v.normal code

Modified: grass/trunk/lib/cdhc/Makefile
===================================================================
--- grass/trunk/lib/cdhc/Makefile	2012-11-08 17:33:18 UTC (rev 53740)
+++ grass/trunk/lib/cdhc/Makefile	2012-11-08 23:35:44 UTC (rev 53741)
@@ -18,7 +18,7 @@
 	cd $(OBJDIR) && $(call run_grass,./test < ../test_numbers.csv)
 
 #  Test functions
-$(OBJDIR)/test$(EXE): $(OBJDIR)/test.o $(CDHCDEP)
+$(OBJDIR)/test$(EXE): $(OBJDIR)/test.o $(GISDEP) $(CDHCDEP)
 	$(call linker)
 
-$(OBJDIR)/test$(EXE): LIBES = $(CDHCLIB)
+$(OBJDIR)/test$(EXE): LIBES = $(GISLIB) $(CDHCLIB)

Modified: grass/trunk/lib/cdhc/test.c
===================================================================
--- grass/trunk/lib/cdhc/test.c	2012-11-08 17:33:18 UTC (rev 53740)
+++ grass/trunk/lib/cdhc/test.c	2012-11-08 23:35:44 UTC (rev 53741)
@@ -1,51 +1,98 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <grass/gis.h>
 #include <grass/cdhc.h>
 
 
 int main(int argc, char **argv)
 {
-    double x[1000];
-    double *y;
+    double z[1000];
+    double *w;
     int n = 0;
 
-    while (scanf("%lf", &x[n++]) != EOF) ;
+    while (scanf("%lf", &z[n++]) != EOF) ;
     n--;
 
-    fprintf(stdout, "N=%d\n", n);
-    fprintf(stdout, "*y=%ld\n", y);
-    y = omnibus_moments(x, n);
-    fprintf(stdout, "*y=%ld\n", y);
-    y = geary_test(x, n);
-    fprintf(stdout, "*y=%ld\n", y);
-    y = dagostino_d(x, n);
-    fprintf(stdout, "y=%g\n", y[1]);
-    y = kuipers_v(x, n);
-    y = watson_u2(x, n);
-    y = durbins_exact(x, n);
-    y = anderson_darling(x, n);
-    y = cramer_von_mises(x, n);
+    fprintf(stdout, "TESTS:\n");
+    fprintf(stdout, "N:							%d\n", n);
 
-    /* for ks and lillefors, the discrepancy seems to come
-       in in computing the sum of x*x */
+    fprintf(stdout, "Moments \\sqrt{b_1} and b_2: ");
+    w = omnibus_moments(z, n);
+    fprintf(stdout, "%g %g\n", w[0], w[1]);
 
-    y = kolmogorov_smirnov(x, n);
-    y = chi_square(x, n);
-    y = shapiro_wilk(x, n);
-    y = shapiro_francia(x, n);
-    y = shapiro_wilk_exp(x, n);
-    y = cramer_von_mises_exp(x, n);
-    y = kolmogorov_smirnov_exp(x, n);
-    y = kuipers_v_exp(x, n);
-    y = watson_u2_exp(x, n);
-    y = anderson_darling_exp(x, n);
-    y = chi_square_exp(x, n);
+    fprintf(stdout, "Geary's a-statistic & an approx. normal:		");
+    w = geary_test(z, n);
+    fprintf(stdout, "%g %g\n", w[0], w[1]);
 
-/* missing from source code:
-    y = mod_maxlik_ratio(x, n);
-    y = coeff_variation(x, n);
-*/
-    y = kotz_families(x, n);
+    fprintf(stdout, "Extreme normal deviates:				");
+    w = extreme(z, n);
+    fprintf(stdout, "%g %g\n", w[0], w[1]);
 
+    fprintf(stdout, "D'Agostino's D & an approx. normal:			");
+    w = dagostino_d(z, n);
+    fprintf(stdout, "%g %g\n", w[0], w[1]);
+
+    fprintf(stdout, "Kuiper's V (regular & modified for normality):		");
+    w = kuipers_v(z, n);
+    fprintf(stdout, "%g %g\n", w[1], w[0]);
+
+    fprintf(stdout, "Watson's U^2 (regular & modified for normality):	");
+    w = watson_u2(z, n);
+    fprintf(stdout, "%g %g\n", w[1], w[0]);
+
+    fprintf(stdout, "Durbin's Exact Test (modified Kolmogorov):		");
+    w = durbins_exact(z, n);
+    fprintf(stdout, "%g\n", w[0]);
+
+    fprintf(stdout,
+	    "Anderson-Darling's A^2 (regular & modified for normality):	");
+    w = anderson_darling(z, n);
+    fprintf(stdout, "%g %g\n", w[1], w[0]);
+
+    fprintf(stdout,
+	    "Cramer-Von Mises W^2(regular & modified for normality):	");
+    w = cramer_von_mises(z, n);
+    fprintf(stdout, "%g %g\n", w[1], w[0]);
+
+    fprintf(stdout,
+	    "Kolmogorov-Smirnov's D (regular & modified for normality):	");
+    w = kolmogorov_smirnov(z, n);
+    fprintf(stdout, "%g %g\n", w[1], w[0]);
+
+    fprintf(stdout, "Chi-Square stat (equal probability classes) and d.f.:	");
+    w = chi_square(z, n);
+    fprintf(stdout, "%g %d\n", w[0], (int)w[1]);
+    if (n > 50) {
+	G_warning("Shapiro-Wilk's W cannot be used for n > 50");
+	if (n < 99)
+	    G_message("Use Weisberg-Binghams's W''");
+    }
+    else {
+	fprintf(stdout, "Shapiro-Wilk W:						");
+	w = shapiro_wilk(z, n);
+	fprintf(stdout, "%g\n", w[0]);
+    }
+
+    if (n > 99 || n < 50)
+	G_warning
+	    ("Weisberg-Bingham's W'' cannot be used for n < 50 or n > 99");
+    else {
+	fprintf(stdout, "Weisberg-Bingham's W'':			");
+	w = weisberg_bingham(z, n);
+	fprintf(stdout, "%g\n", w[0]);
+    }
+
+    if (n > 2000)
+	G_warning("Royston only extended Shapiro-Wilk's W up to n = 2000");
+    else {
+	fprintf(stdout, "Shapiro-Wilk W'':					");
+	w = royston(z, n);
+	fprintf(stdout, "%g\n", w[0]);
+    }
+
+    fprintf(stdout, "Kotz' T'_f (Lognormality vs. Normality):		");
+    w = kotz_families(z, n);
+    fprintf(stdout, "%g\n", w[0]);
+
     return EXIT_SUCCESS;
 }



More information about the grass-commit mailing list