Home > gmmbayestb-v1.0 > gmmbvl_em_init_km.m

gmmbvl_em_init_km

PURPOSE ^

gmmbvl_em_init_km - initialization of EM for Gaussian mixtures

SYNOPSIS ^

function [W,M,R,P,sigma] = gmmbvl_em_init_km(X,k,dyn)

DESCRIPTION ^

gmmbvl_em_init_km - initialization of EM for Gaussian mixtures 

[W,M,R,P,sigma] = gmmbvl_em_init_km(X,k,dyn)
  X - (n x d) matrix of input data 
  k - initial number of Gaussian components
  dyn - if 1 then perform dynamic component allocation else normal EM 
returns
  W - (k x 1) vector of mixing weights
  M - (k x d) matrix of components means
  R - (k x d^2) matrix of Cholesky submatrices of components covariances
  P - (n x k) the posteriors to be used in EM step after initialization
  of priors, means, and components covariance matrices

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [W,M,R,P,sigma] = gmmbvl_em_init_km(X,k,dyn)
0002 %gmmbvl_em_init_km - initialization of EM for Gaussian mixtures
0003 %
0004 %[W,M,R,P,sigma] = gmmbvl_em_init_km(X,k,dyn)
0005 %  X - (n x d) matrix of input data
0006 %  k - initial number of Gaussian components
0007 %  dyn - if 1 then perform dynamic component allocation else normal EM
0008 %returns
0009 %  W - (k x 1) vector of mixing weights
0010 %  M - (k x d) matrix of components means
0011 %  R - (k x d^2) matrix of Cholesky submatrices of components covariances
0012 %  P - (n x k) the posteriors to be used in EM step after initialization
0013 %  of priors, means, and components covariance matrices
0014 
0015 % Nikos Vlassis & Sjaak Verbeek 2002
0016 
0017 %
0018 % $Name:  $
0019 
0020 [n,d] = size(X);
0021 
0022 [tmp,M,tmp2] = gmmbvl_kmeans(X,[],k,0,0,0,0);
0023 [D,I]        = min(gmmbvl_sqdist(M',X'),[],1);
0024 
0025 % mixing weights
0026 W = zeros(k,1);
0027 for i=1:k
0028     W(i) = length(find(I==i))/n;
0029 end
0030 
0031 % covariance matrices
0032 R = zeros(k,d^2);
0033 if k > 1
0034     for j = 1:k
0035         J = find(I==j);
0036         if length(J)>2*d;
0037             Sj = cov(X(J,:));
0038         else
0039             Sj = cov(X);
0040         end
0041         Rj = chol(Sj);
0042         R(j,:) = Rj(:)';
0043     end
0044 else
0045     S = cov(X);
0046     R = chol(S);
0047     R = R(:)';
0048 end
0049 
0050 % compute likelihoods L (n x k)
0051 L = gmmbvl_em_gauss(X,M,R);
0052 
0053 % compute mixture likelihoods F (n x 1)
0054 F = L * W;
0055 F(find(F < eps)) = eps;
0056 
0057 % compute posteriors P (n x k)
0058 P = L .* repmat(W',n,1)  ./ repmat(F,1,k);
0059 
0060 sigma = 0.5 * (4/(d+2)/n)^(1/(d+4)) * sqrt(norm(cov(X)));

Generated on Thu 14-Apr-2005 13:50:22 by m2html © 2003