www.gusucode.com > stats 源码程序 matlab案例代码 > stats/CreatingAndSimulatingFromGaussianMixtureModelsExample.m
%% Create a Gaussian Mixture Model % This example shows how to create a known, or fully specified, Gaussian % mixture model (GMM) object using <docid:stats_ug.brx1emd-1 % gmdistribution> and by specifying component means, covariances, and % mixture proportions. To create a GMM object by fitting data to a GMM, % see <docid:stats_ug.buqq65e>. %% % Specify the component means, covariances, and mixing proportions for a % two-component mixture of bivariate Gaussian distributions. % Copyright 2015 The MathWorks, Inc. Mu = [1 2;-3 -5]; % Means Sigma = cat(3,[2 0;0 .5],[1 0;0 1]); % Covariances P = ones(1,2)/2; % Mixing proportions %% % The rows of |Mu| correspond to the component mean vectors, and the pages % of |Sigma| correspond to the component covariance matrices. %% % Create the GMM object using |gmdistribution|. gm = gmdistribution(Mu,Sigma,P); %% % Display properties of the GMM. properties = properties(gm) %% % For a description of the properties, see <docid:stats_ug.btdocli % gmdistribution>. To access the value of a property, use dot notation. For % example, access the dimensions of the GMM. dimension = gm.NDimensions %% % Visualize the pdf of the GMM using <docid:stats_ug.brx2uvj-1 pdf> and the % MATLAB(R) function <docid:matlab_ref.f21-756044 ezsurf>. gmPDF = @(x,y)pdf(gm,[x y]); figure; ezsurf(gmPDF,[-10 10],[-10 10]) title('PDF of the GMM'); %% % Visualize the cdf of the GMM using <docid:stats_ug.brx2ulk-1 cdf> and % |ezsurf|. gmCDF = @(x,y)cdf(gm,[x y]); figure ezsurf(@(x,y)cdf(gm,[x y]),[-10 10],[-10 10]) title('CDF of the GMM');