增加variate_generator以解决泊松分布问题

时间:2011-12-12 12:27:58

标签: boost distribution poisson

我使用boost variate_generator从boost_1_46_1的泊松分布生成随机数(显然variate_generator的文件夹结构在版本之间随机变化)。

代码片段如下,然后是错误报告:显然它无法识别对variate_generator的调用并抱怨variate_generator.hpp:123: error: no type named result_type in class boost::math::poisson_distribution

我无法弄清楚我做错了什么 - 非常感谢帮助!感谢。

#include <boost/random/variate_generator.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/math/distributions/poisson.hpp>
using namespace boost;

double  poiss(double mean) {
static boost::mt19937 randgen(0);
static boost::math::poisson_distribution <double> pd(mean);
    static boost::variate_generator <boost::mt19937&, boost::math::poisson_distribution <double> > generator(randgen, pd); <- line CnvSeg.c:46
return (double) generator();
}

错误

CnvSeg.c:47: error: no match for call to â(boost::variate_generator<boost::mt19937&, boost::math::poisson_distribution<double, boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> > >) ()â
/home/craczy/boost_1_46_1/include/boost/random/variate_generator.hpp: In constructor âboost::variate_generator<Engine, Distribution>::variate_generator(Engine, Distribution) [with Engine = boost::mt19937&, Distribution = boost::math::poisson_distribution<double, boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> >]â:
CnvSeg.c:46:   instantiated from here
/home/craczy/boost_1_46_1/include/boost/random/variate_generator.hpp:134: error: using invalid field âboost::variate_generator<Engine, Distribution>::_engâ
/home/craczy/boost_1_46_1/include/boost/random/variate_generator.hpp:123: error: no type named âresult_typeâ in âclass boost::math::poisson_distribution<double, boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> >â

1 个答案:

答案 0 :(得分:1)

您正在使用错误的泊松分布。 boost :: math发行版似乎不能与Boost.Random一起使用,所以请使用:

 #include <boost/random/poisson_distribution.hpp>
 boost::poisson_distribution<> pd(mean);
 boost::variate_generator <boost::mt19937, boost::poisson_distribution<> >