Separate Gaussian mixture distributions of 5 components.

5 views (last 30 days)
I used this code (to fit data by gaussian mixture):
binWidth = 1; %width of the bar equal 1
binCtrs = 0:binWidth:134; % the bars start from 0 to 172. d=729 w=104 93 m=24
figure
counts = hist(Life,binCtrs,'k'); % b k m %hold on; plot(n,count,'ro')
stem(binCtrs,counts,'Marker','none','Color',[0.2 0.2 0.2]);
counts = hist(Life,binCtrs);
nu = length(Life);
prob = counts / (nu * binWidth);
figure
stem(binCtrs,prob,'Marker','none','Color',[0.5 0.5 0.5]);hold on ; % axis([-5 144 0 0.018]);
%%finding the number of components
%using minimum value of AIC
AIC = zeros(1,7);
obj = cell(1,7);
for Kk = 1:7
obj{Kk} = gmdistribution.fit(Life,Kk);
AIC(Kk)= obj{Kk}.AIC;
end
[minAIC,numComponents] = min(AIC);
numComponents %differ 5=4 7=6 11=5
%%finding the parameters of Mixture of gaussian using (gmdisribution.fit)
numComponents=4;
paramEsts= gmdistribution.fit(Life,numComponents)
%mu of mixture of gaussians of 4 components
MU=[paramEsts.mu(1);paramEsts.mu(2);paramEsts.mu(3);paramEsts.mu(4)];
SIGMA=cat(3,[paramEsts.Sigma(1)],[paramEsts.Sigma(2)],[paramEsts.Sigma(3)],[paramEsts.Sigma(4)]);%I wrote it at this
PPp=[paramEsts.PComponents(1),paramEsts.PComponents(2),paramEsts.PComponents(3),paramEsts.PComponents(4)];
objA = gmdistribution(MU,SIGMA,PPp);
xgridss=transpose(linspace(0,134,100)); %using the parameters to draw a line from 0 to 173
plot(xgridss,pdf(objA,xgridss),'g--','linewidth',2); hold on
I want to separate each gaussian component (I use this code):
numComponents5=4;
paramEsts5= gmdistribution.fit(Life,numComponents5)
MU1=[paramEsts5.mu(1)];
SIGMA1=cat(3,[paramEsts5.Sigma(1)]);
PPp1=[paramEsts5.PComponents(1)];
objA1 = gmdistribution(MU1,SIGMA1,PPp1);
xgridss1=transpose(linspace(0,134,100));
MU2=[paramEsts5.mu(2)];
SIGMA2=cat(3,[paramEsts5.Sigma(2)]);
PPp2=[paramEsts5.PComponents(2)];
objA2 = gmdistribution(MU2,SIGMA2,PPp2);
xgridss2=transpose(linspace(0,134,100));
MU3=[paramEsts5.mu(3)];
SIGMA3=cat(3,[paramEsts5.Sigma(3)]);
PPp3=[paramEsts5.PComponents(3)];
objA3 = gmdistribution(MU3,SIGMA3,PPp3);
xgridss3=transpose(linspace(0,134,100));
MU4=[paramEsts5.mu(4)];
SIGMA4=cat(3,[paramEsts5.Sigma(4)]);
PPp4=[paramEsts5.PComponents(4)];
objA4 = gmdistribution(MU4,SIGMA4,PPp4);
xgridss4=transpose(linspace(0,134,100));
% figure
plot(xgridss1,pdf(objA1,xgridss1),'r-','linewidth',2) ; hold on
plot(xgridss2,pdf(objA2,xgridss2),'r-','linewidth',2) ; hold on
plot(xgridss3,pdf(objA3,xgridss3),'r-','linewidth',2) ; hold on
plot(xgridss4,pdf(objA4,xgridss4),'r-','linewidth',2) ; hold on
but the value of each gaussian not the same How I could adjust the code to plot seprate individual components?

Answers (1)

the cyclist
the cyclist on 9 Apr 2017
Do you mean you want each gaussian in a separate plot? Then,
figure
plot(xgridss1,pdf(objA1,xgridss1),'r-','linewidth',2);
figure
plot(xgridss2,pdf(objA2,xgridss2),'r-','linewidth',2);
figure
plot(xgridss3,pdf(objA3,xgridss3),'r-','linewidth',2);
figure
plot(xgridss4,pdf(objA4,xgridss4),'r-','linewidth',2);
Or perhaps use the subplot command.
If that is not what you mean, then it is not clear (to me) what you want.
  2 Comments
Amr Hashem
Amr Hashem on 9 Apr 2017
Edited: Amr Hashem on 10 Apr 2017
I am sorry if my question is not clear.
I have this (Gaussian mixture of 5 components)
and I want to get something like this:
which is five separate normal distributions in the same scale/Area (mu and sigma) fitting the data.
Thanks in advance.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!