问题描述
我试图使用从boost ::数学Gamma分布,但它看起来像它不可能与升压:: variate_generator使用它。可能有人证实?或者是有使用它的方式。
I'm trying to use the Gamma distribution from boost::math but it looks like it isn't possible to use it with boost::variate_generator. Could someone confirm that? Or is there a way to use it.
我发现有一个boost :: gamma_distribution无证这也许可以太习惯,但只允许选择从分布的alpha参数,而不是测试版。
I discovered that there is a boost::gamma_distribution undocumented that could probably be used too but it only allows to choose the alpha parameter from the distribution and not the beta.
谢谢!
推荐答案
如,你可以简单地通过所需的规模RNG的输出乘以延长Boost的(或TR1的)一个参数的伽玛分布。
As mentioned in this link, you can extend Boost's (or TR1's) one-parameter gamma distribution simply by multiplying the output of the rng by your desired scale.
下面是使用示例code variate_generator
从伽玛分布得出的数字,以均值和方差参数:
Below is sample code that uses variate_generator
to draw numbers from a gamma distribution, parameterized by mean and variance:
#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();
}
这篇关于Gamma分布在升压的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!