问题描述
我想使用升压根据使用C ++ Beta分布产生随机数。我见过很多例子在线根据random.hpp(例如分布<一个生成随机数href=\"http://books.google.com/books?id=ZR52ao4u5O0C&pg=PA408&dq=boost+random+distribution&hl=en&ei=h7XgTOmLAYqynwfL99W5Dw&sa=X&oi=book_result&ct=result&resnum=1&ved=0CCgQ6AEwAA#v=onepage&q=boost%20random%20distribution&f=false\">this本书)。但是,我没有看到翻译他们使用beta.hpp发现了β分布。
I am trying to use Boost to generate random numbers according to the beta distribution using C++. I have seen many examples online for generating random numbers according to distributions in random.hpp (e.g. this book). However, I cannot seen to translate them to use the beta distribution found in beta.hpp.
感谢。
推荐答案
欢迎到计算器!你首先要从范围(0,1)均匀画出一个随机数。鉴于任何分配,可以再插这个数字到分发的点函数,其结果是,如果一个随机值从分布绘制。从:
Welcome to StackOverflow! You'll first want to draw a random number uniformly from the range (0,1). Given any distribution, you can then plug that number into the distribution's "quantile function," and the result is as if a random value was drawn from the distribution. From here:
一个一般方法来生成从具有无跳跃一个CDF任意分布的随机数是使用反函数的CDF:克(y)的= F ^ { - 1}(Y)。如果U(1),...,U(N)是从统一的(0,1)分布的随机数,则G(U(1)),...,G(U(N))是一个随机从CDF F(X)。
那么,我们如何得到一个beta分布的分位数的功能?对于beta.hpp的文档here.您应该能够使用这样的:
So how do we get a quantile function for a beta distribution? The documentation for beta.hpp is here. You should be able to use something like this:
#include <boost/math/distributions.hpp>
using namespace boost::math;
double alpha, beta, randFromUnif;
//parameters and the random value on (0,1) you drew
beta_distribution<> dist(alpha, beta);
double randFromDist = quantile(dist, randFromUnif);
希望这有助于!
这篇关于生成基于使用Boost Beta分布随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!