用于解决泊松分布问题的 Boost variate_generator
我使用 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> >â
I use boost variate_generator to generate random numbers from poisson distribution for boost_1_46_1 (apparently folder structures for variate_generator randomly change between versions).
The snippets of code are below followed by the error report: apparently it doesn’t recognise a call to variate_generator
and complains about variate_generator.hpp:123: error: no type named result_type in class boost::math::poisson_distribution
.
I couldn’t figure out what I am doing wrong – a help would be most appreciated! Thanks.
code
#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();
}
errors
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> >â
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用了错误的泊松分布。 boost::math 分布似乎不适用于 Boost.Random,因此请使用:
You are using the wrong Poisson distribution. boost::math distributions don't seem to work with Boost.Random, so use: