コード例 #1
0
ファイル: gofw.c プロジェクト: cartazio/htestu
void gofw_IterSpacingsTests0 (double U[], long N, int k,
   lebool printval, lebool graph, FILE * f)
   /* Assumes that U is sorted.  */
{
   int j;
   long i;
   double *S, *UU;
   gofw_TestArray sVal, pVal;

   UU = (double *) util_Calloc (1 + (size_t) N, sizeof (double));
   S = (double *) util_Calloc (1 + (size_t) N, sizeof (double));
   printf ("\n");
   for (i = 1; i <= N; i++)
      UU[i] = U[i];               /* UU is a copy of U */
   for (j = 1; j <= k; j++) {
      printf ("-----------------------------------\n"
         "EDF Tests after \"gofw_IterateSpacings\", level :%2d\n", j);
      gofs_DiffD (UU, S, 1, N, 0.0, 1.0);
      gofs_IterateSpacings (UU, S, N);
      tables_QuickSortD (UU, 1, N);
      gofw_ActiveTests0 (UU, N, sVal, pVal);
      gofw_WriteActiveTests0 (N, sVal, pVal);
      strncpy (desc, "Values of Uniforms after IterateSpacings, level ",
         (size_t) LEN1);
      sprintf (str, "%2d", j);
      strncat (desc, str, (size_t) LEN2);
      if (printval > 0)
         tables_WriteTabD (UU, 1, N, 5, 15, 6, 6, desc);
      if (graph > 0)
         gofw_GraphDistUnif (f, UU, N, desc);
   }
   util_Free (UU);
   util_Free (S);
}
コード例 #2
0
ファイル: num2.c プロジェクト: Marc-B-Reynolds/TestU01x
void num2_CalcMatStirling (double ***M, int m, int n)
/* Calcul des elements de la matrice MatStirling [0..m, 0..n]. */
{
   int i, j, k;
   *M = (double **) util_Calloc ((size_t) (m + 1), sizeof (double *));
   for (i = 0; i <= m; i++)
      (*M)[i] = (double *) util_Calloc ((size_t) (n + 1), sizeof (double));

   for (i = 0; i <= m; i++) {
      for (j = 0; j <= n; j++) {
         (*M)[i][j] = 0.0;
      }
   }

   (*M)[0][0] = 1.0;
   for (j = 1; j <= n; j++) {
      (*M)[0][j] = 0.0;
      if (j <= m) {
         k = j - 1;
         (*M)[j][j] = 1.0;
      } else
         k = m;
      for (i = 1; i <= k; i++) {
         (*M)[i][j] = (double) (i) * (*M)[i][j - 1] + (*M)[i - 1][j - 1];
      }
   }
}
コード例 #3
0
ファイル: udeng.c プロジェクト: Marc-B-Reynolds/TestU01x
static unif01_Gen *CreateDenga (unsigned long m, unsigned long b, int k,
   unsigned long S[], int id)
{
   unif01_Gen *gen;
   DX02_state *state;
   DX02_param *param;
   size_t leng;
   char name[LEN + 1];
   int j;

   gen = util_Malloc (sizeof (unif01_Gen));
   state = util_Malloc (sizeof (DX02_state));
   param = util_Malloc (sizeof (DX02_param));
   if (0 == id) {
      util_Assert (k < 129, "udeng_CreateDL00a:   k > 128");
   } else {
      util_Assert (k < 129, "udeng_CreateDX02a:   k > 128");
   }

   state->X = util_Calloc (MASK1 + 1, sizeof (double));
   for (j = 0; j < k; j++)
      state->X[k - j - 1] = S[j] % m;
   state->s = k - 1;
   state->K = k;
   param->b = b;
   param->m = m;

   if (0 == id)
      strcpy (name, "udeng_CreateDL00a:");
   else
#ifdef LAC
      strcpy (name, "udeng_CreateDX02a, Lac = {0, 101, 102}:");
#else
      strcpy (name, "udeng_CreateDX02a:");
#endif
   addstr_Ulong (name, "   m = ", m);
   addstr_Ulong (name, ",   b = ", b);
   addstr_Uint (name, ",   k = ", (unsigned) k);
   addstr_ArrayUlong (name, ",   S = ", k, S);
   leng = strlen (name);
   gen->name = util_Calloc (leng + 1, sizeof (char));
   strncpy (gen->name, name, leng);

   gen->param   = param;
   gen->state   = state;
   if (0 == id) {
      gen->GetBits = &DL00a_Bits;
      gen->GetU01  = &DL00a_U01;
   } else {
      gen->GetBits = &DX02a_Bits;
      gen->GetU01  = &DX02a_U01;
   }
   gen->Write   = &WrDX02a;
   return gen;
}
コード例 #4
0
ファイル: ffam.c プロジェクト: Marc-B-Reynolds/TestU01x
ffam_Fam * ffam_CreateFam (int Ng, char *name)
{
    ffam_Fam *fam;
    size_t len;

    fam = util_Malloc (sizeof (ffam_Fam));
    fam->Resol = util_Calloc ((size_t) Ng, sizeof (int));
    fam->LSize = util_Calloc ((size_t) Ng, sizeof (int));
    fam->Gen = util_Calloc ((size_t) Ng, sizeof (unif01_Gen *));
    fam->Ng = Ng;
    len = strlen (name);
    fam->name = util_Calloc (1 + len, sizeof (char));
    strncpy (fam->name, name, (size_t) len);
    return fam;
}
コード例 #5
0
ファイル: uweyl.c プロジェクト: JamesHirschorn/TestU01-CMake
unif01_Gen *uweyl_CreateSNWeyl (long M, double Alpha, long n0)
{
   unif01_Gen *gen;
   SNWeyl_param *param;
   Weyl_state *state;
   size_t leng;
   char name[LEN + 1];

   util_Assert ((Alpha > 0.0), "uweyl_CreateSNWeyl:   Alpha <= 0");
   util_Assert ((Alpha < 1.0), "uweyl_CreateSNWeyl:   Alpha >= 1");

   gen = util_Malloc (sizeof (unif01_Gen));
   param = util_Malloc (sizeof (SNWeyl_param));
   state = util_Malloc (sizeof (Weyl_state));
   param->Alpha = Alpha;
   param->M = M;
   if (n0 < 0)
      n0 = -n0;
   state->n = n0;

   strncpy (name, "uweyl_CreateSNWeyl (shuffled nested):", (size_t) LEN);
   addstr_Long (name, "   M = ", M);
   addstr_Double (name, ",   Alpha = ", Alpha);
   addstr_Long (name, ",   n0 = ", n0);
   leng = strlen (name);
   gen->name = util_Calloc (leng + 1, sizeof (char));
   strncpy (gen->name, name, leng);

   gen->GetBits = &SNWeyl_Bits;
   gen->GetU01  = &SNWeyl_U01;
   gen->Write   = &WrWeyl;
   gen->param   = param;
   gen->state   = state;
   return gen;
}
コード例 #6
0
ファイル: unumrec.c プロジェクト: Marc-B-Reynolds/TestU01x
unif01_Gen * unumrec_CreateRan0 (long s)
{
   unif01_Gen *gen;
   Ran0_param *param;
   Ran0_state *state;
   size_t leng;
   char name[LEN + 1];

   util_Assert (s > 0, "unumrec_CreateRan0:   s <= 0");

   gen = util_Malloc (sizeof (unif01_Gen));
   param = util_Malloc (sizeof (Ran0_param));
   state = util_Malloc (sizeof (Ran0_state));

   strncpy (name, "unumrec_CreateRan0:", LEN);
   addstr_Long (name, "   s = ", s);
   leng = strlen (name);
   gen->name = util_Calloc (leng + 1, sizeof (char));
   strncpy (gen->name, name, leng);

   state->S1 = s;
   param->Norm = 1.0 / M1;

   gen->GetBits = &Ran0_Bits;
   gen->GetU01  = &Ran0_U01;
   gen->Write   = &WrRan0;
   gen->param   = param;
   gen->state   = state;
   return gen;
}
コード例 #7
0
ファイル: fcho.cpp プロジェクト: alhunor/projects
fcho_Cho * fcho_CreateSampleSize (double a, double b, double c,
                                  fcho_FuncType F, char *name)
{
   fcho_Cho *cho;
   Sample_Param *param;   
   size_t len;
   char *name0 = "n";

   cho = (fcho_Cho*)util_Malloc (sizeof (fcho_Cho));
   param = (Sample_Param*)util_Malloc (sizeof (Sample_Param));
   param->a = a;
   param->b = b;
   param->c = c;
   if (NULL == F)
      param->F = fcho_2Pow;
   else
      param->F = F;

   if (NULL == name)
      name = name0;
   len = strlen (name);
   cho->name = (char*)util_Calloc (len + 1, sizeof (char));
   strncpy (cho->name, name, (size_t) len);
   cho->param = param;
   cho->Write = WriteSample;
   cho->Choose = ChooseSample;
   param->name = cho->name;
   return cho;
}
コード例 #8
0
ファイル: gofw.c プロジェクト: cartazio/htestu
void gofw_IterPowRatioTests0 (double U[], long N, int k,
   lebool printval, lebool graph, FILE * f)
{
   int i;
   long j;
   double *UU;
   gofw_TestArray sVal, pVal;

   UU = (double *) util_Calloc (1 + (size_t) N, sizeof (double));
   printf ("\n");
   for (j = 1; j <= N; j++)
      UU[j] = U[j];
   for (i = 1; i <= k; i++) {
      gofs_PowerRatios (UU, N);
      printf ("-----------------------------------\n"
              "EDF Tests after \"gofw_PowerRatios\", level :%2d\n", i);
      tables_QuickSortD (UU, 1, N);
      gofw_ActiveTests0 (UU, N, sVal, pVal);
      gofw_WriteActiveTests0 (N, sVal, pVal);
      strncpy (desc, "Values of Uniforms after PowerRatios, level ",
               (size_t) LEN1);
      sprintf (str, "%2d", i);
      strncat (desc, str, (size_t) LEN2);
      if (printval > 0)
         tables_WriteTabD (UU, 1, N, 5, 15, 6, 6, desc);
      if (graph > 0)
         gofw_GraphDistUnif (f, UU, N, desc);
   }
   util_Free (UU);
}
コード例 #9
0
sspectral_Res * sspectral_CreateRes (void)
{
   sspectral_Res *res;
   res = util_Malloc (sizeof (sspectral_Res));
   res->Bas = sres_CreateBasic ();
   res->Coef = util_Calloc (1, sizeof (double));
   res->jmax = 0;
   return res;
}
コード例 #10
0
ファイル: sres.cpp プロジェクト: alhunor/projects
sres_Poisson * sres_CreatePoisson (void)
{
   sres_Poisson *res;
   res = (sres_Poisson*)util_Malloc (sizeof (sres_Poisson));
   memset (res, 0, sizeof (sres_Poisson));
   res->sVal1 = statcoll_Create (1, "");
   res->name = (char*)util_Calloc (1, sizeof (char));
   return res;
}
コード例 #11
0
ファイル: svaria.c プロジェクト: JamesHirschorn/TestU01-CMake
void svaria_SampleProd (unif01_Gen * gen, sres_Basic * res,
   long N, long n, int r, int t)
{
   long i;
   int j;
   long Seq;
   double *P;
   double temp;
   double Par[1];
   lebool localRes = FALSE;
   chrono_Chrono *Timer;
   char *TestName = "svaria_SampleProd test";

   Timer = chrono_Create ();
   if (swrite_Basic) {
      swrite_Head (gen, TestName, N, n, r);
      printf (",   t = %d\n\n", t);
   }

   if (res == NULL) {
      localRes = TRUE;
      res = sres_CreateBasic ();
   }
   sres_InitBasic (res, N, "svaria_SampleProd");

   P = util_Calloc ((size_t) n + 1, sizeof (double));
   statcoll_SetDesc (res->sVal1, "SampleProd sVal1:   Uniform [0, 1]");
   Par[0] = t;

   for (Seq = 1; Seq <= N; Seq++) {
      for (i = 1; i <= n; i++) {
         temp = unif01_StripD (gen, r);
         for (j = 2; j <= t; j++)
            temp *= unif01_StripD (gen, r);
         P[i] = temp;
      }
      gofw_ActiveTests1 (P, n, FDistProd, Par, res->sVal2, res->pVal2);
      statcoll_AddObs (res->sVal1, res->pVal2[gofw_AD]);
   }

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

   if (swrite_Collectors)
      statcoll_Write (res->sVal1, 5, 14, 4, 3);

   if (swrite_Basic) {
      gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2,
         "Anderson-Darling statistic            :");
      swrite_Final (gen, Timer);
   }
   util_Free (P);
   if (localRes)
      sres_DeleteBasic (res);
   chrono_Delete (Timer);
}
コード例 #12
0
ファイル: sres.cpp プロジェクト: alhunor/projects
sres_Disc * sres_CreateDisc (void)
{
   sres_Disc *res;
   res = (sres_Disc *)util_Malloc (sizeof (sres_Disc));
   memset (res, 0, sizeof (sres_Disc));
   res->sVal1 = statcoll_Create (1, "");
   res->name = (char*)util_Calloc (1, sizeof (char));
   return res;
}
コード例 #13
0
ファイル: sres.c プロジェクト: Marc-B-Reynolds/TestU01x
sres_Basic *sres_CreateBasic (void)
{
    sres_Basic *res;
    res = util_Malloc (sizeof (sres_Basic));
    memset (res, 0, sizeof (sres_Basic));
    res->sVal1 = statcoll_Create (1, "");
    res->pVal1 = statcoll_Create (1, "");
    res->name = util_Calloc (1, sizeof (char));
    return res;
}
コード例 #14
0
ファイル: sentrop.c プロジェクト: Marc-B-Reynolds/TestU01x
sentrop_Res * sentrop_CreateRes (void)
{
   sentrop_Res *res;
   res = util_Malloc (sizeof (sentrop_Res));
   memset (res, 0, sizeof (sentrop_Res));
   res->Bas = sres_CreateBasic ();
   res->Count = util_Calloc (1, sizeof (long));
   res->jmax = 0;
   res->jmin = 0;
   return res;
}
コード例 #15
0
ファイル: gofw.c プロジェクト: cartazio/htestu
void gofw_WriteKS1 (double V[], long N, wdist_CFUNC F, double par[])
{
   double *U;
   double D, DM, DP;

   U = (double *) util_Calloc ((size_t) N + 1, sizeof (double));
   gofs_ContUnifTransform (V, N, F, par, U);
   tables_QuickSortD (U, 1, N);
   gofs_KS (U, N, &DP, &DM, &D);
   gofw_WriteKS0 (N, DP, DM, D);
   util_Free (U);
}
コード例 #16
0
ファイル: gofw.c プロジェクト: cartazio/htestu
void gofw_ActiveTests1 (double V[], long N, wdist_CFUNC F, double par[],
                        gofw_TestArray sVal, gofw_TestArray pVal)
{
   double *U;
   util_Assert (N > 0, "gofw_ActiveTests1:   N <= 0");
   U = (double *) util_Calloc ((size_t) N + 1, sizeof (double));
   gofs_ContUnifTransform (V, N, F, par, U);
   tables_QuickSortD (U, 1, N);
   gofw_ActiveTests0 (U, N, sVal, pVal);
   if (N == 1)
      sVal[gofw_Mean] = V[1];
   util_Free (U);
}
コード例 #17
0
ファイル: gofw.c プロジェクト: cartazio/htestu
void gofw_WriteKSJumpOne1 (double V[], long N, wdist_CFUNC F, double par[],
                           double a)
{
   double *U;
   double DP, DM;

   U = (double *)util_Calloc ((size_t) N + 1, sizeof (double));
   gofs_ContUnifTransform (V, N, F, par, U);
   tables_QuickSortD (U, 1, N);
   gofs_KSJumpOne (U, N, a, &DP, &DM);
   gofw_WriteKSJumpOne0 (N, a, DP);
   util_Free (U);
}
コード例 #18
0
ファイル: utaus.c プロジェクト: JamesHirschorn/TestU01-CMake
unif01_Gen * utaus_CreateLongTaus (unsigned int k, unsigned int q,
                                   unsigned int s, ulonglong Y)
{
   unif01_Gen *gen;
   LongTaus_param *param;
   LongTaus_state *state;
   size_t len;
   char name[LEN0 + 1];
   ulonglong B;

   util_Assert ((k <= 64) && (k > 2 * q) && (s <= k - q) && (s >= 1) &&
      (q >= 1), "utaus_CreateLongTaus:   Invalid Parameter");

   gen   = util_Malloc (sizeof (unif01_Gen));
   param = util_Malloc (sizeof (LongTaus_param));
   state = util_Malloc (sizeof (LongTaus_state));

   strncpy (name, "utaus_CreateLongTaus", (size_t) LEN0);
   addstr_Uint (name, ":   k = ", k);
   addstr_Uint (name, ",  q = ", q);
   addstr_Uint (name, ",  s = ", s);
   addstr_ULONG (name, ",  Y = ", Y);
   len = strlen (name);
   gen->name = util_Calloc (len + 1, sizeof (char));
   strncpy (gen->name, name, len);

   param->Q1 = q;
   param->K1mS1 = k - s;
   param->S1 = s;
   B = num_TwoExp[64 - k] - 1.0;        /* k most signif. bits at 1 */
   param->M1 = ~B;

   util_Assert (Y > 0, "utaus_CreateLongTaus:   Y = 0");
   state->ST1 = Y & param->M1;

   /* make sure that the initial state is not 0 */
   while (state->ST1 == 0) {
      Y *= 2;
      state->ST1 = Y & param->M1;
   }
   B = ((state->ST1 << param->Q1) ^ state->ST1) >> k;
   state->ST1 ^= B;

   gen->GetBits = &LongTaus_Bits;
   gen->GetU01  = &LongTaus_U01;
   gen->Write   = &WrLongTaus;
   gen->param   = param;
   gen->state   = state;
   return gen;
}
コード例 #19
0
ファイル: ftab.c プロジェクト: JamesHirschorn/TestU01-CMake
ftab_Table *ftab_CreateTable (int Nr, int j1, int j2, int jstep,
   char *Desc, ftab_FormType Form, int Ns)
{
   ftab_Table *T;
   T = util_Malloc (sizeof (ftab_Table));
   memset (T, 0, sizeof (ftab_Table));
   T->Nr = Nr;
   T->j1 = j1;
   T->j2 = j2;
   T->jstep = jstep;
   T->Nc = 1 + (j2 - j1)/jstep;
   T->Mat = tables_CreateMatrixD (T->Nr, T->Nc);
   T->LSize = util_Calloc ((size_t) T->Nr, sizeof (int));
   T->Desc = NULL;
   ftab_SetDesc (T, Desc);
   T->Form = Form;
   if (Form == ftab_String) {
      T->Strings = util_Calloc ((size_t) Ns, sizeof (char *));
      T->Ns = Ns;
   } else
      T->Strings = NULL;
   return T;
}
コード例 #20
0
ファイル: sres.c プロジェクト: Marc-B-Reynolds/TestU01x
void sres_InitChi2 (sres_Chi2 *res, long N, long jmax, char *nam)
{
    statcoll_Init (res->sVal1, N);
    statcoll_Init (res->pVal1, N);

    if (jmax < 0) {
        if (res->jmax > 0) {
            res->NbExp = util_Free (res->NbExp);
            res->Count = util_Free (res->Count);
            res->Loc = util_Free (res->Loc);
        }
    } else {
        if (res->jmax < 0) {
            res->NbExp = util_Calloc ((size_t) (jmax + 1), sizeof (double));
            res->Count = util_Calloc ((size_t) (jmax + 1), sizeof (long));
            res->Loc = util_Calloc ((size_t) (jmax + 1), sizeof (long));
        } else {
            int j;
            res->NbExp =
                util_Realloc (res->NbExp, (jmax + 1) * sizeof (double));
            res->Count = util_Realloc (res->Count, (jmax + 1) * sizeof (long));
            res->Loc = util_Realloc (res->Loc, (jmax + 1) * sizeof (long));
            for (j = 0; j <= jmax; j++) {
                res->NbExp[j] = 0.0;
                res->Count[j] = 0;
                res->Loc[j] = 0;
            }
        }
    }
    res->degFree = 0;
    res->jmin = 0;
    res->jmax = jmax;
    gofw_InitTestArray (res->sVal2, -1.0);
    gofw_InitTestArray (res->pVal2, -1.0);
    res->name = util_Realloc (res->name, 1 + strlen (nam) * sizeof (char));
    strcpy (res->name, nam);
}
コード例 #21
0
unif01_Gen * uautomata_CreateCA90mp (int m, int S[])
{
   unif01_Gen *gen;
   CA90mp_state *state;
   size_t leng;
   char name[LEN + 1];
   int i;

   gen = util_Malloc (sizeof (unif01_Gen));
   state = util_Malloc (sizeof (CA90mp_state));

   strncpy (name, "uautomata_CreateCA90mp:", (size_t) LEN);
   addstr_Long (name, "   m = ", (long) m);
   addstr_ArrayInt (name, ",   S = ",  m, S);
   leng = strlen (name);
   gen->name = util_Calloc (leng + 1, sizeof (char));
   strncpy (gen->name, name, (size_t) leng);

   state->Cell = util_Calloc ((size_t) m + 2, sizeof (int));
   state->OldCell = util_Calloc ((size_t) m + 2, sizeof (int));
   state->m = m;

   for (i = 1; i <= m; i++) {
      util_Assert (S[i] == 0 || S[i] == 1,
        "uautomata_CreateCA90mp:   all S[i] must be in { 0, 1 }.");
      state->Cell[i] = S[i];
   }
   /* Null boundary condition */
   state->Cell[0] = 0;
   state->OldCell[0] = 0;
   gen->GetBits = &CA90mp_Bits;
   gen->GetU01  = &CA90mp_U01;
   gen->Write   = &WrCA90mp;
   gen->state   = state;
   gen->param   = NULL;
   return gen;
}
コード例 #22
0
ファイル: sres.cpp プロジェクト: alhunor/projects
sres_Chi2 *sres_CreateChi2 (void)
{
   sres_Chi2 *res;
   res = (sres_Chi2 *)util_Malloc (sizeof (sres_Chi2));
   memset (res, 0, sizeof (sres_Chi2));
   res->sVal1 = statcoll_Create (1, "");
   res->pVal1 = statcoll_Create (1, "");
   res->name = (char*)util_Calloc (1, sizeof (char));
   res->jmin = 0;
   res->jmax = -1;
   res->NbExp = NULL;
   res->Count = NULL;
   res->Loc = NULL;
   return res;
}
コード例 #23
0
ファイル: ftab.c プロジェクト: JamesHirschorn/TestU01-CMake
void ftab_SetDesc (ftab_Table *T, char *Desc)
{
   size_t len;
   util_Assert (T != NULL, "ftab_SetDesc:  ftab_Table is a NULL pointer");
   len = strlen (Desc);
   if (len > MAXLEN) {
      len = MAXLEN;
      util_Warning (1, "ftab_Table->Desc truncated");
   }
   if (T->Desc != NULL)
      T->Desc = util_Free (T->Desc);
   T->Desc = util_Calloc (len + 1, sizeof (char));
   strncpy (T->Desc, Desc, (size_t) len);
   T->Desc[len] = '\0';
}
コード例 #24
0
ファイル: CombGenAPRNG.c プロジェクト: jirka-h/aprng
unif01_Gen* CreateCombGenAPRNGFill (APRNG_t *A, unif01_Gen **g, size_t size, unsigned int fill_frequency, char *mess, char *name)
{
    unif01_Gen *gen;
    unif01_Comb_APRNG_fill_t *paramC;
    size_t len, L, i;

    gen = util_Malloc (sizeof (unif01_Gen));
    paramC = util_Malloc (sizeof (unif01_Comb_APRNG_fill_t));
    paramC->size = size;;
    paramC->g = g;
    paramC->A = A;
    paramC->fill_frequency = fill_frequency;
    paramC->n_after_fill = 0;

    len = strlen (A->name) + strlen (name) + strlen (mess);
    for (i=0; i<size; ++i) {
        len += strlen (g[i]->name);
    }
    len += 3 + size;
    gen->name = util_Calloc (len + 1, sizeof (char));
    L = strlen (mess);
    if (L > 0) {
        strncpy (gen->name, mess, len);
        if (mess[L - 1] != ':')
            strncat (gen->name, ":", 3);
        strncat (gen->name, "\n", 3);
    }
    strncat (gen->name, A->name, len);
    strncat (gen->name, "\n", 3);
    for (i=0; i<size; ++i) {
        strncat (gen->name, g[i]->name, len);
        strncat (gen->name, "\n", 3);
    }
    strncat (gen->name, name, len);

    gen->param  = NULL;
    gen->state  = paramC;
    gen->Write  = WrCombGenAPRNGFill;
    gen->GetU01 = GetU01CombGenAPRNGFill;
    gen->GetBits =GetBitsCombGenAPRNGFill;
    return gen;
}
コード例 #25
0
ファイル: unumrec.c プロジェクト: Marc-B-Reynolds/TestU01x
unif01_Gen * unumrec_CreateRan2 (long s)
{
   unif01_Gen *gen;
   Ran0_param *param;
   Ran2_state *state;
   size_t leng;
   char name[LEN + 1];
   int i;
   long k;

   util_Assert (s > 0, "unumrec_CreateRan2:   s <= 0");
   gen = util_Malloc (sizeof (unif01_Gen));
   param = util_Malloc (sizeof (Ran0_param));
   state = util_Malloc (sizeof (Ran2_state));

   strncpy (name, "unumrec_CreateRan2:", LEN);
   addstr_Long (name, "   s = ", s);
   leng = strlen (name);
   gen->name = util_Calloc (leng + 1, sizeof (char));
   strncpy (gen->name, name, leng);

   param->Norm = 1.0 / M1;
   state->S1 = s;
   state->S2 = s;

   for (i = N_TAB8; i >= 1; i--) {
      k = state->S1 / q1;
      state->S1 = A1 * (state->S1 - k * q1) - k * r1;
      if (state->S1 < 0)
         state->S1 += M1;
      if (i <= N_TAB)
         state->Tab[i] = state->S1;
   }
   state->z = state->Tab[1];

   gen->GetBits = &Ran2_Bits;
   gen->GetU01  = &Ran2_U01;
   gen->Write   = &WrRan2;
   gen->param   = param;
   gen->state   = state;
   return gen;
}
コード例 #26
0
ファイル: ftab.c プロジェクト: JamesHirschorn/TestU01-CMake
static void PrintTexName (char *nam)
/*
 * Make sure that any _ char in Latex format name is printed as \_
 */
{
   char *p, *name = nam;
   size_t len;

   if (NULL == nam)
      return;
   len = strlen (name) + 1;
   name = util_Calloc (len, sizeof (char));
   strncpy (name, nam, (size_t) len);

   while ((p = strchr(name, '_'))) {
      *p = '\0';
      printf ("%s", name);
      printf ("\\_");
      name = p + 1;
   }
   printf ("%s", name);
}
コード例 #27
0
ファイル: gofw.c プロジェクト: cartazio/htestu
void gofw_KSJumpsMany2 (statcoll_Collector *S, fdist_FUNC_JUMPS *H,
                        int Detail)
{
   double DM, DP;
   double *X;
   wdist_CFUNC F = H->F;
   double *W = H->par;

   /* The implementation of fdist_KSPlusJumpsMany and fdist_KSMinusJumpsMany
      works only for NObs <= 64: instability for larger NObs.  */
   if (S->NObs > 64) {
      printf ("\nKolmogorov-Smirnov, sample too large\n\n\n"
	      "------------------------------------------\n");
      return;
   }

   X = (double *) util_Calloc (1 + (size_t) S->NObs, sizeof (double));
   tables_CopyTabD (S->St, X, 1, S->NObs);
   tables_QuickSortD (X, 1, S->NObs);
   statcalc_KSJumpsMany (X, S->NObs, F, W, &DP, &DM, Detail);
   gofw_KSJumpsMany0 (DP, DM, H);
   util_Free (X);
   printf ("\n");
}
コード例 #28
0
ファイル: uweyl.c プロジェクト: JamesHirschorn/TestU01-CMake
static unif01_Gen *CreateWeyl_0 (double Alpha, long n0, char name[])
{
   unif01_Gen *gen;
   Weyl_param *param;
   Weyl_state *state;
   size_t leng;

   gen = util_Malloc (sizeof (unif01_Gen));
   param = util_Malloc (sizeof (Weyl_param));
   state = util_Malloc (sizeof (Weyl_state));
   param->Alpha = Alpha;
   state->n = n0;

   addstr_Double (name, "  Alpha = ", Alpha);
   addstr_Long (name, ",   n0 = ", n0);
   leng = strlen (name);
   gen->name = util_Calloc (leng + 1, sizeof (char));
   strncpy (gen->name, name, leng);

   gen->Write = &WrWeyl;
   gen->param = param;
   gen->state = state;
   return gen;
}
コード例 #29
0
ファイル: sknuth.c プロジェクト: Marc-B-Reynolds/TestU01x
void sknuth_MaxOft (unif01_Gen * gen, sknuth_Res1 * res,
   long N, long n, int r, int d, int t)
{
   long Seq;                      /* Replication number */
   double tReal = t;
   double dReal = d;
   double NbExp;                  /* Expected number in each class */
   double MaxU;
   double U;
   long Groupe;
   int j, Indice;
   double *P;
   double Par[1];
   double X2;
   double V[1];                   /* Number degrees of freedom for Chi2 */
   char str[LENGTH + 1];
   lebool localRes = FALSE;
   chrono_Chrono *Timer;
   char *TestName = "sknuth_MaxOft test";
   sres_Basic *Bas;
   sres_Chi2 *Chi;

   Timer = chrono_Create ();
   Par[0] = t;

   NbExp = n / dReal;
   if (swrite_Basic)
      WriteDataMaxOft (gen, TestName, N, n, r, d, t, NbExp);
   util_Assert (NbExp >= gofs_MinExpected,
      "MaxOft:   NbExp < gofs_MinExpected");
   if (res == NULL) {
      localRes = TRUE;
      res = sknuth_CreateRes1 ();
   }
   InitRes1 (res, N, d);
   Bas = res->Bas;
   Chi = res->Chi;
   Chi->jmin = 0;
   Chi->jmax = d - 1;
   for (j = 0; j < d; j++) {
      Chi->Loc[j] = j;
      Chi->NbExp[j] = NbExp;
   }

   sprintf (str, "The N statistic values (a ChiSquare with %1d degrees"
                 " of freedom):", d - 1);
   statcoll_SetDesc (Chi->sVal1, str);
   Chi->degFree = d - 1;
   statcoll_SetDesc (Bas->sVal1,
      "The N statistic values (the Anderson-Darling p-values):");
   P = util_Calloc ((size_t) n + 1, sizeof (double));

   for (Seq = 1; Seq <= N; Seq++) {
      for (Indice = 0; Indice < d; Indice++)
         Chi->Count[Indice] = 0;
      for (Groupe = 1; Groupe <= n; Groupe++) {
         /* Generate a vector and find the max value */
         MaxU = unif01_StripD (gen, r);
         for (j = 1; j < t; j++) {
            U = unif01_StripD (gen, r);
            if (U > MaxU)
               MaxU = U;
         }
         /* For the chi2 */
         Indice = pow (MaxU, tReal) * dReal;
         ++Chi->Count[Indice];

         /* For the Anderson-Darling */
         P[Groupe] = MaxU;
      }
      if (swrite_Counters)
         tables_WriteTabL (Chi->Count, 0, d - 1, 5, 10, "Observed numbers:");

      /* Value of the chi2 statistic */
      X2 = gofs_Chi2Equal (NbExp, Chi->Count, 0, d - 1);
      statcoll_AddObs (Chi->sVal1, X2);

      /* Value of the Anderson-Darling statistic */
      gofw_ActiveTests1 (P, n, FDistMax, Par, Bas->sVal2, Bas->pVal2);
      statcoll_AddObs (Bas->sVal1, Bas->pVal2[gofw_AD]);
   }
   util_Free (P);

   V[0] = d - 1;
   gofw_ActiveTests2 (Chi->sVal1->V, Chi->pVal1->V, N, wdist_ChiSquare, V,
      Chi->sVal2, Chi->pVal2);
   Chi->pVal1->NObs = N;
   sres_GetChi2SumStat (Chi);

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

   if (swrite_Collectors) {
      statcoll_Write (Chi->sVal1, 5, 14, 4, 3);
      statcoll_Write (Bas->sVal1, 5, 14, 4, 3);
   }
   if (swrite_Basic) {
      if (N == 1) {
         swrite_AddStrChi (str, LENGTH, Chi->degFree);
         gofw_WriteActiveTests2 (N, Chi->sVal2, Chi->pVal2, str);
      } else {
         printf ("\n-----------------------------------------------\n");
         printf ("Test results for chi2 with %2ld degrees of freedom:\n",
                 Chi->degFree);
         gofw_WriteActiveTests0 (N, Chi->sVal2, Chi->pVal2);
         swrite_Chi2SumTest (N, Chi);
      }

      if (N == 1) {
         gofw_WriteActiveTests2 (N, Bas->sVal2, Bas->pVal2,
            "Anderson-Darling statistic            :");
      } else {
         printf ("\n-----------------------------------------------\n");
         printf ("Test results for Anderson-Darling:\n");
         gofw_WriteActiveTests0 (N, Bas->sVal2, Bas->pVal2);
      }
      printf ("\n");
      swrite_Final (gen, Timer);
   }
   if (localRes)
      sknuth_DeleteRes1 (res);
   chrono_Delete (Timer);
}
コード例 #30
0
ファイル: svaria.c プロジェクト: JamesHirschorn/TestU01-CMake
static int svaria_CollisionArgMax_00 (unif01_Gen *gen, sres_Chi2 *res,
   long N, long n, int r, long k, long m)
/*
 * Return 0 if no error, otherwise return != 0.
 */
{
   double X;
   double U;
   double Max;
   long NbColl;
   long Indice = -1;
   long j;
   long i;
   long Rep;
   long Seq;
   long NbClasses;
   long *Loc;
   int *Urne;
   double V[1];
   fmass_INFO Q;
   lebool localRes = FALSE;
   chrono_Chrono *chro, *Timer;
   char *TestName = "svaria_CollisionArgMax test";
   char chaine[LEN1 + 1] = "";
   char str[LEN2 + 1];

   Timer = chrono_Create ();
   if (swrite_Basic)
      WriteDataArgMax (gen, TestName, N, n, r, k, m);

   util_Assert (n <= 4 * k, "svaria_CollisionArgMax:   n > 4k");
   /*   util_Assert (m > 2.0 * gofs_MinExpected,
	"svaria_CollisionArgMax:    m <= 2*gofs_MinExpected"); */

   if (res == NULL) {
      localRes = TRUE;
      res = sres_CreateChi2 ();
   }
   sres_InitChi2 (res, N, n, "svaria_CollisionArgMax");
   Loc = res->Loc;
   Urne = util_Calloc ((size_t) k + 1, sizeof (int));

   if (svaria_Timer) {
      printf ("-----------------------------------------------");
      printf ("\nCPU time to initialize the collision distribution:  ");
      chro = chrono_Create ();
   }
   Q = smultin_CreateCollisions (n, (smultin_CellType) k);
   if (svaria_Timer) {
      chrono_Write (chro, chrono_hms);
      printf ("\n\n");
   }

   /* Compute the expected numbers of collisions: m*P(j) */
   for (j = 0; j <= n; j++)
      res->NbExp[j] = m * smultin_CollisionsTerm (Q, j);
   smultin_DeleteCollisions (Q);

   res->jmin = 0;
   res->jmax = n;
   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, "CollisionArgMax 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 1;
   }

   if (svaria_Timer)
      chrono_Init (chro);

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

      for (Rep = 1; Rep <= m; Rep++) {
         for (j = 0; j <= k; j++)
            Urne[j] = -1;

         NbColl = 0;
         for (j = 1; j <= n; j++) {
            Max = -1.0;
            for (i = 1; i <= k; i++) {
               U = unif01_StripD (gen, r);
               if (U > Max) {
                  Max = U;
                  Indice = i;
               }
            }
            if (Urne[Indice] < 0)
               Urne[Indice] = 1;
            else
               ++NbColl;
         }
         if (NbColl > res->jmax)
            ++res->Count[res->jmax];
         else
            ++res->Count[Loc[NbColl]];
      }
      if (swrite_Counters)
         tables_WriteTabL (res->Count, res->jmin, res->jmax, 5, 10,
                           "Observed numbers:");
      X = gofs_Chi2 (res->NbExp, res->Count, res->jmin, res->jmax);
      statcoll_AddObs (res->sVal1, X);
   }

   if (svaria_Timer) {
      printf ("\n----------------------------------------------\n"
              "CPU time for the test           :  ");
      chrono_Write (chro, chrono_hms);
      printf ("\n\n");
      chrono_Delete (chro);
   }

   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);
   }
   util_Free (Urne);
   if (localRes)
      sres_DeleteChi2 (res);
   chrono_Delete (Timer);
   return 0;
}