Generate random samples from arbitrary discrete probability density function in Matlab

조회 수: 10 (최근 30일)
I've got an arbitrary probability density function discretized as a matrix in Matlab, that means that for every pair x,y the probability is stored in the matrix: A(x,y) = probability
This is a 100x100 matrix, and I would like to be able to generate random samples of two dimensions (x,y) out of this matrix and also, if possible, to be able to calculate the mean and other moments of the PDF. I want to do this because after resampling, I want to fit the samples to an approximated Gaussian Mixture Model.
I've been looking everywhere but I haven't found anything as specific as this. I hope you may be able to help me.
Thank you.

채택된 답변

Miguel Encinas
Miguel Encinas 2015년 7월 28일
Thank you all for your ideas.
In the end, the closest to the solution I was looking for was found by a user in this site. All credit to him: http://stackoverflow.com/questions/31665504/generate-random-samples-from-arbitrary-discrete-probability-density-function-in/

추가 답변 (2개)

Walter Roberson
Walter Roberson 2015년 7월 28일
편집: Walter Roberson 2015년 7월 28일
nA = numel(A);
numsamples = 20;
samples = A(randi(nA,[numsamples,1]));
This assumes you want to uniformly sample from the matrix. If you do not, then you will need to specify your sampling method.
  댓글 수: 1
Miguel Encinas
Miguel Encinas 2015년 7월 28일
편집: Miguel Encinas 2015년 7월 28일
First of all thank you for your answer.
The solution you gave me takes samples from the values stored in the matrix, but maybe I didn't explain well what I want.
The matrix A that I have represents a discrete probability density function (as I understand it), that means that for each pair of values (x,y) which are the indices of the matrix a probability is stored in the matrix in the following way: A(x,y) = probability
What I want to do are two things:
1) Take samples according to the probability stored in the matrix, so that this samples follow this custom discretized distribution. That means that my samples have to be of two dimensions [x y] and need to be produced according to the probability stored in the matrix.
2) Calculate the mean and covariance by approximating the samples taken before to a Gaussian Mixture Model (I think I know how to do this once I have the samples).
Thank you.

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


Torsten
Torsten 2015년 7월 28일
Take a look at the second example under
Best wishes
Torsten.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by