具有特定非均匀分布的伪随机数生成
我正在编写一个程序来模拟各种随机游走(具有不同的分布)。在每个时间步长,我需要随机游走分布中随机生成的二维步长距离和角度。我希望有人可以检查我对如何生成这些随机数的理解。
据我了解,我可以按如下方式使用逆变换采样:
如果 f(x) 是具有非均匀分布的随机游走的 pdf,并且 y 是来自均匀分布的随机数。 然后,如果我们让 f(x) = y 并求解出 x,那么我们就会得到一个来自非均匀分布的随机数。
这是一个可行的解决方案吗?
I'm writing a program that simulates various random walks (with differing distributions). At each timestep, I need randomly generated, two dimensional step distances and angles from the distribution of the random walk. I'm hoping someone can check my understanding of how to generate these random numbers.
As I understand it I can use Inverse Transform Sampling as follows:
If f(x) is the pdf of our random walk that has a non-uniform distribution, and y is a random number from a uniform distribution.
Then if we let f(x) = y and solve to find x then we have a random number from the non-uniform distribution.
Is this a feasible solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不完全是。需要求逆的函数不是 pdf f(x),而是 cdf F(x)=P(X<=x)=int_{-inf}^{x}f(t)dt。好处是 F 是单调的,因此实际上有唯一的逆元(与 f 不同)。
还有多种其他方法可以根据给定的分布生成随机数。例如,如果 cdf F 难以计算或求逆,拒绝采样 可以是如果 f 很容易计算,那么这是一个不错的选择。
Not quite. The function that needs to be inverted is not f(x), the pdf, but F(x)=P(X<=x)=int_{-inf}^{x}f(t)dt, the cdf. The good thing is that F is monotone, so actually has a unique inverse (unlike f).
There are multiple other ways of generating random numbers according to a given distribution. For example, if the cdf F is difficult to compute or to invert, rejection sampling can be a good option if f is easy to compute.
你很接近,但还不够。每个概率密度函数 (pdf) 都有一个相应的累积密度函数 (cdf)。 CDF(x) 的一个重要属性是它们始终介于 0 和 1 之间。因为绘制 0 到 1 之间的随机数相对容易,所以我们可以使用它来逆向分布。因此,在您的问题中将 pdf 一词更改为 CDF 会使该陈述正确。
为了使这一点在计算上有意义,您需要找到一个易于计算的 CDF 的逆函数。实现此目的的一种方法是将多项式近似拟合到 CDF 并找到该函数的反函数。有更先进的技术可以模拟杂乱分布的概率分布。有关详细信息,请参阅图书章节。
You are close, but not quite. Every probability density function (pdf) has a corresponding cumulative density function (cdf). An important property about CDF(x) is that they are always between 0 and 1. Because it is relatively easy to draw a random number between 0 and 1, we can use that to work our way backwards to the distribution. So changing the word pdf to CDF in your question makes the statement correct.
As an aside for this to make sense computationally you need to find an easy to calculate inverse of the CDF. One way to do this is to fit a polynomial approximation to the CDF and find the inverse of that function. There are more advanced techniques for simulating probability distributions with messy distributions. See this book chapter for the details.