Generate random numbers from a non-parametric PDF
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuestas (1)
Torsten
el 28 de Nov. de 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.
0 comentarios
Ver también
Categorías
Más información sobre Random Number Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!