diff options
| author | ziejd2 | 2017-09-28 15:04:40 -0500 |
|---|---|---|
| committer | ziejd2 | 2017-09-28 15:04:40 -0500 |
| commit | 8070dc963753142bb86c4ed698d91fd623ed28e7 (patch) | |
| tree | d0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/BNT/examples/static/Zoubin/mfa_cl.m | |
| parent | 7cc31810d53176e805532b2789955f4eedbce6bb (diff) | |
| download | BNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz | |
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning. I am calling this BNW_1.02. It can be accessed at: compbio.uthsc.edu/BNW_1.02
Diffstat (limited to 'sourcecodes/bnt-master/BNT/examples/static/Zoubin/mfa_cl.m')
| -rw-r--r-- | sourcecodes/bnt-master/BNT/examples/static/Zoubin/mfa_cl.m | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/examples/static/Zoubin/mfa_cl.m b/sourcecodes/bnt-master/BNT/examples/static/Zoubin/mfa_cl.m new file mode 100644 index 00000000..b90bab18 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Zoubin/mfa_cl.m @@ -0,0 +1,54 @@ +% function [lik, likv]=mfa_cl(X,Lh,Ph,Mu,Pi); +% +% Calculates log likelihoods of a data set under a mixture of factor +% analysis model. +% +% X - data matrix +% Lh - factor loadings +% Ph - diagonal uniquenesses matrix +% Mu - mean vectors +% Pi - priors +% +% lik - log likelihood of X +% likv - vector of log likelihoods +% +% If 0 or 1 output arguments requested, lik is returned. If 2 output +% arguments requested, [lik likv] is returned. + +function [lik, likv]=mfa_cl(X,Lh,Ph,Mu,Pi); + +N=length(X(:,1)); +D=length(X(1,:)); +K=length(Lh(1,:)); +M=length(Pi); + +if (abs(sum(Pi)-1) > 1e-6) + disp('ERROR: Pi should sum to 1'); + return; +elseif ((size(Lh) ~= [D*M K]) | (size(Ph) ~= [D 1]) | (size(Mu) ~= [M D]) ... + | (size(Pi) ~= [M 1] & size(Pi) ~= [1 M])) + disp('ERROR in input matrix sizes'); + return; +end; + +tiny=exp(-744); +const=(2*pi)^(-D/2); + +I=eye(K); +Phi=1./Ph; +Phid=diag(Phi); +for k=1:M + Lht=Lh((k-1)*D+1:k*D,:); + LP=Phid*Lht; + MM=Phid-LP*inv(I+Lht'*LP)*LP'; + dM=sqrt(det(MM)); + Xk=(X-ones(N,1)*Mu(k,:)); + XM=Xk*MM; + H(:,k)=const*Pi(k)*dM*exp(-0.5*sum((XM.*Xk)'))'; +end; + +Hsum=rsum(H); + +likv=log(Hsum+(Hsum==0)*tiny); +lik=sum(likv); + |
