2010-03-26 31 views
2

我正在嘗試使用boost :: math中的Gamma分佈,但它看起來像不能用於boost :: variate_generator。有人可以證實嗎?或者有沒有辦法使用它。增量中的伽馬分佈

我發現有一個boost :: gamma_distribution無法記錄,可能也可以使用,但它只允許從分佈中選擇alpha參數而不是beta。

謝謝!

回答

4

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(); 
} 
+0

這是很好的,你也可以得到反伽馬出這 – pyCthon 2011-12-07 06:04:41

相關問題