Define a density function and draw N samples of it

Hi,
So i want to define a density function and draw N samples of it. does anyone know how can i do it?
for example if i want a gaussian mixture (with M=4 gaussians with diffrent expectations mu's) i defined:
f1=(1/(2*pi*sigma2*M))*(exp((-1/(2*sigma2))*((vecnorm((X-mu(1,:)).').').^2))+...
exp((-1/(2*sigma2))*((vecnorm((X-mu(2,:)).').').^2))+...
exp((-1/(2*sigma2))*((vecnorm((X-mu(3,:)).').').^2))+...
exp((-1/(2*sigma2))*((vecnorm((X-mu(4,:)).').').^2)));
But im not sure how to chose X such as the samples will represent the distrebution (that is more samples in the center of the gauusians and less in its sides).
The gaussian mixture is just an exaple i am looking for a way to do it to any density function.
Thanks

답변 (2개)

Jeff Miller
Jeff Miller 2021년 4월 26일

0 개 추천

I don't think that density function is right--seems like you at least need to include the mixture probabilities in there--e.g., 1/4 * each density if the 4 gaussians are equally likely.
You might have a look at Cupid which supports densities and random number generation for mixtures of lots of density functions. It might already do what you want; if not, you might get some useful formulas.

댓글 수: 2

As far as i understand i did the normalization you talked about, with the coeffetiont (1/(2*pi*sigma2*M)) (M=4).
Cupid looks great, i will take a look. thanks!
M=4 seems right--I did not notice that.
If you know the cdf's of all your distributions, then the cdf of the mixture at each x is the sum of the cdf_i(x)*p*i values, and you can use the inverse transform sampling technique suggested by Paul.
Alternatively, you can generate random numbers by first choosing one of the distributions randomly with probabilities p_i and then choosing a random number from that distribution. (This is what Cupid does for mixtures.)

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

Paul
Paul 2021년 4월 27일

0 개 추천

The Statistics and Machine Learning Toolbox has lots of typical densities that can be used to generate samples of random variables. If you have a custom-defined probability density function for which you can define the CDF, you can try an inverse transform sampling technique, which can be implemented numerically if you don't have a closed form expression for the CDF.

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

질문:

2021년 4월 26일

댓글:

2021년 4월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by