Noise samples of gaussian mixture distribution
Show older comments
I'm new to matlab. I want to generate noise samples of Gaussian mixture with PDF= sqrt((u.^3)./pi).*exp(-u.*(x.^2)) + sqrt((1-u)^3/pi).*exp(-(1-u).*x.^2);
The length of noise sample is (1,200) Please help me out.
Accepted Answer
More Answers (2)
Proof of concept, not the smart way to do it
If this was to be done in an efficient way:
- Derive the cdf.
- Get a random number between 0 and 1: rand()
- Compute the inverse cdf for that number.
This is possible to do analytically.
We can do it numerically for u = 0.5:
u = 0.5;
myfun = @(x) sqrt((u.^3)./pi).*exp(-u.*(x.^2)) + sqrt((1-u)^3/pi).*exp(-(1-u).*x.^2);
Getting the random value
val = rand;
The integral() part computes the cdf corresponding to a value in the interval ]0,1[
intFun = @(x) integral(myfun,-Inf,x) - val;
The value you are looking for will be the root for the above function:
your_value = fzero(intFun,0);
And you can check that you actually obtained the right result.
integral(myfun,-Inf,your_value)
Which should be equal to val
Inefficient: loop 200 times to get your random vector. Better: solve it analytically, or see if your function is a built-in distribution in Matlab (I don't think so though).
2 Comments
Ankita kumari
on 28 Jun 2016
I'm unable to understand why you subtracted val from integral value. The integral will give the cdf. Earlier you said that after deriving the CDF we need to compute the inverse of that.
I have computed the cdf it is:
cdf=u*(1-qfunc(x/(sqrt(1/(2*u))))) + (1-u)*(1-qfunc(x/(sqrt(1/(2*(1-u))))));
next what I need to do?
José-Luis
on 28 Jun 2016
Because you need to find the value for which the cdf gives val and finding the roots of the cdf minus said value is one way to go.
I you have the cdf then you can ignore the integral() part of what I gave you and use that instead. Better yet, compute the inverse cdf and obtain your value directly.
Bjorn Gustavsson
on 28 Jun 2016
0 votes
For any given u between 0 and 1/2 this looks like the sum of 2 zero-centred normal-distributions (however there seems to me that the scaling is a bit off, so maybe check that the pdf actually adds up to 1?), in that case it should be as simple as
x_samples = sigma1*randn(sz_samples) + sigma2*randn(sz_samples)
right?
HTH
5 Comments
John D'Errico
on 28 Jun 2016
Yes. You are correct that it is not properly scaled for a pair of Gaussian modes as a mixture. As such, the PDF is incorrect.
Ankita kumari
on 28 Jun 2016
I have checked the pdf, the integration from minus infinity to infinty gives 1.
The method you suggested
x_samples = sigma1*randn(sz_samples) + sigma2*randn(sz_samples)
what does sz_samples contains?
Bjorn Gustavsson
on 28 Jun 2016
OK, in that case sz_samples should be your noise-sample-size i.e. [1,200].
John D'Errico
on 28 Jun 2016
Edited: John D'Errico
on 28 Jun 2016
Actually, this procedure is not correct. It is not the same to simply add samples from two different gaussians as what the OP asked for.
The sum of x and y, where x and y are both gaussian with different variances has a gaussian distribution also. The PDF posed by the OP was a MIXTURE distribution. That is a VERY different animal.
Ankita kumari
on 28 Jun 2016
Yes, you're right. This gives wrong results.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
