Generate random numbers from a non-parametric PDF

1 Ansicht (letzte 30 Tage)
TheBeginner
TheBeginner am 27 Nov. 2014
Beantwortet: Torsten am 28 Nov. 2014
Hello,
I know similar questions have already been asked, but I can't seem to solve my problem.
I want to generate random numbers from a probality density function having two blobs, for instance the sum of gaussians. My PDF would therefore look like this :
p(x) = N(x;mu1,sigma1) + N(x;mu2,sigma2);
I have tried the following procedures :
1. Generate random numbers using uniform distribution. Take the PDFs of a vector and invert it using "icdf"
2.Generate random numbers using uniform distribution. Write the CDF (analytic in this case) and invert it.
My code looks like this (for the first idea) :
%Uniform random numbers
u = rand(1,1000);
%PDF
x = linspace(0,xmax,N)';
values = gauss(x,mu1,sigma1) + gauss(x,mu2,sigma2);
pd = fitdist(values,'kernel');
%Inversion
y = icdf(pd,u);
But it doesn't seem to work. The second method also doesn't work, because I can't invert the CDF of two gaussians.
Any idea?

Antworten (1)

Torsten
Torsten am 28 Nov. 2014
If X~N(mu1,sigma1) and Y~N(mu2,sigma2) and X and Y are independent, then X+Y~N(mu1+mu2,sigma1+sigma2).
Thus the PDF of the sum of two gaussians does not have two blobs.
Best wishes
Torsten.

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by