Define a density function and draw N samples of it
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
Jeff Miller
2021-4-26
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 个评论
Jeff Miller
2021-4-27
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
2021-4-27
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!