From 602e08b2a29bbc0d5dd6fdc639ea5a6a999dcc74 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sat, 13 Jun 2020 08:39:17 +0000 Subject: [PATCH] ex-1: compute exact median The approximation of the running statistics isn't accurate enough. --- ex-1/bootstrap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ex-1/bootstrap.c b/ex-1/bootstrap.c index 3046015..d3eddb7 100644 --- a/ex-1/bootstrap.c +++ b/ex-1/bootstrap.c @@ -179,6 +179,7 @@ uncert bootstrap_median( gsl_rstat_workspace* w = gsl_rstat_alloc(); double *values = calloc(boots, sizeof(double)); + double *resample = calloc(n, sizeof(double)); for (size_t i = 0; i < boots; i++) { /* The sampling is simply done by generating @@ -186,9 +187,9 @@ uncert bootstrap_median( */ for (size_t j = 0; j < n; j++) { 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