用于解决泊松分布问题的 Boost variate_generator

发布于 2024-12-20 22:02:19 字数 3370 浏览 1 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白云不回头 2024-12-27 22:02:19

您使用了错误的泊松分布。 boost::math 分布似乎不适用于 Boost.Random,因此请使用:

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

You are using the wrong Poisson distribution. boost::math distributions don't seem to work with Boost.Random, so use:

 #include <boost/random/poisson_distribution.hpp>
 boost::poisson_distribution<> pd(mean);
 boost::variate_generator <boost::mt19937, boost::poisson_distribution<> >
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文