C++ でライブラリ GSL から関数 gsl_histogram_pdf_sample を使用する方法を理解するのに問題があります。ドキュメントはこちら、
私はまだ専門家ではないので、このコードの何が問題なのか誰か教えてもらえないかと思っていましたが、
#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;
}
プログラムはエラーなしでコンパイルされますが、実行すると常に次のエラーが発生します。
gsl: /usr/src/gsl-1.16-1/src/gsl-1.16/histogram/pdf.c:46: ERROR: cannot find r in cumulative pdf
そして、私はそれが何を意味するのか分かりません。