EMGMM

Expectation-Maximization Algorithm for Gaussian mixture model.


 
 Synopsis:
  model = emgmm(X)
  model = emgmm(X,options)
  model = emgmm(X,options,init_model)

 Description:
  This function implements the Expectation-Maximization algorithm 
  (EM) [Schles68][DLR77] which computes the maximum-likelihood 
  estimate of the paramaters of the Gaussian mixture model (GMM). 
  The EM algorithm is an iterative procedure which monotonically 
  increases log-likelihood of the current estimate until it reaches 
  a local optimum. 

  The number of components of the GMM is given in options.ncomp 
  (default 2).

  The following three stopping are condition used:
   1. Improvement of the log-likelihood is less than given
      threshold
                logL(t+1)  - logL(t) < options.eps_logL
   2. Change of the squared differences of a estimated posteriory 
      probabilities is less than given threshold
               ||alpha(t+1) - alpha(t)||^2 < options.eps_alpha
   3. Number of iterations exceeds given threshold.
               t >= options.tmax 

  The type of estimated covariance matrices is optional:
    options.cov_type = 'full'      full covariance matrix (default)
    options.cov_type = 'diag'      diagonal covarinace matrix
    cov_options.type = 'spherical' spherical covariance matrix

  The initial model (estimate) is selected:
    1. randomly (options.init = 'random') 
    2. using C-means (options.init = 'cmeans')
    3. using the user specified init_model.

 Input:
  X [dim x num_data] Data sample.
  
  options [struct] Control paramaters:
   .ncomp [1x1] Number of components of GMM (default 2).
   .tmax [1x1] Maximal number of iterations (default inf).
   .eps_logL [1x1] Minimal improvement in log-likelihood (default 0).
   .eps_alpha [1x1] Minimal change of Alphas (default 0).
   .cov_type [1x1] Type of estimated covarince matrices (see above).
   .init [string] 'random' use random initial model (default);
                  'cmeans' use K-means to find initial model.
   .verb [1x1] If 1 then info is displayed (default 0).
 
  init_model [struct] Initial model:
   .Mean [dim x ncomp] Mean vectors.
   .Cov [dim x dim x ncomp] Covariance matrices.
   .Priors [1 x ncomp] Weights of mixture components.
   .Alpha [ncomp x num_data] (optional) Distribution of hidden state.
   .t [1x1] (optional) Counter of iterations.

 Output:
  model [struct] Estimated Gaussian mixture model:
   .Mean [dim x ncomp] Mean vectors.
   .Cov [dim x dim x ncomp] Covariance matrices.
   .Prior [1 x ncomp] Weights of mixture components.
   .t [1x1] Number iterations.
   .options [struct] Copy of used options.
   .exitflag [int] 0      ... maximal number of iterations was exceeded.
                   1 or 2 ... EM has converged; indicates which stopping 
                              was used (see above).
  
 Example:
 Note: if EM algorithm does not converge run it again from different
 initial model.

 EM is used to estimate parameters of mixture of 2 Guassians:
  true_model = struct('Mean',[-2 2],'Cov',[1 0.5],'Prior',[0.4 0.6]);
  sample = gmmsamp(true_model, 100);
  estimated_model = emgmm(sample.X,struct('ncomp',2,'verb',1));

  figure; ppatterns(sample.X);
  h1=pgmm(true_model,struct('color','r'));
  h2=pgmm(estimated_model,struct('color','b'));
  legend([h1(1) h2(1)],'Ground truth', 'ML estimation'); 
  figure; hold on; xlabel('iterations'); ylabel('log-likelihood');
  plot( estimated_model.logL );

 See also
  MLCGMMMMGAUSSPDFGMMGMMSAMP.


Source: emgmm.m

About: Statistical Patte7rn Recognition Toolbox
(C) 1999-2003, Written by Vojtech Franc and Vaclav Hlavac
Czech Technical University Prague
Faculty of Electrical Engineering
Center for Machine Perception

Modifications:
26-jul-07, VF, inconsistent parameter names 'ncomp and 'num_gauss' removed
26-may-2004, VF, initialization by K-means added
1-may-2004, VF
19-sep-2003, VF
16-mar-2003, VF