Pseudo Random Nubmer Sampling

Pseudo Random Nubmer Sampling

https://en.wikipedia.org/wiki/Inverse\_transform\_sampling

given a distribution's cumulative distribution function (CDF), generate sample numbers for this distribution.

typically based on uniform distribution variable X (or several of them), then somehow manipulate it, and get random variable Y which has the required distribution

Rejection Sampling if density function is known

one type of Monte-Carlo Method
see some notes

target: sample from F=f(x)

idea: find an alternative G=g(x) which we already know, and that f(x)/g(x) <= c where c is a constant (ideally close to 1)

algorithm:

  1. sample y from G;
  2. sample u from U[0,1];
  3. if u <= f(y)/c*g(y), then accept y; reject otherwise

Inverse Transform Sampling for distributions where CDF is known

  1. input 1: CDF of some distribution; for example, exponential distribution, F(x)=1-exp{\left(1-\lambda x\right)}
  2. input 2: a uniform distribution U[0,1]; for example, u=0.387;
  3. F(x) = y => x = F^{-1}\left(y\right) = -\frac{1}{\lambda}\ln{\left(1-y\right)} => x = -\frac{1}{\lambda}\ln\left(y\right)
  4. draw a value from U[0,1], and use it as CDF() value, then solve for the corresponding x value

Box-Muller Transform for Normal Distribution

  1. only used for generating Normal Distribution
  2. input: uniform distribution U[0,1]
  3. output: 2 independent standard normal distribution numbers
  4. Suppose U1 and U2 are independent random variables from U[0,1]
  5. let Z0 and Z1, then Z0 and Z1 are both N(0,1) random variables

example

有一个数组,类似于:{{'Canada', 3}, {'USA', 5}, {'UK', 2}, {'Brasil', 3}}, 数组的类型是Country, 有两个变量, Country.name, Country.weight. 每个国家都有一个权重,然后给一个output()函数,每次调用这个函数的时候就输出一个国家的名字,要使每个国家被输出的概率相等。我用的方法是平摊weight: {Canada, Canada, USA, USA, USA, USA, UK, UK, Brasil, Brasil, Brasil}, 然后用Random 函数输出。Follow up : 如果这个权重的值很大很大,比如billio级别,应该怎么办。我的方法是类似于线段树,然后再用sum * Random(), 看这个区间坐落在哪里。

  1. target distribution is a discrete distribution, p(x='Canada')=3/13, p(x='USA')=5/13 etc.
  2. fit it into the Inverse Transform Sampling algorithm
  3. sample an integer from [1,13], {1,2,3} => Canada, {4,5,6,7,8} => USA, {9,10} => UK, {11,12,13} => Brasil

转载于:https://www.cnblogs.com/qsort/p/6107720.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值