📄 gmclasslikelihood.m
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -