I am having some trouble understanding how to use the function gsl_histogram_pdf_sample from the library GSL in C++. The documentation is here,
I am not really an expert yet, so, I was wondering if anyone could tell me what is wrong with this code,
#include <iostream>
#include <gsl/gsl_histogram.h>
#include <gsl/gsl_rng.h>
using namespace std;
int main()
{
// I am going to use 5 bins
size_t Bins = 5;
// These are the ranges (must be Bins + 1)
double range[6] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 };
// Array with probabilities
double w[5] = {0.05, 0.1, 0.3, 0.4, 1};
// Create the histogram pdf
gsl_histogram_pdf MyHistPdf;
MyHistPdf.n = Bins;
MyHistPdf.range = range;
MyHistPdf.sum = w;
const gsl_rng_type * T;
gsl_rng * r;
T = gsl_rng_default;
r = gsl_rng_alloc (T);
double u = gsl_rng_uniform(r);
cout << u << endl;
double a = gsl_histogram_pdf_sample(&MyHistPdf, u);
return 0;
}
The program compiles with no errors, but when I run it, I always get the following error,
gsl: /usr/src/gsl-1.16-1/src/gsl-1.16/histogram/pdf.c:46: ERROR: cannot find r in cumulative pdf
And I have no idea what does it mean.