필터 지우기
필터 지우기

Generating random number from a pdf

조회 수: 4 (최근 30일)
Symeon Mattes
Symeon Mattes 2014년 5월 8일
편집: Symeon Mattes 2014년 5월 12일
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 ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by