【问题标题】:Drawing number with pareto distribution具有帕累托分布的图号
【发布时间】:2016-03-15 00:00:02
【问题描述】:

我需要创建一个数字生成器,它可以在特定区间内绘制具有帕累托分布的数字。我正在使用 C++。

我无法使用 C++ 11 的 <random> 库,因此我试图通过使用我发现类 pareto_distribution 的 boost 库来解决我的问题。

关于这个主题还有另一个问题,但他们提出的解决方案对我不起作用。

谁能帮帮我?

提前致谢。

【问题讨论】:

  • 告诉我们你做了什么
  • “但他们提出的解决方案对我不起作用。” - 你甚至没有链接到它。所以没有人应该浪费时间给你一个很可能出于神秘原因“不适合你”的答案。
  • 对不起,你是对的。这是我找到的上一个问题的链接:stackoverflow.com/questions/29155783/…。我还附上了我根据该解决方案编写的脚本,其中也包含错误。感谢您的建议
  • 您可以轻松地从指数分布生成它:en.wikipedia.org/wiki/…

标签: c++ boost random distribution


【解决方案1】:

这是我写的脚本:

    #include <iostream> 
    #include <boost/random/uniform_real_distribution.hpp>
    #include <boost/random/mersenne_twister.hpp>
    #include <boost/random/variate_generator.hpp>
    #include <boost/math/distributions/pareto.hpp>
    #include <time.h>

using namespace std;

int main()
{

     boost::mt19937 *rg = new boost::mt19937();
     rg->seed(time(NULL));
     boost::math::pareto_distribution<> dist;
     boost::random::uniform_real_distribution<> uniformReal(1.0,10.0);

     boost::variate_generator<boost::mt19937&,boost::random::uniform_real_distribution<> > generator(rg, dist);

     double cdfComplement;
     cdfComplement = boost::math::complement::cdf(boost::math::complement(dist,generator()));

     cout << " cdfComplement: " << cdfComplement << endl;


     return 0;
}

【讨论】:

  • 这行给我一个错误: boost::variate_generator<:mt19937> > generator(rg, dist); -- 错误:没有匹配的函数调用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-15
  • 1970-01-01
  • 2018-12-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多