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); }
void fcho_DeleteSampleSize (fcho_Cho *cho) { if (NULL == cho) return; cho->name = (char*)util_Free (cho->name); cho->param = util_Free (cho->param); util_Free (cho); }
void sspectral_DeleteRes (sspectral_Res *res) { if (res == NULL) return; sres_DeleteBasic (res->Bas); util_Free (res->Coef); util_Free (res); }
void sentrop_DeleteRes (sentrop_Res *res) { if (res == NULL) return; sres_DeleteBasic (res->Bas); util_Free (res->Count); util_Free (res); }
void sres_DeletePoisson (sres_Poisson *res) { if (res == NULL) return; statcoll_Delete (res->sVal1); util_Free (res->name); util_Free (res); }
void sres_DeleteDisc (sres_Disc *res) { if (res == NULL) return; statcoll_Delete (res->sVal1); util_Free (res->name); util_Free (res); }
void sres_DeleteBasic (sres_Basic * res) { if (res == NULL) return; statcoll_Delete (res->sVal1); statcoll_Delete (res->pVal1); util_Free (res->name); util_Free (res); }
void ffam_DeleteFam (ffam_Fam *fam) { if (fam == NULL) return; util_Free (fam->Resol); util_Free (fam->Gen); util_Free (fam->LSize); util_Free (fam->name); util_Free (fam); }
void ftab_DeleteTable (ftab_Table * T) { if (T == NULL) return; tables_DeleteMatrixD (&T->Mat); T->LSize = util_Free (T->LSize); T->Desc = util_Free (T->Desc); if (T->Form == ftab_String) T->Strings = util_Free (T->Strings); util_Free (T); }
void sres_DeleteChi2 (sres_Chi2 * res) { if (res == NULL) return; statcoll_Delete (res->sVal1); statcoll_Delete (res->pVal1); util_Free (res->NbExp); util_Free (res->Count); util_Free (res->Loc); util_Free (res->name); util_Free (res); }
void uautomata_DeleteCA90mp (unif01_Gen *gen) { CA90mp_state *state; if (NULL == gen) return; state = gen->state; util_Free (state->Cell); util_Free (state->OldCell); gen->state = util_Free (gen->state); gen->name = util_Free (gen->name); util_Free (gen); }
void udeng_DeleteGen (unif01_Gen * gen) { DX02_state *state; if (NULL == gen) return; state = gen->state; util_Free (state->X); gen->state = util_Free (gen->state); gen->param = util_Free (gen->param); gen->name = util_Free (gen->name); util_Free (gen); }
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); }
void sknuth_DeleteRes1 (sknuth_Res1 *res) { if (res != NULL) { sres_DeleteBasic(res->Bas); sres_DeleteChi2(res->Chi); util_Free(res); } }
void sknuth_DeleteRes2 (sknuth_Res2 *res) { if (res == NULL) return; sres_DeleteBasic (res->Bas); sres_DeletePoisson (res->Pois); util_Free (res); }
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); }
void fwalk_DeleteRes1 (fwalk_Res1 * res) { if (res == NULL) return; fres_DeleteCont (res->H); fres_DeleteCont (res->M); fres_DeleteCont (res->J); fres_DeleteCont (res->R); fres_DeleteCont (res->C); util_Free (res); }
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); }
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); }
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); }
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); }
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'; }
void uautomata_DeleteGen (unif01_Gen *gen) { CA1_state *state; if (NULL == gen) return; state = gen->state; util_Free (state->Cell); util_Free (state->OldCell); util_Free (state->Rand); gen->state = util_Free (gen->state); gen->param = util_Free (gen->param); gen->name = util_Free (gen->name); util_Free (gen); }
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"); }
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); }
void sentrop_EntropyDMCirc (unif01_Gen * gen, sres_Basic * res, long N, long n, int r, long m) { long i; /* Index */ double I0, x; long Seq; /* Replication number */ double Entropy; /* Value of the statistic H(m, n) */ double LnEntropy; double SumR; /* 1 + 1/2 + ... + 1/(2m-1) */ double nLR = n; double Twom; /* 2m */ double *AU; lebool localRes = FALSE; chrono_Chrono *Timer; char *TestName = "sentrop_EntropyDMCirc test"; Timer = chrono_Create (); if (swrite_Basic) WriteDataDM (gen, TestName, N, n, r, m); Twom = 2 * m; I0 = Twom - 1.0; SumR = 0.0; for (i = 2 * m - 1; i >= 1; i--) { SumR += 1.0 / I0; I0 -= 1.0; } if (res == NULL) { localRes = TRUE; res = sres_CreateBasic (); } sres_InitBasic (res, N, "sentrop_EntropyDMCirc"); AU = util_Calloc ((size_t) (n + 1), sizeof (double)); statcoll_SetDesc (res->sVal1, "The N statistic values (a standard normal)"); for (Seq = 1; Seq <= N; Seq++) { /* Generate the sample and sort */ for (i = 1; i <= n; i++) AU[i] = unif01_StripD (gen, r); tables_QuickSortD (AU, 1, n); /* Compute empirical entropy */ Entropy = 1.0; LnEntropy = 0.0; for (i = 1; i <= n; i++) { if (i - m < 1) { Entropy *= (AU[i + m] - AU[n + i - m] + 1.0); } else if (i + m > n) { Entropy *= (AU[i + m - n] - AU[i - m] + 1.0); } else Entropy *= (AU[i + m] - AU[i - m]); if (Entropy < Epsilon) { LnEntropy += log (Entropy); Entropy = 1.0; } } Entropy = (LnEntropy + log (Entropy)) / nLR + log (nLR / Twom); /* Compute standardized statistic */ x = sqrt (3.0 * Twom * nLR) * ((Entropy + log (Twom) + Euler) - SumR); statcoll_AddObs (res->sVal1, x); } gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_Normal, (double *) NULL, res->sVal2, res->pVal2); res->pVal1->NObs = N; sres_GetNormalSumStat (res); if (swrite_Collectors) statcoll_Write (res->sVal1, 5, 14, 4, 3); if (swrite_Basic) { gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, "Normal statistic :"); swrite_NormalSumTest (N, res); swrite_Final (gen, Timer); } util_Free (AU); if (localRes) sres_DeleteBasic (res); chrono_Delete (Timer); }
void fcho_DeleteCho2 (fcho_Cho2 *cho) { if (NULL == cho) return; util_Free (cho); }
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; }
void svaria_AppearanceSpacings (unif01_Gen * gen, sres_Basic * res, long N, long Q, long K, int r, int s, int L) { double E[AS_DIM + 1]; /* Theoretical mean of the log (Base2) of the most recent occurrence of a block */ double KV[AS_DIM + 1]; /* K times the theoretical variance of the same */ long Seq; long block; long Nblocks; /* 2^L = total number of distinct blocks */ long K2; long Q2; long i; long sBits; /* Numerical value of the s given bits */ long d; /* 2^s */ const int SdivL = s / L; const int LdivS = L / s; const int LmodS = L % s; long sd; /* 2^LmodS */ long rang; double n; /* Total number of bits in a sequence */ double sigma; /* Standard deviation = sqrt (Variance) */ double somme; double ARang; /* Most recent occurrence of block */ long *Count; /* Index of most recent occurrence of block */ double FactMoy; lebool localRes = FALSE; chrono_Chrono *Timer; Timer = chrono_Create (); n = ((double) K + (double) Q) * L; if (swrite_Basic) WriteDataAppear (gen, N, r, s, L, Q, K, n); util_Assert (s < 32, "svaria_AppearanceSpacings: s >= 32"); InitAppear (r, s, L, Q, E, KV); sigma = CalcSigma (L, K, KV); d = num_TwoExp[s]; Nblocks = num_TwoExp[L]; FactMoy = 1.0 / (num_Ln2 * K); if (res == NULL) { localRes = TRUE; res = sres_CreateBasic (); } sres_InitBasic (res, N, "svaria_AppearanceSpacings"); Count = util_Calloc ((size_t) Nblocks + 2, sizeof (long)); statcoll_SetDesc (res->sVal1, "AppearanceSpacings sVal1: standard normal"); if (LdivS > 0) { sd = num_TwoExp[LmodS]; for (Seq = 1; Seq <= N; Seq++) { for (i = 0; i < Nblocks; i++) Count[i] = 0; /* Initialization with Q blocks */ for (rang = 0; rang < Q; rang++) { block = 0; for (i = 1; i <= LdivS; i++) { sBits = unif01_StripB (gen, r, s); block = block * d + sBits; } if (LmodS > 0) { sBits = unif01_StripB (gen, r, LmodS); block = block * sd + sBits; } Count[block] = rang; } /* Test proper with K blocks */ somme = 0.0; for (rang = Q; rang < Q + K; rang++) { block = 0; for (i = 1; i <= LdivS; i++) { sBits = unif01_StripB (gen, r, s); block = block * d + sBits; } if (LmodS > 0) { sBits = unif01_StripB (gen, r, LmodS); block = block * sd + sBits; } ARang = rang - Count[block]; somme += log (ARang); Count[block] = rang; } statcoll_AddObs (res->sVal1, (somme * FactMoy - E[L]) / sigma); } } else { /* s > L */ Q2 = Q / SdivL; K2 = K / SdivL; for (Seq = 1; Seq <= N; Seq++) { for (i = 0; i < Nblocks; i++) Count[i] = 0; /* Initialization: Q blocks */ for (rang = 0; rang < Q2; rang++) { sBits = unif01_StripB (gen, r, s); for (i = 0; i < SdivL; i++) { block = sBits % Nblocks; Count[block] = SdivL * rang + i; sBits /= Nblocks; } } /* Test proper with K blocks */ somme = 0.0; for (rang = Q2; rang < Q2 + K2; rang++) { sBits = unif01_StripB (gen, r, s); for (i = 0; i < SdivL; i++) { block = sBits % Nblocks; ARang = SdivL * rang + i - Count[block]; somme += log (ARang); Count[block] = SdivL * rang + i; sBits /= Nblocks; } } statcoll_AddObs (res->sVal1, (somme * FactMoy - E[L]) / sigma); } } gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_Normal, (double *) NULL, res->sVal2, res->pVal2); res->pVal1->NObs = N; sres_GetNormalSumStat (res); if (swrite_Collectors) statcoll_Write (res->sVal1, 5, 12, 4, 3); if (swrite_Basic) { gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, "Normal statistic :"); swrite_NormalSumTest (N, res); swrite_Final (gen, Timer); } util_Free (Count); if (localRes) sres_DeleteBasic (res); chrono_Delete (Timer); }
void svaria_SampleCorr (unif01_Gen * gen, sres_Basic * res, long N, long n, int r, int k) { long i; long Seq; double U; double Sum; double *Pre; /* Previous k generated numbers */ int pos; /* Circular index to element at lag k */ lebool localRes = FALSE; chrono_Chrono *Timer; char *TestName = "svaria_SampleCorr test"; Timer = chrono_Create (); if (swrite_Basic) { swrite_Head (gen, TestName, N, n, r); printf (", k = %d\n\n", k); } util_Assert (n > 2, "svaria_SampleCorr: n <= 2"); if (res == NULL) { localRes = TRUE; res = sres_CreateBasic (); } sres_InitBasic (res, N, "svaria_SampleCorr"); statcoll_SetDesc (res->sVal1, "SampleCorr sVal1: asymptotic standard normal"); Pre = util_Calloc ((size_t) (k + 1), sizeof (double)); for (Seq = 1; Seq <= N; Seq++) { /* Generate first k numbers U and keep them in Pre */ for (i = 0; i < k; i++) Pre[i] = unif01_StripD (gen, r); Sum = 0.0; pos = 0; /* Element Pre[pos] is at lag k from U */ for (i = k; i < n; i++) { U = unif01_StripD (gen, r); Sum += Pre[pos] * U - 0.25; Pre[pos] = U; pos++; pos %= k; } /* Save standardized correlation */ statcoll_AddObs (res->sVal1, Sum * sqrt (12.0 / (n - k))); } gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_Normal, (double *) NULL, res->sVal2, res->pVal2); res->pVal1->NObs = N; sres_GetNormalSumStat (res); if (swrite_Collectors) statcoll_Write (res->sVal1, 5, 14, 4, 3); if (swrite_Basic) { gofw_WriteActiveTests2 (N, res->sVal2, res->pVal2, "Normal statistic :"); swrite_NormalSumTest (N, res); swrite_Final (gen, Timer); } util_Free (Pre); if (localRes) sres_DeleteBasic (res); chrono_Delete (Timer); }