Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/KPMstats/clg_Mstep_simple.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 [mu, B] = clg_Mstep_simple(w, Y, YY, YTY, X, XX, XY) | |
2 % CLG_MSTEP_SIMPLE Same as CLG_MSTEP, but doesn;t estimate Sigma, so is slightly faster | |
3 % function [mu, B] = clg_Mstep_simple(w, Y, YY, YTY, X, XX, XY) | |
4 % | |
5 % See clg_Mstep for details. | |
6 % Unlike clg_Mstep, there are no optional arguments, which are slow to process | |
7 % if this function is inside a tight loop. | |
8 | |
9 [Ysz Q] = size(Y); | |
10 | |
11 if isempty(X) % no regression | |
12 %B = []; | |
13 B2 = zeros(Ysz, 1, Q); | |
14 for i=1:Q | |
15 B(:,:,i) = B2(:,1:0,i); % make an empty array of size Ysz x 0 x Q | |
16 end | |
17 [mu, Sigma] = mixgauss_Mstep(w, Y, YY, YTY); | |
18 return; | |
19 end | |
20 | |
21 N = sum(w); | |
22 %YY = YY + cov_prior; % regularize the scatter matrix | |
23 | |
24 % Set any zero weights to one before dividing | |
25 % This is valid because w(i)=0 => Y(:,i)=0, etc | |
26 w = w + (w==0); | |
27 | |
28 Xsz = size(X,1); | |
29 % Append 1 to X to get Z | |
30 ZZ = zeros(Xsz+1, Xsz+1, Q); | |
31 ZY = zeros(Xsz+1, Ysz, Q); | |
32 for i=1:Q | |
33 ZZ(:,:,i) = [XX(:,:,i) X(:,i); | |
34 X(:,i)' w(i)]; | |
35 ZY(:,:,i) = [XY(:,:,i); | |
36 Y(:,i)']; | |
37 end | |
38 | |
39 mu = zeros(Ysz, Q); | |
40 B = zeros(Ysz, Xsz, Q); | |
41 for i=1:Q | |
42 % eqn 9 | |
43 if rcond(ZZ(:,:,i)) < 1e-10 | |
44 sprintf('clg_Mstep warning: ZZ(:,:,%d) is ill-conditioned', i); | |
45 %probably because there are too few cases for a high-dimensional input | |
46 ZZ(:,:,i) = ZZ(:,:,i) + 1e-5*eye(Xsz+1); | |
47 end | |
48 %A = ZY(:,:,i)' * inv(ZZ(:,:,i)); | |
49 A = (ZZ(:,:,i) \ ZY(:,:,i))'; | |
50 B(:,:,i) = A(:, 1:Xsz); | |
51 mu(:,i) = A(:, Xsz+1); | |
52 end |