www.gusucode.com > stats 源码程序 matlab案例代码 > stats/RegularizeGaussianMixtureModelEstimationExample.m
%% Regularize Gaussian Mixture Model Estimation %% % Generate data from a mixture of two bivariate Gaussian distributions. % Create a third predictor that is the sum of the first and second % predictors. mu1 = [1 2]; Sigma1 = [1 0; 0 1]; mu2 = [3 4]; Sigma2 = [0.5 0; 0 0.5]; rng(3); % For reproducibility X1 = [mvnrnd(mu1,Sigma1,100);mvnrnd(mu2,Sigma2,100)]; X = [X1,X1(:,1)+X1(:,2)]; %% % The columns of |X| are linearly dependent. This can cause ill-conditioned % covariance estimates. %% % Fit a Gaussian mixture model to the data. You can use |try| / |catch| % statements to help manage error messages. rng(1); % Reset seed for common start values try GMModel = fitgmdist(X,2) catch exception disp('There was an error fitting the Gaussian mixture model') error = exception.message end %% % The covariance estimates are ill-conditioned. Consequently, optimization % stops and an error appears. %% % Fit a Gaussian mixture model again, but use regularization. rng(3); % Reset seed for common start values GMModel = fitgmdist(X,2,'RegularizationValue',0.1) %% % In this case, the algorithm converges to a solution due to % regularization.