comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/Zoubin/mfa_cl.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 % function [lik, likv]=mfa_cl(X,Lh,Ph,Mu,Pi);
2 %
3 % Calculates log likelihoods of a data set under a mixture of factor
4 % analysis model.
5 %
6 % X - data matrix
7 % Lh - factor loadings
8 % Ph - diagonal uniquenesses matrix
9 % Mu - mean vectors
10 % Pi - priors
11 %
12 % lik - log likelihood of X
13 % likv - vector of log likelihoods
14 %
15 % If 0 or 1 output arguments requested, lik is returned. If 2 output
16 % arguments requested, [lik likv] is returned.
17
18 function [lik, likv]=mfa_cl(X,Lh,Ph,Mu,Pi);
19
20 N=length(X(:,1));
21 D=length(X(1,:));
22 K=length(Lh(1,:));
23 M=length(Pi);
24
25 if (abs(sum(Pi)-1) > 1e-6)
26 disp('ERROR: Pi should sum to 1');
27 return;
28 elseif ((size(Lh) ~= [D*M K]) | (size(Ph) ~= [D 1]) | (size(Mu) ~= [M D]) ...
29 | (size(Pi) ~= [M 1] & size(Pi) ~= [1 M]))
30 disp('ERROR in input matrix sizes');
31 return;
32 end;
33
34 tiny=exp(-744);
35 const=(2*pi)^(-D/2);
36
37 I=eye(K);
38 Phi=1./Ph;
39 Phid=diag(Phi);
40 for k=1:M
41 Lht=Lh((k-1)*D+1:k*D,:);
42 LP=Phid*Lht;
43 MM=Phid-LP*inv(I+Lht'*LP)*LP';
44 dM=sqrt(det(MM));
45 Xk=(X-ones(N,1)*Mu(k,:));
46 XM=Xk*MM;
47 H(:,k)=const*Pi(k)*dM*exp(-0.5*sum((XM.*Xk)'))';
48 end;
49
50 Hsum=rsum(H);
51
52 likv=log(Hsum+(Hsum==0)*tiny);
53 lik=sum(likv);
54