生成基于使用Boost Beta分布随机数 [英] Generate Random Number Based on Beta Distribution using Boost

查看:1355
本文介绍了生成基于使用Boost Beta分布随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用升压根据使用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)。

A general method to generate random numbers from an arbitrary distribution which has a cdf without jumps is to use the inverse function to the cdf: G(y)=F^{-1}(y). If u(1), ..., u(n) are random numbers from the uniform on (0,1) distribution then G(u(1)), ..., G(u(n)) is a random sample from the distribution with cdf F(x).

那么,我们如何得到一个beta分布的分位数的功能?对于beta.hpp的文档<一个href=\"http://www.boost.org/doc/libs/1_44_0/libs/math/doc/sf_and_dist/html/math_toolkit/dist/dist_ref/dists/beta_dist.html\">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分布随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆