ex-1: reduce sample size and various fixes

This commit is contained in:
Michele Guerini Rocco 2020-04-11 19:29:38 +02:00
parent 72fa3ad2e7
commit 343fe3aac3
3 changed files with 7 additions and 7 deletions

View File

@ -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++)

View File

@ -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

View File

@ -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);