ex-1: remove histogram code
This commit is contained in:
parent
01060d2344
commit
b8571eaee8
22
ex-1/main.c
22
ex-1/main.c
@ -2,7 +2,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <gsl/gsl_randist.h>
|
||||
#include <gsl/gsl_histogram.h>
|
||||
#include <gsl/gsl_statistics_double.h>
|
||||
|
||||
#include "landau.h"
|
||||
@ -10,10 +9,10 @@
|
||||
#include "bootstrap.h"
|
||||
|
||||
|
||||
/* Here we generate random numbers in a uniform
|
||||
* range and by using the quantile we map them
|
||||
* to a Landau distribution. Then we generate an
|
||||
* histogram to check the correctness.
|
||||
/* Here we generate random numbers following
|
||||
* the Landau distribution and run a series of
|
||||
* test to check if they really belong to such a
|
||||
* distribution.
|
||||
*/
|
||||
int main(int argc, char** argv) {
|
||||
// initialize an RNG
|
||||
@ -23,17 +22,14 @@ int main(int argc, char** argv) {
|
||||
// prepare histogram
|
||||
size_t samples = 100000;
|
||||
double* sample = calloc(samples, sizeof(double));
|
||||
size_t bins = 40;
|
||||
double min = -10;
|
||||
double max = 10;
|
||||
gsl_histogram* hist = gsl_histogram_alloc(bins);
|
||||
gsl_histogram_set_ranges_uniform(hist, min, max);
|
||||
|
||||
|
||||
/* Sample generation
|
||||
*
|
||||
* Sample points from the Landau
|
||||
* distribution and fill the histogram.
|
||||
* Sample points from the Landau distribution
|
||||
* using the GSL Landau generator.
|
||||
*/
|
||||
fprintf(stderr, "# Sampling\n");
|
||||
fprintf(stderr, "generating %ld points... ", samples);
|
||||
@ -41,11 +37,10 @@ int main(int argc, char** argv) {
|
||||
for(size_t i=0; i<samples; i++) {
|
||||
x = gsl_ran_landau(r);
|
||||
sample[i] = x;
|
||||
gsl_histogram_increment(hist, x);
|
||||
}
|
||||
fprintf(stderr, "done\n");
|
||||
|
||||
// sort the sample
|
||||
// sort the sample: needed for HSM and KS tests
|
||||
qsort(sample, samples, sizeof(double), &cmp_double);
|
||||
|
||||
|
||||
@ -54,6 +49,7 @@ int main(int argc, char** argv) {
|
||||
* Compute the D statistic and its
|
||||
* associated probability.
|
||||
*/
|
||||
fprintf(stderr, "\n\n# Kolmogorov-Smirnov test\n");
|
||||
double D = 0;
|
||||
double d;
|
||||
for(size_t i=0; i<samples; i++) {
|
||||
@ -61,7 +57,6 @@ int main(int argc, char** argv) {
|
||||
if (d > D)
|
||||
D = d;
|
||||
}
|
||||
fprintf(stderr, "\n\n# Kolmogorov-Smirnov test\n");
|
||||
double beta = kolmogorov_cdf(D, samples);
|
||||
|
||||
// print the results
|
||||
@ -152,7 +147,6 @@ int main(int argc, char** argv) {
|
||||
|
||||
|
||||
// clean up and exit
|
||||
gsl_histogram_free(hist);
|
||||
gsl_rng_free(r);
|
||||
free(sample);
|
||||
return EXIT_SUCCESS;
|
||||
|
Loading…
Reference in New Issue
Block a user