0

I am trying to use the Gamma distribution from Boost 1.5. Now I want the value of k and theta to be 4 and .5 respectively. But I get a compile error whenever I set the value of theta < 1.

/usr/local/include/boost/random/gamma_distribution.hpp:118: boost::random::gamma_distribution<RealType>::gamma_distribution(const RealType&, const RealType&) [with RealType = double]: Assertion `_beta > result_type(0)' failed.

Is there any way to get around the same?

mavam
  • 12,242
  • 10
  • 53
  • 87
freeborn
  • 115
  • 1
  • 2
  • 8
  • Without posting a small self-contained example code snippet, it is very hard to debug your problem. – mavam Aug 15 '12 at 19:22

1 Answers1

0

It looks like you do not pass the parameters correctly to the distribution function. Here is the C++11 version (Boost works equivalently):

#include <random>
#include <iostream>
int main()
{   
    std::random_device rd;
    std::mt19937 gen(rd());
    double alpha = 4.0;
    double theta = 0.5;
    std::gamma_distribution<> gamma(alpha, 1.0 / theta);
    auto value = gamma(gen);

    // May print: 6.94045.
    std::cout << value << std::endl;

    return 0;
}

Note the parametrization:

  • alpha is the same as k
  • beta the inverse scale parameter and is the same as 1 / theta.
mavam
  • 12,242
  • 10
  • 53
  • 87