1 /*
2  * $Id: rgb_kstest_test.c 250 2009-10-04 05:02:26Z rgb $
3  *
4  * See copyright in copyright.h and the accompanying file COPYING
5  */
6 
7 /*
8  *========================================================================
9  * A Kolmogorov-Smirnov test using Anderson-Darling tests a set of
10  * deviates for uniformity.  So does Kuiper KS.  The AD in this suite has
11  * been "symmetrized" so that it is not left biased, and is now very
12  * similar to the algorithm in R.  Kuiper was invented in the first place
13  * to be a symmetric test and has cyclic symmetry, not sensitive to
14  * the end points of the test interval.
15  *
16  * The test is simple.  Fill a test vector with uniform deviates from the
17  * default generator.  Run the selected KS test on them, and record the
18  * pvalue in the test's vector of pvalues to pass back to the front end
19  * for histogram graphing and/or a final KS test to a test pvalue.
20  *
21  * This test has two purposes.  One is that it is a legitimate test of
22  * rngs, although one that is perhaps too expensive to use for very large
23  * tsamples because it can require the input data to be sorted.  The
24  * other, more important one, is to allow me and other test developers
25  * a platform to gain experience in interpreting the final set of
26  * ks pvalues formed from a test of the uniformity of psamples pvalues
27  * from individual tests.  These appear to be consistently biased high
28  * for psamples = 100 even for what should be very good rngs, and I
29  * want to see what happens when I form a large set of ks pvalues of (say)
30  * 100 tsamples drawn directly as uniform deviates from known good
31  * generators, ones that I am CERTAIN have no detectable bias of this
32  * sort on only 100 samples.
33  *========================================================================
34  */
35 
36 #include <dieharder/libdieharder.h>
37 
rgb_kstest_test(Test ** test,int irun)38 int rgb_kstest_test(Test **test, int irun)
39 {
40 
41  uint t,tsamples;
42  double *testvec;
43 
44  tsamples = test[0]->tsamples;
45  testvec = (double *)malloc(tsamples*sizeof(double));
46 
47  if(verbose == D_RGB_KSTEST_TEST || verbose == D_ALL){
48      printf("Generating a vector of %u uniform deviates.\n",test[0]->tsamples);
49  }
50  for(t=0;t<tsamples;t++){
51 
52    /*
53     * Generate and (conditionally) print out a point.
54     */
55    testvec[t] = gsl_rng_uniform_pos(rng);
56    if(verbose == D_RGB_KSTEST_TEST || verbose == D_ALL){
57        printf("testvec[%u] = %f",t,testvec[t]);
58    }
59  }
60 
61  if(ks_test >= 3){
62    /*
63     * This (Kuiper) can be selected with -k 3 from the command line.
64     * All other values test variants of the regular kstest().
65     */
66    test[0]->pvalues[irun] = kstest_kuiper(testvec,tsamples);
67  } else {
68    /*
69     * This (Symmetrized KS) is -k 0,1,2.  Default is 0.
70     */
71    test[0]->pvalues[irun] = kstest(testvec,tsamples);
72  }
73 
74  free(testvec);
75 
76  if(verbose == D_RGB_KSTEST_TEST || verbose == D_ALL){
77    printf("# rgb_kstest_test(): test[0]->pvalues[%u] = %10.5f\n",irun,test[0]->pvalues[irun]);
78  }
79 
80  /*
81   * I guess we return 0 on normal healthy return
82   */
83  return(0);
84 
85 }
86 
87