Effacer les filtres
Effacer les filtres

How to sample from custom 2D distribution?

24 vues (au cours des 30 derniers jours)
Filip Trönnberg
Filip Trönnberg le 18 Avr 2012
I have a joint density function for to independent variables X and Y. (See: http://dl.dropbox.com/u/709705/JointDens.png) And I now want to sample new x,y from this distribution.
What I believe I have to do is to find the joint cumulative distribution and then somehow sample from it. I kinda know how to do this in 1D, but I find it really hard to understand how to do it in 2D.
I also used the matlab-function cumtrapz to find the cumulative distribution function for the above pdf. (See: http://dl.dropbox.com/u/709705/CumulativeDist.png)
Just to be clear, what i want to do is to sample random values x,y from this empirical distribution.
Can someone please point me in the right direction here?!

Réponse acceptée

Razvan
Razvan le 19 Avr 2012
  3 commentaires
Tristan Ursell
Tristan Ursell le 26 Juil 2012
Happy to help :)
Hussein Ammar
Hussein Ammar le 2 Juil 2019
Thank you for mentioning this function. It helped me a lot.

Connectez-vous pour commenter.

Plus de réponses (2)

Richard Brown
Richard Brown le 19 Avr 2012
A really basic, quick to code (but darned inefficient way) is to generate uniform samples in the 3D volume defined by the x and y coordinates and the maximum z coordinate. Accept only samples that fall beneath the surface. The x,y coordinates of these samples will have the distribution you want.
  3 commentaires
Atul Kedia
Atul Kedia le 21 Juil 2019
Modifié(e) : Atul Kedia le 22 Juil 2019
Lets say the pdf is for variables and is denoted by .
You can imagine a 2-D distribution as a surface in 3 dimensions with undulations based on the distribution. The height of the surface above any point corresponds to its probability (distribution ). What he is suggesting is to sample uniformly over the range of (where maximum value that z takes = maximum value of the pdf, or , or the max height of the surface in 3-D).
If for the sampled () , then the coordinates are part of your randomly sampled points. If then the point need to be rejected and is not part of your sample.
Let me know if you have more questions.
Ahmadreza Momenisedei
Ahmadreza Momenisedei le 28 Sep 2020
Modifié(e) : Ahmadreza Momenisedei le 28 Sep 2020
That was smart!

Connectez-vous pour commenter.


Tom Lane
Tom Lane le 19 Avr 2012
There is a Statistics Toolbox function "slicesample" that could be useful. It does not generate independent samples from the distribution, but instead generates a Markov Chain such that a long sequence of values will have a distribution close to the target distribution. To use this, you would need to be able to write down an expression for the density.

Community Treasure Hunt

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

Start Hunting!

Translated by