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