I am trying since quite some time to draw random variates from the gsl dirichlet distribution, but I cannot seem to make it work.
I have looked around for documentation/examples, but cannot find anything. Does anybody have any recommendations?
Basically, the function the gsl gives is:
void gsl_ran_dirichlet(const gsl_rng *r, size_t K, const double alpha[], double theta[])
Below you can find the code I am using. I can get the programm to return a random draw from the beta distribution, so it is compiling. But I am doing something (or probably) several things wrong for the dirichlet.
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include "gsl/gsl_rng.h"
#include "gsl/gsl_randist.h"
using namespace std;
int main(int argc, const char *argv[]) {
gsl_rng *gen = gsl_rng_alloc (gsl_rng_mt19937); // allocate gsl_rng version of Mersenne twister
gsl_rng_set(gen,(unsigned)time(NULL)); // seed gsl_rng version of Mersenne twister
//gsl_rng gen1;
gsl_rng** gen1;
gen1 = &gen;
gsl_rng* gen2;
gen2 = gen;
double aBetaDist = 2;
double bBetaDist = 2;
double belateresult = gsl_ran_beta(gen,aBetaDist,bBetaDist);
const size_t K = 3;
const double alpha [3] = { 3, 3, 3};
double theta[3];
void gsl_ran_dirichlet(const gsl_rng *r, size_t K, const double alpha[], double theta[]);
gsl_ran_dirichlet(gen, K, alpha[], theta[]);
cout << "beta_value = " << gsl_ran_beta(gen,aBetaDist,bBetaDist) << endl;
cout << "beta_value1 = " << belateresult << endl;
cout << "alpha_value = " << alpha[2] << endl;
gsl_rng_free(gen);
return 0;
}
Thanks a lot for your help!