ex-1: compute exact median

The approximation of the running statistics isn't accurate enough.
This commit is contained in:
Michele Guerini Rocco 2020-06-13 08:39:17 +00:00
parent e02e4a9557
commit 602e08b2a2

View File

@ -179,6 +179,7 @@ uncert bootstrap_median(
gsl_rstat_workspace* w = gsl_rstat_alloc(); gsl_rstat_workspace* w = gsl_rstat_alloc();
double *values = calloc(boots, sizeof(double)); double *values = calloc(boots, sizeof(double));
double *resample = calloc(n, sizeof(double));
for (size_t i = 0; i < boots; i++) { for (size_t i = 0; i < boots; i++) {
/* The sampling is simply done by generating /* The sampling is simply done by generating
@ -186,9 +187,9 @@ uncert bootstrap_median(
*/ */
for (size_t j = 0; j < n; j++) { for (size_t j = 0; j < n; j++) {
size_t choice = gsl_rng_uniform_int(r, n); size_t choice = gsl_rng_uniform_int(r, n);
gsl_rstat_add(sample[choice], w); resample[j] = sample[choice];
} }
values[i] = gsl_rstat_median(w); values[i] = gsl_stats_median(resample, 1, n);
} }
/* Compute mean and stdev of the medians /* Compute mean and stdev of the medians