Hi I am trying to create a GM model with 2 components in 1 dimension. I have both the means and covariances as well as the mixing proportions. Ia am getting an error 'The shared diagonal covariance must be a row vector with the same number of columns as MU.' when I try to use gmdistribution function. How do I set sigma up so it can be used in this function. My code is as follows:
mu = [6.25 ;4.33];
sigma = [0.52,0.37];
p = [0.40,0.60];
gm = gmdistribution(mu, sigma, p);

댓글 수: 4

Jeff Miller
Jeff Miller 2021년 1월 26일
Are you sure gmdistribution works for univariate mixtures (2 components in 1 dimension)? I think it might only work for multivariate mixtures.
That may well be the case, I'm not sure why I'm having so much trouble doing this simple task. Do you know any other method of creating a gaussian mixture model with univariate mixtures when I know the properties of each component?
What exactly do you want to do with the model after you make it? For example, if you just want the PDF or CDF of the mixture model, you can get those as the .40/.60 weighted PDFs of the two underlying normal PDFs or CDFs. If you want to generate random numbers, then you pick one distribution or the other with the given probabilities and then pick a random number from that distribution.
Maybe you would find Cupid helpful if you want to do more complicated things with the model. The Cupid routines will compute quite a few different things. For example, using that, the code
normix = Mixture(.4,Normal(6.25,0.52),.6,Normal(4.33,0.37));
[normix.Mean, normix.SD]
normix.PlotDens
produces the following:
ans =
5.098 1.0368
Thanks, yes my goal is to get the CDF of the distribution! How did you combine the CDFs of the 2 underlying component CDFs with a specified weight?

댓글을 달려면 로그인하십시오.

 채택된 답변

Paul
Paul 2021년 1월 28일
편집: Paul 2021년 1월 28일

1 개 추천

Try this:
>> mu=[6.25;4.33];
>> sigma=reshape([0.52 0.37],1,1,2); % third dimesion required, note that sigma are VARIANCES per doc gmdistribution
>> p=[0.4 0.6];
>> gm = gmdistribution(mu,sigma,p);
>> x=(0:.1:15).';
>> plot(x,pdf(gm,x)),grid

댓글 수: 1

The CDF is the integral of the PDF, and integration is linear operation, so the CDFs combine in the same way that the PDFs combine:
plot(x,cdf(gm,x),x,p(1)*cdf('normal',x,mu(1),sqrt(sigma(1)))+p(2)*cdf('normal',x,mu(2),sqrt(sigma(2))),'o'),grid
Note that sqrt(sigma) is needed because the sigmas used to define the gmdistribution are variances, but the cdf('normal', ...) is parameterized by what what we typically mean by sigma, i.e., the sqrt of the variance.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품

릴리스

R2020b

질문:

2021년 1월 26일

댓글:

2021년 2월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by