Generating random number from a pdf
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
SK
el 8 de Mayo de 2014
Editada: SK
el 8 de Mayo de 2014
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 comentario
Symeon Mattes
el 11 de Mayo de 2014
Editada: Symeon Mattes
el 12 de Mayo de 2014
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 ?
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!