void sknuth_DeleteRes2 (sknuth_Res2 *res) { if (res == NULL) return; sres_DeleteBasic (res->Bas); sres_DeletePoisson (res->Pois); util_Free (res); }
void sknuth_DeleteRes1 (sknuth_Res1 *res) { if (res != NULL) { sres_DeleteBasic(res->Bas); sres_DeleteChi2(res->Chi); util_Free(res); } }
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 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 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); }
void svaria_SampleMean (unif01_Gen * gen, sres_Basic * res, long N, long n, int r) { long i; long Seq; double Sum; double Coef[SAM_LIM + 1]; lebool localRes = FALSE; chrono_Chrono *Timer; char *TestName = "svaria_SampleMean test"; Timer = chrono_Create (); if (swrite_Basic) { swrite_Head (gen, TestName, N, n, r); printf ("\n\n"); } util_Assert (n > 1, "svaria_SampleMean: n < 2"); if (res == NULL) { localRes = TRUE; res = sres_CreateBasic (); } sres_InitBasic (res, N, "svaria_SampleMean"); if (n < SAM_LIM) InitFDistMeans (n, Coef); if (n < SAM_LIM) statcoll_SetDesc (res->sVal1, "SampleMean sVal1: n*<U>"); else statcoll_SetDesc (res->sVal1, "SampleMean sVal1: standard normal"); for (Seq = 1; Seq <= N; Seq++) { Sum = 0.0; for (i = 1; i <= n; i++) Sum += unif01_StripD (gen, r); if (n < SAM_LIM) statcoll_AddObs (res->sVal1, Sum); else statcoll_AddObs (res->sVal1, sqrt (12.0 / n) * (Sum - 0.5 * n)); } if (n < SAM_LIM) { gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, FDistMeans, Coef, res->sVal2, res->pVal2); } else { /* Normal approximation */ gofw_ActiveTests2 (res->sVal1->V, res->pVal1->V, N, wdist_Normal, (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, "Statistic value :"); swrite_Final (gen, Timer); } if (localRes) sres_DeleteBasic (res); chrono_Delete (Timer); }
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 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); }