void diehard_dna(Test **test, int irun)
{

 uint i,j,k,l,m,n,o,p,q,r,t,boffset;
 uint i0,j0,k0,l0,m0,n0,o0,p0,q0,r0;
 Xtest ptest;
 char **********w;

 /*
  * p = 141909, with sigma 339, FOR tsamples 2^21+1 2 letter words.
  * These cannot be varied unless one figures out the actual
  * expected "missing works" count as a function of sample size.  SO:
  *
  * ptest.x = number of "missing words" given 2^21+1 trials
  * ptest.y = 141909
  * ptest.sigma = 339
  */
 ptest.x = 0.0;  /* Initial value */
 ptest.y = 141909.0;
 ptest.sigma = 339.0;

 /*
  * We now make tsamples measurements, as usual, to generate the missing
  * statistic.  Wow!  10 dimensions!  I don't think even my tensor()
  * package will do that...;-)
  */

 w = (char **********)malloc(4*sizeof(char *********));
 for(i=0;i<4;i++){
   w[i] = (char *********)malloc(4*sizeof(char ********));
   for(j=0;j<4;j++){
     w[i][j] = (char ********)malloc(4*sizeof(char *******));
     for(k=0;k<4;k++){
       w[i][j][k] = (char *******)malloc(4*sizeof(char******));
       for(l=0;l<4;l++){
         w[i][j][k][l] = (char ******)malloc(4*sizeof(char*****));
         for(m=0;m<4;m++){
           w[i][j][k][l][m] = (char *****)malloc(4*sizeof(char****));
           for(n=0;n<4;n++){
             w[i][j][k][l][m][n] = (char ****)malloc(4*sizeof(char***));
             for(o=0;o<4;o++){
               w[i][j][k][l][m][n][o] = (char ***)malloc(4*sizeof(char**));
               for(p=0;p<4;p++){
                 w[i][j][k][l][m][n][o][p] = (char **)malloc(4*sizeof(char*));
                 for(q=0;q<4;q++){
                   w[i][j][k][l][m][n][o][p][q] = (char *)malloc(4*sizeof(char));
                   /* Zero the column */
                   memset(w[i][j][k][l][m][n][o][p][q],0,4*sizeof(char));
		 }
	       }
	     }
	   }
	 }
       }
     }
   }
 }

 /*
  * To minimize the number of rng calls, we use each j and k mod 32
  * to determine the offset of the 10-bit long string (with
  * periodic wraparound) to be used for the next iteration.  We
  * therefore have to "seed" the process with a random l
  */
 q = gsl_rng_get(rng);
 for(t=0;t<test[0]->tsamples;t++){
   if(overlap){
     /*
      * Let's do this the cheap/easy way first, sliding a 20 bit
      * window along each int for the 32 possible starting
      * positions a la birthdays, before trying to slide it all
      * the way down the whole random bitstring implicit in a
      * long sequence of random ints.  That way we can exit
      * the tsamples loop at tsamples = 2^15...
      */
     if(t%32 == 0) {
       i0 = gsl_rng_get(rng);
       j0 = gsl_rng_get(rng);
       k0 = gsl_rng_get(rng);
       l0 = gsl_rng_get(rng);
       m0 = gsl_rng_get(rng);
       n0 = gsl_rng_get(rng);
       o0 = gsl_rng_get(rng);
       p0 = gsl_rng_get(rng);
       q0 = gsl_rng_get(rng);
       r0 = gsl_rng_get(rng);
       boffset = 0;
     }
     /*
      * Get four "letters" (indices into w)
      */
     i = get_bit_ntuple(&i0,1,2,boffset);
     j = get_bit_ntuple(&j0,1,2,boffset);
     k = get_bit_ntuple(&k0,1,2,boffset);
     l = get_bit_ntuple(&l0,1,2,boffset);
     m = get_bit_ntuple(&m0,1,2,boffset);
     n = get_bit_ntuple(&n0,1,2,boffset);
     o = get_bit_ntuple(&o0,1,2,boffset);
     p = get_bit_ntuple(&p0,1,2,boffset);
     q = get_bit_ntuple(&q0,1,2,boffset);
     r = get_bit_ntuple(&r0,1,2,boffset);
     /* printf("%u:   %u  %u  %u  %u  %u\n",t,i,j,k,l,boffset); */
     w[i][j][k][l][m][n][o][p][q][r]++;
     boffset++;

   } else {
     /*
      * Get two "letters" (indices into w)
      */
     boffset = q%32;
     i = gsl_rng_get(rng);
     i = get_bit_ntuple(&i,1,2,boffset);
     boffset = i%32;
     j = gsl_rng_get(rng);
     j = get_bit_ntuple(&j,1,2,boffset);
     boffset = j%32;
     k = gsl_rng_get(rng);
     k = get_bit_ntuple(&k,1,2,boffset);
     boffset = k%32;
     l = gsl_rng_get(rng);
     l = get_bit_ntuple(&l,1,2,boffset);
     boffset = l%32;
     m = gsl_rng_get(rng);
     m = get_bit_ntuple(&m,1,2,boffset);
     boffset = m%32;
     n = gsl_rng_get(rng);
     n = get_bit_ntuple(&n,1,2,boffset);
     boffset = n%32;
     o = gsl_rng_get(rng);
     o = get_bit_ntuple(&o,1,2,boffset);
     boffset = o%32;
     p = gsl_rng_get(rng);
     p = get_bit_ntuple(&p,1,2,boffset);
     boffset = p%32;
     q = gsl_rng_get(rng);
     q = get_bit_ntuple(&q,1,2,boffset);
     boffset = q%32;
     r = gsl_rng_get(rng);
     r = get_bit_ntuple(&r,1,2,boffset);
     w[i][j][k][l][m][n][o][p][q][r]++;
   }
 }
 /*
  * Now we count the holes, so to speak
  */
 ptest.x = 0;
 for(i=0;i<4;i++){
   for(j=0;j<4;j++){
     for(k=0;k<4;k++){
       for(l=0;l<4;l++){
         for(m=0;m<4;m++){
           for(n=0;n<4;n++){
             for(o=0;o<4;o++){
               for(p=0;p<4;p++){
                 for(q=0;q<4;q++){
                   for(r=0;r<4;r++){
                     if(w[i][j][k][l][m][n][o][p][q][r] == 0){
                       ptest.x += 1.0;
                       /* printf("ptest.x = %f  Hole: w[%u][%u][%u][%u] = %u\n",ptest.x,i,j,k,l,w[i][j][k][l]); */
		     }
		   }
		 }
	       }
	     }
	   }
	 }
       }
     }
   }
 }
 MYDEBUG(D_DIEHARD_DNA) {
   printf("%f %f %f\n",ptest.y,ptest.x,ptest.x-ptest.y);
 }

 Xtest_eval(&ptest);
 test[0]->pvalues[irun] = ptest.pvalue;

 MYDEBUG(D_DIEHARD_DNA) {
   printf("# diehard_dna(): test[0]->pvalues[%u] = %10.5f\n",irun,test[0]->pvalues[irun]);
 }

 /*
  * Don't forget to free w when done, in reverse order
  */
 for(i=0;i<4;i++){
   for(j=0;j<4;j++){
     for(k=0;k<4;k++){
       for(l=0;l<4;l++){
         for(m=0;m<4;m++){
           for(n=0;n<4;n++){
             for(o=0;o<4;o++){
               for(p=0;p<4;p++){
                 for(q=0;q<4;q++){
                   free(w[i][j][k][l][m][n][o][p][q]);
		 }
		 free(w[i][j][k][l][m][n][o][p]);
	       }
               free(w[i][j][k][l][m][n][o]);
	     }
             free(w[i][j][k][l][m][n]);
	   }
           free(w[i][j][k][l][m]);
	 }
         free(w[i][j][k][l]);
       }
       free(w[i][j][k]);
     }
     free(w[i][j]);
   }
   free(w[i]);
 }
 free(w);

}
void diehard_oqso(Test **test, int irun)
{

 uint i,j,k,l,i0,j0,k0,l0,t,boffset;
 Xtest ptest;
 char ****w;

 /*
  * p = 141909, with sigma 295, FOR tsamples 2^21 2 letter words.
  * These cannot be varied unless one figures out the actual
  * expected "missing works" count as a function of sample size.  SO:
  *
  * ptest.x = number of "missing words" given 2^21 trials
  * ptest.y = 141909
  * ptest.sigma = 295
  */
 ptest.x = 0.0;  /* Initial value */
 ptest.y = 141909.0;
 ptest.sigma = 295.0;

 /*
  * We now make tsamples measurements, as usual, to generate the
  * missing statistic.  We proceed exactly as we did in opso, but
  * with a 4d 32x32x32x32 matrix and 5 bit indices.  This should
  * basically be strongly related to a Knuth hyperplane test in
  * four dimensions.  Equally obviously there is a sequence of
  * tests, all basically identical, that can be done here much
  * as rgb_bitdist tries to do them.  I'll postpone thinking about
  * this in detail until I'm done with diehard and some more of STS
  * and maybe have implemented the REAL Knuth tests from the Art of
  * Programming.
  */

 w = (char ****)malloc(32*sizeof(char ***));
 for(i=0;i<32;i++){
   w[i] = (char ***)malloc(32*sizeof(char **));
   for(j=0;j<32;j++){
     w[i][j] = (char **)malloc(32*sizeof(char *));
     for(k=0;k<32;k++){
       w[i][j][k] = (char *)malloc(32*sizeof(char));
       /* Zero the column */
       memset(w[i][j][k],0,32*sizeof(char));
     }
   }
 }

 /*
  * To minimize the number of rng calls, we use each j and k mod 32
  * to determine the offset of the 10-bit long string (with
  * periodic wraparound) to be used for the next iteration.  We
  * therefore have to "seed" the process with a random l
  */
 l = gsl_rng_get(rng);
 for(t=0;t<test[0]->tsamples;t++){
   if(overlap){
     /*
      * Let's do this the cheap/easy way first, sliding a 20 bit
      * window along each int for the 32 possible starting
      * positions a la birthdays, before trying to slide it all
      * the way down the whole random bitstring implicit in a
      * long sequence of random ints.  That way we can exit
      * the tsamples loop at tsamples = 2^15...
      */
     if(t%32 == 0) {
       i0 = gsl_rng_get(rng);
       j0 = gsl_rng_get(rng);
       k0 = gsl_rng_get(rng);
       l0 = gsl_rng_get(rng);
       boffset = 0;
     }
     /*
      * Get four "letters" (indices into w)
      */
     i = get_bit_ntuple(&i0,1,5,boffset);
     j = get_bit_ntuple(&j0,1,5,boffset);
     k = get_bit_ntuple(&k0,1,5,boffset);
     l = get_bit_ntuple(&l0,1,5,boffset);
     /* printf("%u:   %u  %u  %u  %u  %u\n",t,i,j,k,l,boffset); */
     w[i][j][k][l]++;
     boffset++;

   } else {
     /*
      * Get four "letters" (indices into w)
      */
     boffset = l%32;
     i = gsl_rng_get(rng);
     i = get_bit_ntuple(&i,1,5,boffset);
     boffset = i%32;
     j = gsl_rng_get(rng);
     j = get_bit_ntuple(&j,1,5,boffset);
     boffset = j%32;
     k = gsl_rng_get(rng);
     k = get_bit_ntuple(&k,1,5,boffset);
     boffset = k%32;
     l = gsl_rng_get(rng);
     l = get_bit_ntuple(&l,1,5,boffset);
     w[i][j][k][l]++;
   }
 }
 /*
  * Now we count the holes, so to speak
  */
 ptest.x = 0.0;
 for(i=0;i<32;i++){
   for(j=0;j<32;j++){
     for(k=0;k<32;k++){
       for(l=0;l<32;l++){
         if(w[i][j][k][l] == 0){
           ptest.x += 1.0;
           /* printf("ptest.x = %f  Hole: w[%u][%u][%u][%u] = %u\n",ptest.x,i,j,k,l,w[i][j][k][l]); */
	 }
       }
     }
   }
 }
 MYDEBUG(D_DIEHARD_OQSO){
   printf("%f %f %f\n",ptest.y,ptest.x,ptest.x-ptest.y);
 }

 Xtest_eval(&ptest);
 test[0]->pvalues[irun] = ptest.pvalue;

 MYDEBUG(D_DIEHARD_OQSO) {
   printf("# diehard_oqso(): ks_pvalue[%u] = %10.5f\n",irun,test[0]->pvalues[irun]);
 }

 /*
  * Don't forget to free w when done, in reverse order
  */
 for(i=0;i<32;i++){
   for(j=0;j<32;j++){
      for(k=0;k<32;k++){
         free(w[i][j][k]);
      }
      free(w[i][j]);
   }
   free(w[i]);
 }
 free(w);

}
示例#3
0
int sts_runs(Test **test, int irun)
{

 int b,t;
 uint value;
 uint *rand_int;
 Xtest ptest;
 double pones,c00,c01,c10,c11;;

 /*
  * for display only.  2 means sts_runs tests 2-tuples.
  */
 test[0]->ntuple = 2;

 /*
  * Allocate the space needed by the test.
  */
 rand_int = (uint *)malloc(test[0]->tsamples*sizeof(uint));

 /*
  * Number of total bits from -t test[0]->tsamples = size of rand_int[]
  */
 bits = rmax_bits*test[0]->tsamples;

 /*
  * We have to initialize these a bit differently this time
  */
 ptest.x = 0.0;

 /*
  * Create entire bitstring to be tested
  */
 for(t=0;t<test[0]->tsamples;t++){
   rand_int[t] = gsl_rng_get(rng);
 }

 /*
  * Fill vector of "random" integers with selected generator.
  * NOTE WELL:  This can also be done by reading in a file!
  */
 pones = 0.0;
 c00 = 0.0;
 c01 = 0.0;
 c10 = 0.0;  /* Equal to c01 by obvious periodic symmetry */
 c11 = 0.0;
 for(b=0;b<bits;b++){
   /*
    * This gets the integer value of the ntuple at index position
    * n in the current bitstring, from a window with cyclic wraparound.
    */
   value = get_bit_ntuple(rand_int,test[0]->tsamples,2,b);
   switch(value){
     case 0:   /* 00 no new ones */
       c00++;
       break;
     case 1:   /* 01 no new ones */
       c01++;
       ptest.x++;
       break;
     case 2:   /* 10 one new one (from the left) */
       c10++;
       ptest.x++;
       pones++;
       break;
     case 3:   /* 11 one new one (from the left) */
       c11++;
       pones++;
       break;
   }
   MYDEBUG(D_STS_RUNS) {
     printf("# sts_runs(): ptest.x = %f, pone = %f\n",ptest.x,pones);
   }
 }
 /*
  * form the probability of getting a one in the entire sample
  */
 pones /= (double) test[0]->tsamples*rmax_bits;
 c00 /= (double) test[0]->tsamples*rmax_bits;
 c01 /= (double) test[0]->tsamples*rmax_bits;
 c10 /= (double) test[0]->tsamples*rmax_bits;
 c11 /= (double) test[0]->tsamples*rmax_bits;

 /*
  * Now we can finally compute the targets for the problem.
  */
 ptest.y = 2.0*bits*pones*(1.0-pones);
 ptest.sigma = 2.0*sqrt(bits)*pones*(1.0-pones);

 MYDEBUG(D_STS_RUNS) {
   printf(" p = %f c00 = %f c01 = %f c10 = %f c11 = %f\n",pones,c00,c01,c10,c11);
 }

 Xtest_eval(&ptest);
 test[0]->pvalues[irun] = ptest.pvalue;

 MYDEBUG(D_STS_RUNS) {
   printf("# sts_runs(): test[0]->pvalues[%u] = %10.5f\n",irun,test[0]->pvalues[irun]);
 }

 free(rand_int);

 return(0);

}