void tables_QuickSortD (double T[], int l, int r) /* On trie le tableau des observations T[l..r]. */ { int j; /* Indices dans le tableau Tab. */ int i; double w; double x; i = l; j = r; x = T[(l + r) / 2]; do { while (T[i] < x) ++i; while (x < T[j]) --j; if (i <= j) { w = T[i]; T[i] = T[j]; T[j] = w; ++i; --j; } } while (i <= j); if (l < j) tables_QuickSortD (T, l, j); if (i < r) tables_QuickSortD (T, i, r); }
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 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 gofw_ActiveTests2 (double V[], double U[], long N, wdist_CFUNC F, double par[], gofw_TestArray sVal, gofw_TestArray pVal) { util_Assert (N > 0, "gofw_ActiveTests1: N <= 0"); tables_QuickSortD (V, 1, N); gofs_ContUnifTransform (V, N, F, par, U); gofw_ActiveTests0 (U, N, sVal, pVal); if (N == 1) sVal[gofw_Mean] = V[1]; }
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_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 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_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 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); }