diff --git a/ex-1/bootstrap.c b/ex-1/bootstrap.c index ca69985..f8388d3 100644 --- a/ex-1/bootstrap.c +++ b/ex-1/bootstrap.c @@ -43,8 +43,8 @@ size_t mean_index(gsl_vector *v, double x) { /* Computes the half-sample mode (also called the Robertson-Cryer * mode estimator) of the sample `x` containing `n` observations. * - * It is based on repeatedly finding the modal interval (interval - * containing the most observations) of half of the sample. + * It is based on repeatedly finding the half modal interval (smallest + * interval containing half of the observations) of the sample. * This implementation is based on the `hsm()` function from the * modeest[1] R package. * @@ -129,7 +129,7 @@ double gauss_kde(double x, void * params) { * by the sample variance times a factor which * depends on the number of points and dimension. */ - double bw = p.var * pow((double)p.n*3.0/4, -2.0/5); + double bw = 0.4 * p.var * pow((double)p.n*3.0/4, -2.0/5); double sum = 0; for (size_t i = 0; i < p.n; i++) diff --git a/ex-1/main.c b/ex-1/main.c index af414f1..293e052 100644 --- a/ex-1/main.c +++ b/ex-1/main.c @@ -20,7 +20,7 @@ int main(int argc, char** argv) { gsl_rng *r = gsl_rng_alloc(gsl_rng_default); // prepare histogram - size_t samples = 100000; + size_t samples = 50000; double* sample = calloc(samples, sizeof(double)); double min = -10; double max = 10; @@ -40,7 +40,7 @@ int main(int argc, char** argv) { } fprintf(stderr, "done\n"); - // sort the sample: needed for HSM and KS tests + // sort the sample: needed for HSM and ks tests qsort(sample, samples, sizeof(double), &cmp_double); @@ -88,7 +88,7 @@ int main(int argc, char** argv) { // print the results fprintf(stderr, "\n## Results\n"); - fprintf(stderr, "expected mode: %.7f\n", mode_e); + fprintf(stderr, "expected mode: %.8f\n", mode_e); fprintf(stderr, "observed mode: %.4f±%.4f\n", mode_o.n, mode_o.s); // t-test diff --git a/ex-1/tests.c b/ex-1/tests.c index f080079..91b86d1 100644 --- a/ex-1/tests.c +++ b/ex-1/tests.c @@ -108,7 +108,7 @@ double numeric_mode(double min, double max, x = gsl_min_fminimizer_x_minimum(s); min = gsl_min_fminimizer_x_lower(s); max = gsl_min_fminimizer_x_upper(s); - status = gsl_min_test_interval(min, max, prec, prec); + status = gsl_min_test_interval(min, max, 0, prec); } while (status == GSL_CONTINUE && iter < max_iter);