How to sample from custom 2D distribution?
조회 수: 24 (최근 30일)
이전 댓글 표시
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?!
댓글 수: 0
채택된 답변
추가 답변 (2개)
Richard Brown
2012년 4월 19일
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
Atul Kedia
2019년 7월 21일
편집: Atul Kedia
2019년 7월 22일
Lets say the pdf is for variables
and is denoted by
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230700/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230701/image.png)
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).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230702/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230701/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230704/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230705/image.png)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230706/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230707/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230708/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230709/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230708/image.png)
Let me know if you have more questions.
Tom Lane
2012년 4월 19일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Probability Distributions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!