Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Gaussian Mixture

Subject: Gaussian Mixture

From: Jose Valerio

Date: 25 Mar, 2009 03:00:04

Message: 1 of 10

So,

I have to generate 1000 samples distributed according to Gaussian Mixture distribution. And it has to consist of the sum of two distribution N(-2,1) and (2,1). weights of 0.4 and 0.6

I know that there is a method to generate the random numbers based on the inverse function of the cdf of that distribution and that's what I need to use, but I just can't figure it out.

Subject: Gaussian Mixture

From: Peter Perkins

Date: 25 Mar, 2009 13:37:40

Message: 2 of 10

Jose Valerio wrote:

> I have to generate 1000 samples distributed according to Gaussian Mixture distribution. And it has to consist of the sum of two distribution N(-2,1) and (2,1). weights of 0.4 and 0.6
>
> I know that there is a method to generate the random numbers based on the inverse function of the cdf of that distribution and that's what I need to use, but I just can't figure it out.

You _can_ do that if that's what the homework assignment asks for, but there's a more obvious way. Consider what a mixture model is: a random value chosen from one of two probability distributions with (in your case) probabilities .4 and .6. If that sounds like a constructive definition useful for generating a random value from the mixture, it is.

Hope this helps.

Subject: Gaussian Mixture

From: Jose Valerio

Date: 25 Mar, 2009 14:00:18

Message: 3 of 10

Peter Perkins <Peter.Perkins@MathRemoveThisWorks.com> wrote in message <gqdc34$go5$1@fred.mathworks.com>...
> Jose Valerio wrote:
>
> > I have to generate 1000 samples distributed according to Gaussian Mixture distribution. And it has to consist of the sum of two distribution N(-2,1) and (2,1). weights of 0.4 and 0.6
> >
> > I know that there is a method to generate the random numbers based on the inverse function of the cdf of that distribution and that's what I need to use, but I just can't figure it out.
>
> You _can_ do that if that's what the homework assignment asks for, but there's a more obvious way. Consider what a mixture model is: a random value chosen from one of two probability distributions with (in your case) probabilities .4 and .6. If that sounds like a constructive definition useful for generating a random value from the mixture, it is.
>
> Hope this helps.

Ok, this is the whole asignment, but I can't find anything on my lectures that can help much with it. I've tried different ways and I still don't get it, maybe if it was worded a different way I would have a better chance of completing it.

A method to generate random numbers from any distribution is based on the inverse function of
the cdf of that distribution (see the below figure to understand the principle of the method).
Use the method to generate 1000 samples distributed according to a Gaussian Mixture -
distribution (GM), which consist of the weighted sum of two normal distributions N(-2,1) and
N(2,1), with the corresponding weights of 0.4 and 0.6.
Application For Data Analysis - 2 -
Final Project Winter 2009
• Generate the two normal pdfs with function normpdf, just as previously. Plot the pdfs into
a single figure.
• Calculate the weighted sum of these two pdfs, which is the GM-pdf. Plot the GM-pdf with
the function plot – does it look like the weighted sum of two normal distributions?

Subject: Gaussian Mixture

From: Matt

Date: 25 Mar, 2009 15:04:01

Message: 4 of 10

"Jose Valerio" <lapenda@gmail.com> wrote in message <gqdddi$mfe$1@fred.mathworks.com>...
> Peter Perkins <Peter.Perkins@MathRemoveThisWorks.com> wrote in message <gqdc34$go5$1@fred.mathworks.com>...
> > Jose Valerio wrote:
> >
> > > I have to generate 1000 samples distributed according to Gaussian Mixture distribution. And it has to consist of the sum of two distribution N(-2,1) and (2,1). weights of 0.4 and 0.6
> > >
> > > I know that there is a method to generate the random numbers based on the inverse function of the cdf of that distribution and that's what I need to use, but I just can't figure it out.
> >
> > You _can_ do that if that's what the homework assignment asks for, but there's a more obvious way. Consider what a mixture model is: a random value chosen from one of two probability distributions with (in your case) probabilities .4 and .6. If that sounds like a constructive definition useful for generating a random value from the mixture, it is.
> >
> > Hope this helps.
>
> Ok, this is the whole asignment, but I can't find anything on my lectures that can help much with it. I've tried different ways and I still don't get it, maybe if it was worded a different way I would have a better chance of completing it.
>
> A method to generate random numbers from any distribution is based on the inverse function of
> the cdf of that distribution (see the below figure to understand the principle of the method).
> Use the method to generate 1000 samples distributed according to a Gaussian Mixture -
> distribution (GM), which consist of the weighted sum of two normal distributions N(-2,1) and
> N(2,1), with the corresponding weights of 0.4 and 0.6.
> Application For Data Analysis - 2 -
> Final Project Winter 2009
> • Generate the two normal pdfs with function normpdf, just as previously. Plot the pdfs into
> a single figure.
> • Calculate the weighted sum of these two pdfs, which is the GM-pdf. Plot the GM-pdf with
> the function plot – does it look like the weighted sum of two normal distributions?


A hint. You can do this with a combination of erf() and interp1()

Subject: Gaussian Mixture

From: Jose Valerio

Date: 25 Mar, 2009 16:20:17

Message: 5 of 10

"Matt " <xys@whatever.com> wrote in message <gqdh51$qju$1@fred.mathworks.com>...
> "Jose Valerio" <lapenda@gmail.com> wrote in message <gqdddi$mfe$1@fred.mathworks.com>...
> > Peter Perkins <Peter.Perkins@MathRemoveThisWorks.com> wrote in message <gqdc34$go5$1@fred.mathworks.com>...
> > > Jose Valerio wrote:
> > >
> > > > I have to generate 1000 samples distributed according to Gaussian Mixture distribution. And it has to consist of the sum of two distribution N(-2,1) and (2,1). weights of 0.4 and 0.6
> > > >
> > > > I know that there is a method to generate the random numbers based on the inverse function of the cdf of that distribution and that's what I need to use, but I just can't figure it out.
> > >
> > > You _can_ do that if that's what the homework assignment asks for, but there's a more obvious way. Consider what a mixture model is: a random value chosen from one of two probability distributions with (in your case) probabilities .4 and .6. If that sounds like a constructive definition useful for generating a random value from the mixture, it is.
> > >
> > > Hope this helps.
> >
> > Ok, this is the whole asignment, but I can't find anything on my lectures that can help much with it. I've tried different ways and I still don't get it, maybe if it was worded a different way I would have a better chance of completing it.
> >
> > A method to generate random numbers from any distribution is based on the inverse function of
> > the cdf of that distribution (see the below figure to understand the principle of the method).
> > Use the method to generate 1000 samples distributed according to a Gaussian Mixture -
> > distribution (GM), which consist of the weighted sum of two normal distributions N(-2,1) and
> > N(2,1), with the corresponding weights of 0.4 and 0.6.
> > Application For Data Analysis - 2 -
> > Final Project Winter 2009
> > • Generate the two normal pdfs with function normpdf, just as previously. Plot the pdfs into
> > a single figure.
> > • Calculate the weighted sum of these two pdfs, which is the GM-pdf. Plot the GM-pdf with
> > the function plot – does it look like the weighted sum of two normal distributions?
>
>
> A hint. You can do this with a combination of erf() and interp1()

i have to use normpdf().
So what I did was,
x=-50:0.1:50 %These are my 1000 samples, or I could just do ramdom numbers
y=normpdf(x,-2,1); %This is normal distributions N(-2,1)??? Here is where I'm a little confuse. What does the N(-2,1) means?? is it a range od the mean -2 and Variace 1???
plot(x,y)

Subject: Gaussian Mixture

From: Matt

Date: 25 Mar, 2009 17:41:01

Message: 6 of 10

"Jose Valerio" <lapenda@gmail.com> wrote in message <gqdlk1$l78$1@fred.mathworks.com>...
> "Matt " <xys@whatever.com> wrote in message <gqdh51$qju$1@fred.mathworks.com>...
> > "Jose Valerio" <lapenda@gmail.com> wrote in message <gqdddi$mfe$1@fred.mathworks.com>...
> > > Peter Perkins <Peter.Perkins@MathRemoveThisWorks.com> wrote in message <gqdc34$go5$1@fred.mathworks.com>...
> > > > Jose Valerio wrote:
> > > >
> > > > > I have to generate 1000 samples distributed according to Gaussian Mixture distribution. And it has to consist of the sum of two distribution N(-2,1) and (2,1). weights of 0.4 and 0.6
> > > > >
> > > > > I know that there is a method to generate the random numbers based on the inverse function of the cdf of that distribution and that's what I need to use, but I just can't figure it out.
> > > >
> > > > You _can_ do that if that's what the homework assignment asks for, but there's a more obvious way. Consider what a mixture model is: a random value chosen from one of two probability distributions with (in your case) probabilities .4 and .6. If that sounds like a constructive definition useful for generating a random value from the mixture, it is.
> > > >
> > > > Hope this helps.
> > >
> > > Ok, this is the whole asignment, but I can't find anything on my lectures that can help much with it. I've tried different ways and I still don't get it, maybe if it was worded a different way I would have a better chance of completing it.
> > >
> > > A method to generate random numbers from any distribution is based on the inverse function of
> > > the cdf of that distribution (see the below figure to understand the principle of the method).
> > > Use the method to generate 1000 samples distributed according to a Gaussian Mixture -
> > > distribution (GM), which consist of the weighted sum of two normal distributions N(-2,1) and
> > > N(2,1), with the corresponding weights of 0.4 and 0.6.
> > > Application For Data Analysis - 2 -
> > > Final Project Winter 2009
> > > • Generate the two normal pdfs with function normpdf, just as previously. Plot the pdfs into
> > > a single figure.
> > > • Calculate the weighted sum of these two pdfs, which is the GM-pdf. Plot the GM-pdf with
> > > the function plot – does it look like the weighted sum of two normal distributions?
> >
> >
> > A hint. You can do this with a combination of erf() and interp1()
>
> i have to use normpdf().

I think you mean normcdf(). The instructions you posted are all about CDF's

> So what I did was,
> x=-50:0.1:50 %These are my 1000 samples, or I could just do ramdom numbers
> y=normpdf(x,-2,1); %This is normal distributions N(-2,1)??? Here is where I'm a little confuse. What does the N(-2,1) means?? is it a range od the mean -2 and Variace 1???
> plot(x,y)


N(-2,1) means a Gaussian distribution with mean -2 and variance 1

Subject: Gaussian Mixture

From: Jose Valerio

Date: 25 Mar, 2009 19:15:05

Message: 7 of 10

>
> N(-2,1) means a Gaussian distribution with mean -2 and variance 1
Thanks, that help a little.

So what I have up to now is:
x = -2:0.01:2;
y = normpdf(x,-2,1);
plot(x,y)
xi = normpdf(x,2,1);
hold on
plot(x,xi)
figure
plot(y,xi)

I think I don't know what I'm doing, I'm so confused

Subject: Gaussian Mixture

From: Matt

Date: 25 Mar, 2009 19:38:01

Message: 8 of 10

"Jose Valerio" <lapenda@gmail.com> wrote in message <gqdvrp$6c1$1@fred.mathworks.com>...

> plot(y,xi)

I don't understand your last line. Why is 'y' plotted on the x-axis?
 

Subject: Gaussian Mixture

From: Jose Valerio

Date: 25 Mar, 2009 19:47:02

Message: 9 of 10

"Matt " <xys@whatever.com> wrote in message <gqe16p$6lh$1@fred.mathworks.com>...
> "Jose Valerio" <lapenda@gmail.com> wrote in message <gqdvrp$6c1$1@fred.mathworks.com>...
>
> > plot(y,xi)
>
> I don't understand your last line. Why is 'y' plotted on the x-axis?
>

Never mind the last line. It should be the other way. Now I'm up to here:

x = -5:0.1:5;
y = normpdf(x,-2,1);
plot(x,y)
xi = normpdf(x,2,1);
hold on
plot(x,xi)

r = y + xi;
figure
plot(r)

figure
cdf_sum = cumsum(y + xi);
plot(cdf_sum)

????

Subject: Gaussian Mixture

From: liu s.h

Date: 1 Jul, 2009 09:12:01

Message: 10 of 10

your code maybe correct!

I want to ask if you have done this problem?

Or you my have interest to talk about it?

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us