필터 지우기
필터 지우기

Generate random numbers from a non-parametric PDF

조회 수: 5 (최근 30일)
TheBeginner
TheBeginner 2014년 11월 27일
답변: Torsten 2014년 11월 28일
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?

답변 (1개)

Torsten
Torsten 2014년 11월 28일
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.

Community Treasure Hunt

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

Start Hunting!

Translated by