Gamma distribution in Boost

I am trying to use the Gamma distribution from boost :: math, but it seems that it cannot be used with boost :: variate_generator. Can anyone confirm this? Or is there a way to use it.

I found that there is an invalid boost :: gamma_distribution, which you can probably use, but it only allows you to select the alpha parameter from the distribution, and not from the beta version.

Thank!

+2
source share
1 answer

As mentioned in this link , you can expand the one-parameter Boost gamma distribution (or TR1) simply by multiplying the rng output on the desired scale.

, variate_generator -, :

#include <boost/random.hpp>
#include <boost/random/gamma_distribution.hpp>

double rgamma( double mean, double variance, boost::mt19937& rng ) {
  const double shape = ( mean*mean )/variance;
  double scale = variance/mean;

  boost::gamma_distribution<> gd( shape );
  boost::variate_generator<boost::mt19937&,boost::gamma_distribution<> > var_gamma( rng, gd );

  return scale*var_gamma();
}
+4

All Articles