Beispiel #1
0
static void PrintVal (ftab_Table * T, double d, ftab_FormType Form)
/*
 * Prints the value d according to format Form.
 */
{
   int s;
   /* All Table tables are initialized to -1; thus the test was not done for 
      this pair (e, f) if d = -1. */
   if (d < -0.9) {
      printf ("      ---  ");
   } else if (Form == ftab_String) {
      printf ("   ");
      s = 0.5 + d;
      printf ("%s", T->Strings[s]);
   } else if (Form == ftab_Integer) {
      printf ("   ");
      if (d <= LONG_MAX)
         printf ("%8ld", (long) d);
      else
         num_WriteD (d, 8, 0, 0);
   } else if (Form == ftab_Real) {
      printf ("   ");
      num_WriteD (d, 8, 2, 2);
   } else if (Form == ftab_pLog2) {
      PrintLog2 (d);
   } else if (Form == ftab_pLog10) {
      PrintLog10 (d);
   } else if (d < gofw_Epsilonp) {
      printf ("      eps  ");
   } else if (d < ftab_Suspectp) {
      printf ("   ");
      num_WriteD (d, 8, 2, 2);
   } else if (d > 1.0 - gofw_Epsilonp1 && Form == ftab_pVal2) {
      printf ("     -eps1  ");
   } else if (d > 1.0 - ftab_Suspectp && Form == ftab_pVal2) {
      printf ("   ");
      num_WriteD (d - 1.0, 8, 2, 2);
   } else if (Form == ftab_NotInit) {
      util_Error ("ftab_PrintTable:   Form is not initialized");
   } else {
      printf ("           ");
   }
}
Beispiel #2
0
static void PrintValTex (ftab_Table * T, double d, ftab_FormType Form)
/*
 * Similar to PrintVal, but prints in LaTex style.
 */
{
   int s;
   if (d < -0.9) {
      printf (" &   ---   ");
   } else if (Form == ftab_String) {
      printf (" & ");
      s = d + 0.5;
      printf ("%s", T->Strings[s]);
   } else if (Form == ftab_Integer) {
      printf (" & ");
      if (d <= LONG_MAX)
         printf ("%8ld", (long) d);
      else
         num_WriteD (d, 8, 0, 0);
   } else if (Form == ftab_Real) {
      printf (" & ");
      num_WriteD (d, 8, 2, 2);
   } else if (Form == ftab_pLog10) {
      PrintLog10Tex (d);
   } else if (Form == ftab_pLog2) {
      PrintLog2Tex (d);
   } else if (d < gofw_Epsilonp) {
      printf (" &   \\eps  ");
   } else if (d < ftab_Suspectp) {
      printf (" & ");
      num_WriteD (d, 8, 2, 2);
   } else if (d > 1.0 - gofw_Epsilonp1 && Form == ftab_pVal2) {
      printf (" &  \\epsm  ");
   } else if (d > 1.0 - ftab_Suspectp && Form == ftab_pVal2) {
      printf (" & ");
      num_WriteD (d - 1.0, 8, 2, 2);
   } else if (Form == ftab_NotInit) {
      util_Error ("ftab\\_PrintTable:   Form is not initialized");
   } else {
      printf (" &         ");
   }
}
Beispiel #3
0
static void InitAppear (int r, int s, int L, long Q, double E[], double KV[])
{
   util_Assert (r >= 0, "svaria_AppearanceSpacings:   r < 0");
   util_Assert (s > 0, "svaria_AppearanceSpacings:   s <= 0");
   /*   if (L >= s && L % s) {
      util_Error ("svaria_AppearanceSpacings:   L mod s != 0");
      }*/
   if (L < s && s % L) {
      util_Error ("svaria_AppearanceSpacings:   s mod L != 0");
   }
   util_Warning (Q < 10.0 * num_TwoExp[L],
      "svaria_AppearanceSpacings:   Q < 10 * 2^L");

   /* Theoretical mean E and variance KV for different L given by Maurer */
   if (L > 16) {
      /* For L > 16 and near 16, the 6-th decimal of E[L] could be
         erroneous. For KV [L], the 4-th decimal. */
      E[L] = L - 8.32746E-1;
      KV[L] = 3.423715;
   } else {
      E [1]  = 0.73264948;      KV[1]  = 0.68977;
      E [2]  = 1.53743829;      KV[2]  = 1.33774;
      E [3]  = 2.40160681;      KV[3]  = 1.90133;
      E [4]  = 3.31122472;      KV[4]  = 2.35774;
      E [5]  = 4.25342659;      KV[5]  = 2.70455;
      E [6]  = 5.21770525;      KV[6]  = 2.95403;
      E [7]  = 6.19625065;      KV[7]  = 3.12539;
      E [8]  = 7.18366555;      KV[8]  = 3.23866;
      E [9]  = 8.17642476;      KV[9]  = 3.31120;
      E [10] = 9.17232431;      KV[10] = 3.35646;
      E [11] = 10.1700323;      KV[11] = 3.38409;
      E [12] = 11.1687649;      KV[12] = 3.40065;
      E [13] = 12.1680703;      KV[13] = 3.41043;
      E [14] = 13.1676926;      KV[14] = 3.41614;
      E [15] = 14.1674884;      KV[15] = 3.41943;
      E [16] = 15.1673788;      KV[16] = 3.42130;
   }
}
Beispiel #4
0
static void Plot (unif01_Gen * gen, char *Nin, int Prec)
{
   FILE *f;

   if (scatter_Output == scatter_latex) {
      strcpy (Nout1, Nin);
      strcat (Nout1, ".tex");
      f = util_Fopen (Nout1, "w");
      HeadGraphTex (f);
      PutPointsTex (gen, f, Prec);
      BottomGraphTex (gen, f);
      util_Fclose (f);

   } else if (scatter_Output == scatter_gnu_ps ||
      scatter_Output == scatter_gnu_term) {
      HeadGraphGnu (gen, Nin);
      f = util_Fopen (Nout2, "w");
      PutPointsGnu (gen, f, Prec);
      util_Fclose (f);

   } else
      util_Error ("Plot:   scatter_Output has invalid value");
}
Beispiel #5
0
void gofw_GraphDistUnif (FILE * f, double U[], long N, char Desc[])
{
   long i;
   double UnSurN = 1.0 / N;
   if (f == NULL)
      f = stdout;

   switch (gofw_GraphSoft) {

   case gofw_Gnuplot:
      fprintf (f, "#----------------------------------\n");
      fprintf (f, "# %-70s\n\n", Desc);
      fprintf (f, "%16.8g  %16.8g\n", 0.0, 0.0);
      for (i = 1; i <= N; i++)
         fprintf (f, "%16.8g  %16.8g\n", U[i], i * UnSurN);
      fprintf (f, "%16.8g  %16.8g\n\n", 1.0, 1.0);
      break;

   case gofw_Mathematica:
      fprintf (f, "(*----------------------------------*)\n");
      fprintf (f, "(* %-70s\n *)\n\npoints = { \n", Desc);
      printMath2 (f, 0.0, 0.0);
      fprintf (f, ",\n");
      for (i = 1; i <= N; i++) {
         printMath2 (f, U[i], i * UnSurN);
         fprintf (f, ",\n");
      }
      printMath2 (f, 1.0, 1.0);
      fprintf (f, "\n}\n\n");
      break;

   default:
      util_Error ("gofw_GraphDistUnif:   gofw_GraphSoft unknown");
      break;
   }
}
Beispiel #6
0
static void PrintHead (char *name, ffam_Fam * fam, TestType test, void *par1,
                       int Nr, int j1, int j2, int jstep)
{
    long *Par = par1;
    double *ParD = par1;

    printf
    ("\n\n================================================================\n");
    printf ("Family:  %s\n\n", fam->name);
    printf ("Test:    %s\n", name);

    if (test == A_VARGEO)
        printf ("   N  = %ld,   n  = %ld,   r = %d",
                (long) ParD[0], (long) ParD[1], (int) ParD[2]);
    else
        printf ("   N  = %ld,   n  = %ld,   r = %d",
                Par[0], Par[1], (int) Par[2]);

    switch (test) {
    case A_VARGEO:
        printf (",   Mu = %f", ParD[3]);
        break;
    case A_RANDOMWALK1:
        printf (",   s = %d,   L  = %ld", (int) Par[3], (long) Par[4]);
        break;
    case A_RANDOMWALK1A:
        printf (",   s = %d,   t = %d,   L  = %ld,   C  = %lu",
                (int) Par[3], (int) Par[4], (long) Par[5], (bitset_BitSet) Par[6]);
        break;
    default:
        util_Error ("in fwalk, PrintHead:  no such case");
    }

    printf ("\n   Nr = %d,   j1 = %d,   j2 = %d,   jstep = %d\n\n",
            Nr, j1, j2, jstep);
}
Beispiel #7
0
static unif01_Gen * scatter_ReadData (
   unif01_Gen *gen,
   char *F               /* Input file name without its extension .dat */
   )
/*
 * Reads the data in file <F>.dat for scatter_PlotUnif, according to the
 * format of the figure in the documentation scatter.tex.
 */
{
   FILE *fin;                     /* Input file */
   int i, j;
   double xa, xb;
   unif01_Gen *genL;

   strncpy (Nin, F, (size_t) NUM_CHAR - 5);
   /* Add the extension .dat to input data file */
   strcat (Nin, ".dat");
   fin = util_Fopen (Nin, "r");

   fgets (S, NUM_CHAR, fin);
   j = sscanf (S, " %ld", &scatter_N);
   util_Assert (j > 0, "scatter_ReadData:   on reading scatter_N");

   fgets (S, NUM_CHAR, fin);
   j = sscanf (S, " %d", &scatter_t);
   util_Assert (j > 0, "scatter_ReadData:   on reading scatter_t");
   util_Assert (scatter_t <= scatter_MAXDIM,
                "scatter_ReadData:   scatter_t > scatter_MAXDIM");
   util_Assert (scatter_t > 1, "scatter_ReadData:   scatter_t < 2");

   fgets (S, NUM_CHAR, fin);
   util_ReadBool (S, &scatter_Over);

   fgets (S, NUM_CHAR, fin);
   j = sscanf (S, " %d %d", &scatter_x, &scatter_y);
   util_Assert (j > 0,
                "scatter_ReadData:   on reading scatter_x or scatter_y");
   util_Assert (scatter_x <= scatter_t,
                "scatter_ReadData:  scatter_x > scatter_t");
   util_Assert (scatter_y <= scatter_t,
                "scatter_ReadData:  scatter_y > scatter_t");

   /* By default, bounds are [0, 1] */
   for (i = 1; i < scatter_t; i++) {
      scatter_L[i] = 0.0;
      scatter_H[i] = 1.0;
   }

   do {
      fgets (S, NUM_CHAR, fin);
      j = sscanf (S, " %d %lf %lf", &i, &xa, &xb);
      util_Assert (j > 0,
         "scatter_ReadData:   on reading r, scatter_L[r], scatter_H[r]");
      util_Assert (i <= scatter_t,
                   "scatter_ReadData:   r > scatter_t");
      scatter_L[i] = xa;
      scatter_H[i] = xb;
      util_Assert (scatter_L[i] >= 0.0,
         "scatter_ReadData:   scatter_L[r] < 0");
      util_Assert (scatter_H[i] <= 1.0,
                   "scatter_ReadData:   scatter_H[r] > 1");
      util_Assert (scatter_L[i] < scatter_H[i],
                   "scatter_ReadData:   scatter_H[r] <= scatter_L[r]");
   } while (i != scatter_t);

   fgets (S, NUM_CHAR, fin);
   j = sscanf (S, " %lf %lf", &scatter_Width, &scatter_Height);
   util_Assert (j > 0,
      "scatter_ReadData:   on reading scatter_Width, scatter_Height");

   fgets (S, NUM_CHAR, fin);
   j = sscanf (S, " %12s", str);
   if (!strcmp (str, "latex"))
      scatter_Output = scatter_latex;
   else if (!strcmp (str, "gnu_term"))
      scatter_Output = scatter_gnu_term;
   else if (!strcmp (str, "gnu_ps"))
      scatter_Output = scatter_gnu_ps;
   else {
      util_Error ("scatter_ReadData:   on reading scatter_Output");
   }

   fgets (S, NUM_CHAR, fin);
   j = sscanf (S, " %d", &precision);
   util_Assert (j > 0, "scatter_ReadData:   on reading Precision");

   fgets (S, NUM_CHAR, fin);
   util_ReadBool (S, &scatter_Lacunary);

   if (scatter_Lacunary) {
      for (i = 0; i < scatter_t; i++) {
         fgets (S, NUM_CHAR, fin);
         j = sscanf (S, " %ld", &scatter_LacI[i]);
         util_Assert (j > 0,
            "scatter_ReadData:   on reading scatter_LacI[]");
      }
      genL = unif01_CreateLacGen (gen, scatter_t, scatter_LacI);
   } else
      genL = gen;

   util_Fclose (fin);
   return genL;
}
Beispiel #8
0
void svaria_SumCollector (unif01_Gen * gen, sres_Chi2 * res,
   long N, long n, int r, double g)
{
   const double gmax = 10.0;      /* Maximal value of g */
   const int jmax = 50;           /* Maximal number of classes */
   int j;                         /* Class index */
   long Seq;
   long i;
   double X;
   double Y;
   double Sum;
   long NbClasses;
   long *Loc;
   double V[1];
   lebool localRes = FALSE;
   chrono_Chrono *Timer;
   char *TestName = "svaria_SumCollector test";
   char chaine[LEN1 + 1] = "";
   char str[LEN2 + 1];

   Timer = chrono_Create ();
   if (swrite_Basic)
      WriteDataSumColl (gen, TestName, N, n, r, g);

   if (g < 1.0 || g > gmax) {
      util_Error ("svaria_SumCollector:   g < 1.0 or g > 10.0");
   }
   if (res == NULL) {
      localRes = TRUE;
      res = sres_CreateChi2 ();
   }
   sres_InitChi2 (res, N, jmax, "svaria_SumCollector");
   Loc = res->Loc;

   res->jmin = g;
   res->jmax = jmax;
   Sum = 0.0;
   for (j = res->jmin; j < jmax; j++) {
      res->NbExp[j] = n * ProbabiliteG (res->jmin, j, g);
      Sum += res->NbExp[j];
   }
   res->NbExp[jmax] = util_Max (0.0, n - Sum);

   if (swrite_Classes)
      gofs_WriteClasses (res->NbExp, Loc, res->jmin, res->jmax, 0);
   gofs_MergeClasses (res->NbExp, Loc, &res->jmin, &res->jmax, &NbClasses);
   if (swrite_Classes)
      gofs_WriteClasses (res->NbExp, Loc, res->jmin, res->jmax, NbClasses);

   strncpy (chaine, "SumCollector sVal1:   chi2 with ", (size_t) LEN1);
   sprintf (str, "%ld", NbClasses - 1);
   strncat (chaine, str, (size_t) LEN2);
   strncat (chaine, " degrees of freedom", (size_t) LEN1);
   statcoll_SetDesc (res->sVal1, chaine);
   res->degFree = NbClasses - 1;
   if (res->degFree < 1) {
      if (localRes)
         sres_DeleteChi2 (res);
      return;
   }

   for (Seq = 1; Seq <= N; Seq++) {
      for (j = 1; j <= jmax; j++)
         res->Count[j] = 0;

      for (i = 1; i <= n; i++) {
         X = 0.0;
         j = 0;
         do {
            X += unif01_StripD (gen, r);
            ++j;
         }
         while (X <= g);
         if (j > res->jmax)
            ++res->Count[res->jmax];
         else
            ++res->Count[Loc[j - 1]];
      }
      if (swrite_Counters)
         tables_WriteTabL (res->Count, res->jmin, res->jmax, 5, 10,
                           "Observed numbers:");
      Y = gofs_Chi2 (res->NbExp, res->Count, res->jmin, res->jmax);
      statcoll_AddObs (res->sVal1, Y);
   }

   V[0] = NbClasses - 1;
   gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_ChiSquare, V,
                      res->sVal2, res->pVal2);
   res->pVal1->NObs = N;
   sres_GetChi2SumStat (res);
   
   if (swrite_Collectors)
      statcoll_Write (res->sVal1, 5, 14, 4, 3);

   if (swrite_Basic) {
      swrite_AddStrChi (str, LEN2, res->degFree);
      gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, str);
      swrite_Chi2SumTest (N, res);
      swrite_Final (gen, Timer);
   }
   if (localRes)
      sres_DeleteChi2 (res);
   chrono_Delete (Timer);
}
Beispiel #9
0
void gofw_GraphFunc (FILE *f, wdist_CFUNC F, double par[], double a,
                     double b, int M, int mono, char Desc[])
{
   int i;
   double yprec, y, x, h;
   if (f == NULL)
      f = stdout;

   switch (gofw_GraphSoft) {

      /* Il y a trop de repetition de code ici.  */
   case gofw_Gnuplot:
      fprintf (f, "#----------------------------------\n");
      fprintf (f, "# %-70s\n\n", Desc);
      h = (b - a) / M;
      if (mono == 1)
         yprec = -DBL_MAX;
      else if (mono == -1)
         yprec = DBL_MAX;
      else
         yprec = 0.0;
      for (i = 0; i <= M; i++) {
         x = a + i * h;
         y = F (par, x);
         fprintf (f, "%16.8g      %16.8g", x, y);
         switch (mono) {
         case 1:
            if (y < yprec)
               fprintf (f, "    #  DECREASING");
            break;
         case -1:
            if (y > yprec)
               fprintf (f, "    #  INCREASING");
            break;
         default:
            break;
         }
         fprintf (f, "\n");
         yprec = y;
      }
      fprintf (f, "\n");
      break;

   case gofw_Mathematica:
      fprintf (f, "(*----------------------------------*)\n");
      fprintf (f, "(* %-70s\n *)\n\npoints = { \n", Desc);
      h = (b - a) / M;
      if (mono == 1)
         yprec = -DBL_MAX;
      else if (mono == -1)
         yprec = DBL_MAX;
      else
         yprec = 0.0;
      for (i = 0; i <= M; i++) {
         x = a + i * h;
         y = F (par, x);
         printMath2 (f, x, y);
         if (i < M)
            fprintf (f, ",");

         switch (mono) {
         case 1:
            if (y < yprec)
               fprintf (f, "   (* DECREASING *)");
            break;
         case -1:
            if (y > yprec)
               fprintf (f, "   (* INCREASING *)");
            break;
         default:
            break;
         }
         fprintf (f, "\n");
         yprec = y;
      }
      fprintf (f, "}\n\n");
      break;

   default:
      util_Error ("gofw_GraphFunc:   gofw_GraphSoft unknown");
      break;
   }
}
Beispiel #10
0
static void EntropyDisc00 (unif01_Gen * gen, sentrop_Res * res,
   long N, long n, int r, int s, int L)
/*
 * Test based on the discrete entropy, proposed by Compagner and L'Ecuyer
 */
{
   long Seq;
   long j;
   long i;
   double EntropyNorm;            /* Normalized entropy */
   double Entropy;                /* Value of entropy S */
   double EntropyPrev;            /* Previous value of entropy */
   double SumSq;                  /* To compute the covariance */
   double Sigma, Mu;              /* Parameters of the normal law */
   double tem;
   double nLR = n;
   long d;                        /* 2^s */
   long C;                        /* 2^L */
   long LSurs;                    /* L / s */
   long sSurL;                    /* s / L */
   long nLSurs;                   /* nL / s */
   double xLgx[NLIM + 1];         /* = -i/n * Lg (i/n) */
   unsigned long Block;
   unsigned long Number;
   unsigned int LL = L;
   lebool localRes = FALSE;
   chrono_Chrono *Timer;
   char *TestName = "sentrop_EntropyDisc test";

   Timer = chrono_Create ();
   if (s <= L && L % s) {
      util_Error ("EntropyDisc00:   s <= L and L % s != 0");
   }
   if (s > L && s % L) {
      util_Error ("EntropyDisc00:   s > L and s % L != 0");
   }

   d = num_TwoExp[s];
   C = num_TwoExp[L];

   if (s <= L)
      LSurs = L / s;
   else {
      sSurL = s / L;
      nLSurs = n / sSurL;
      if (n % sSurL)
         ++nLSurs;
   }

   util_Assert (n / num_TwoExp[L] < NLIM,
      "sentrop_EntropyDisc:    n/2^L is too large");
   smultin_MultinomMuSigma (n, num_TwoExp[L], 0.0, (double) n,
        FoncMNEntropie, &Mu, &Sigma);

   if (swrite_Basic)
      WriteDataDisc (gen, TestName, N, n, r, s, L, Mu, Sigma);

   if (res == NULL) {
      localRes = TRUE;
      res = sentrop_CreateRes ();
   }
   InitRes (res, N, C - 1, "sentrop_EntropyDisc");
   CalcLgx (xLgx, n);

   statcoll_SetDesc (res->Bas->sVal1, "EntropyDisc sVal1");
   statcoll_SetDesc (res->Bas->pVal1, "EntropyDisc pVal1");
   SumSq = EntropyPrev = 0.0;

   for (Seq = 1; Seq <= N; Seq++) {
      for (i = 0; i < C; i++)
         res->Count[i] = 0;

      if (s <= L) {
         for (i = 1; i <= n; i++) {
            Block = unif01_StripB (gen, r, s);
            for (j = 2; j <= LSurs; j++)
               Block = Block * d + unif01_StripB (gen, r, s);
            ++res->Count[Block];
         }

      } else {                    /* s > L */
         for (i = 1; i <= nLSurs; i++) {
            Number = unif01_StripB (gen, r, s);
            for (j = 1; j <= sSurL; j++) {
               Block = Number % C;
               ++res->Count[Block];
               Number >>= LL;
            }
         }
      }

      /* Compute entropy */
      Entropy = 0.0;
      for (i = 0; i < C; i++) {
         if (res->Count[i] > NLIM) {
            tem = res->Count[i] / nLR;
            tem *= -num_Log2 (tem);
            Entropy += tem;
         } else if (res->Count[i] > 0) {
            Entropy += xLgx[res->Count[i]];
         }
      }
      EntropyNorm = (Entropy - Mu) / Sigma;
      statcoll_AddObs (res->Bas->sVal1, EntropyNorm);
      SumSq += EntropyNorm * EntropyPrev;
      EntropyPrev = EntropyNorm;

      if (swrite_Counters)
         tables_WriteTabL (res->Count, 0, C - 1, 5, 10, "Counters:");

      if (swrite_Collectors) {
         printf ("Entropy = ");
         num_WriteD (Entropy, 15, 6, 1);
         printf ("\n");
      }
   }

   gofw_ActiveTests2 (res->Bas->sVal1->V, res->Bas->pVal1->V, N, wdist_Normal,
      (double *) NULL, res->Bas->sVal2, res->Bas->pVal2);
   res->Bas->pVal1->NObs = N;
   sres_GetNormalSumStat (res->Bas);

   /* We now test the correlation between successive values of the entropy.
      The next SumSq should have mean 0 and variance 1. */
   if (N > 1) {
      res->Bas->sVal2[gofw_Cor] = SumSq / sqrt ((double) N);
      res->Bas->pVal2[gofw_Cor] = fbar_Normal1 (res->Bas->sVal2[gofw_Cor]);
   }
   if (swrite_Collectors) {
      statcoll_Write (res->Bas->sVal1, 5, 14, 4, 3);
   }
   if (swrite_Basic) {
      WriteResultsDisc (N, res->Bas->sVal2, res->Bas->pVal2, res->Bas);
      swrite_Final (gen, Timer);
   }

   if (localRes)
      sentrop_DeleteRes (res);
   chrono_Delete (Timer);
}