gmclasslikelihood.m

来自「混合高斯模型 对于给定的数据」· M 代码 · 共 27 行

M
27
字号
function ll = GMClassLikelihood(mixture, Y)
% ll = GMClassLikelihood(class, Y)
% GMClassLikelihood  calculate the log-likelihood of data vectors assuming
% they are generated by the given Gaussian Mixture
% 
%     mixture: a structure representing a Gaussian mixture
%     Y: a NxM matrix, each row is an observation vector of dimension M
% 
%     ll: a Nx1 matrix with the n-th entry returning the log-likelihood of the 
%        n-th observation
%

   [N, M] = size(Y);
   K = mixture.K;
   pnk=zeros(N,K);            
   for k=1:K
      Y1=Y-ones(N,1)*mixture.cluster(k).mu';
      Y2=-0.5*Y1*mixture.cluster(k).invR;
      pnk(:,k) = dot(Y1,Y2,2)+mixture.cluster(k).const;
   end
   llmax=max(pnk,[],2);
   pnk =exp( pnk-llmax*ones(1,K) );
   pnk = pnk.*(ones(N,1)*[mixture.cluster(:).pb]);
   ss = sum(pnk,2);
   ll = log(ss)+llmax;
end   

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?