Generating random number from a pdf

6 次查看(过去 30 天)
Hi all,
I have bivariate probability density function f(x,y), which it doesn't follow any pdf from the known pdfs, and I would like to generate x, y random numbers that follow this pdf. Is there any way to do that in matlab?
Thanks in advance

回答(1 个)

SK
SK 2014-5-8
编辑:SK 2014-5-8
For simplicity, assume that the distribution has bounded support, i.e:
There is some Mx and My such that f(x,y) is zero for abs(x) > Mx and abs(y) > My.
One could probably do without this condition but it would a little more involved and in practice (unless you have a heavy-tailed distribution) it wont make much difference.
With this assumption, a general way to do it for any f(x,y) is as follows:
Let Mz = max(f(x,y)) over all x and y.
Now use rand to choose 3 numbers uniformly in the Box (-Mx < x < Mx) x (-My < y < My) x (z < Mz):
x = 2*Mx*(rand-0.5);
y = 2*My*(rand-0.5);
z = Mz*rand;
if z > f(x,y), reject x and y
otherwise add (x,y) to your set of generated points.
Best Regards,
Sandeep
  1 个评论
Symeon Mattes
Symeon Mattes 2014-5-11
编辑:Symeon Mattes 2014-5-12
Thanks SK for your reply. This seem to work but because I have a huge amount of data and the grid is very dense is there any analytical method such as in 1D case, e.g. Using a sample PDF to generate random numbers ?

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by