我正在尝试使用boost::math中的Gamma发行版,但它看起来不可能与boost::variate_generator一起使用。有人能证实这一点吗?或者有没有办法使用它。
我发现有一个没有文档记录的boost::gamma_distribution,可能也可以使用,但它只允许从发行版中选择alpha参数,而不是beta。
谢谢!
发布于 2010-05-20 23:35:22
正如在this link中提到的,您可以简单地通过将rng的输出乘以所需的比例来扩展Boost(或tr1)的单参数伽马分布。
下面是使用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();
}https://stackoverflow.com/questions/2526483
复制相似问题