gmmbvl_em_gauss - compute likelihoods for all points and all components L = gmmbvl_em_gauss(X,M,R) X - (n x d) matrix of input data M - (k x d) matrix of components means R - (k x d^2) matrix of Cholesky submatrices of components covariances in vector reshaped format. To get the covariance of component k: Rk = reshape(R(k,:),d,d); S = Rk'*Rk; returns L - (n x k) likelihoods of points x_n belonging to component k
0001 function L = gmmbvl_em_gauss(X,M,R) 0002 %gmmbvl_em_gauss - compute likelihoods for all points and all components 0003 % 0004 %L = gmmbvl_em_gauss(X,M,R) 0005 % X - (n x d) matrix of input data 0006 % M - (k x d) matrix of components means 0007 % R - (k x d^2) matrix of Cholesky submatrices of components covariances 0008 % in vector reshaped format. To get the covariance of component k: 0009 % Rk = reshape(R(k,:),d,d); S = Rk'*Rk; 0010 %returns 0011 % L - (n x k) likelihoods of points x_n belonging to component k 0012 0013 % Nikos Vlassis, 2000 0014 0015 % 0016 % $Name: $ 0017 0018 [n,d] = size(X); 0019 k = size(M,1); 0020 0021 L = zeros(n,k); 0022 for j = 1:k 0023 0024 % Cholesky triangular matrix of component's covariance matrix 0025 Rj = reshape(R(j,:),d,d); 0026 0027 % We need to compute the Mahalanobis distances between all inputs 0028 % and the mean of component j; using the Cholesky form of covariances 0029 % this becomes the Euclidean norm of some new vectors 0030 New = (X - repmat(M(j,:),n,1)) * inv(Rj); 0031 Mah = sum(New.^2,2); 0032 0033 L(:,j) = (2*pi)^(-d/2) / det(Rj) * exp(-0.5*Mah); 0034 end