1 function[phi,rho,pi,LLF,S] = EMGLLF(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,lambda,X,Y,tau)
3 %Get matrices dimensions
6 [p,m,k] = size(phiInit);
15 %Other local variables
16 %NOTE: variables order is always n,p,m,k
35 while ite<=mini || (ite<=maxi && (dist>=tau || dist2>=sqrt(tau)))
41 %Calculs associés à Y et X
44 Y2(:,mm,r) = sqrt(gam(:,r)) .* Y(:,mm);
47 X2(i,:,r) = X(i,:) .* sqrt(gam(i,r));
50 ps2(:,mm,r) = transpose(X2(:,:,r)) * Y2(:,mm,r);
54 Gram2(j,s,r) = dot(X2(:,j,r), X2(:,s,r));
65 b(r) = sum(sum(abs(phi(:,:,r))));
68 a = sum(gam*transpose(log(pi)));
70 %tant que les proportions sont negatives
72 pi2AllPositive = false;
74 pi2 = pi + 0.1^kk * ((1/n)*gam2 - pi);
75 pi2AllPositive = true;
78 pi2AllPositive = false;
85 %t(m) la plus grande valeur dans la grille O.1^k tel que ce soit
86 %décroissante ou constante
87 while (-1/n*a+lambda*((pi.^gamma)*b))<(-1/n*gam2*transpose(log(pi2))+lambda.*(pi2.^gamma)*b) && kk<1000
88 pi2 = pi+0.1^kk*(1/n*gam2-pi);
92 pi = (pi+t*(pi2-pi)) / sum(pi+t*(pi2-pi));
98 ps1(i,mm,r) = Y2(i,mm,r) * dot(X2(i,:,r), phi(:,mm,r));
99 nY21(i,mm,r) = (Y2(i,mm,r))^2;
101 ps(mm,r) = sum(ps1(:,mm,r));
102 nY2(mm,r) = sum(nY21(:,mm,r));
103 rho(mm,mm,r) = ((ps(mm,r)+sqrt(ps(mm,r)^2+4*nY2(mm,r)*(gam2(r))))/(2*nY2(mm,r)));
109 S(j,mm,r) = -rho(mm,mm,r)*ps2(j,mm,r) + dot(phi(1:j-1,mm,r),Gram2(j,1:j-1,r)')...
110 + dot(phi(j+1:p,mm,r),Gram2(j,j+1:p,r)');
111 if abs(S(j,mm,r)) <= n*lambda*(pi(r)^gamma)
114 if S(j,mm,r)> n*lambda*(pi(r)^gamma)
115 phi(j,mm,r)=(n*lambda*(pi(r)^gamma)-S(j,mm,r))/Gram2(j,j,r);
117 phi(j,mm,r)=-(n*lambda*(pi(r)^gamma)+S(j,mm,r))/Gram2(j,j,r);
130 %precompute dot products to numerically adjust their values
131 dotProducts = zeros(k,1);
133 dotProducts(r)= (Y(i,:)*rho(:,:,r)-X(i,:)*phi(:,:,r)) * transpose(Y(i,:)*rho(:,:,r)-X(i,:)*phi(:,:,r));
135 shift = 0.5*min(dotProducts);
137 %compute Gam(:,:) using shift determined above
140 Gam(i,r) = pi(r)*det(rho(:,:,r))*exp(-0.5*dotProducts(r) + shift);
141 sumLLF1 = sumLLF1 + Gam(i,r)/(2*PI)^(m/2);
143 sumLogLLF2 = sumLogLLF2 + log(sumLLF1);
144 sumGamI = sum(Gam(i,:));
146 gam(i,:) = Gam(i,:) / sumGamI;
148 gam(i,:) = zeros(k,1);
154 sumPen = sumPen + pi(r).^gamma .* b(r);
156 LLF(ite) = -(1/n)*sumLogLLF2 + lambda*sumPen;
161 dist = (LLF(ite)-LLF(ite-1))/(1+abs(LLF(ite)));
164 Dist1=max(max(max((abs(phi-Phi))./(1+abs(phi)))));
165 Dist2=max(max(max((abs(rho-Rho))./(1+abs(rho)))));
166 Dist3=max(max((abs(pi-Pi))./(1+abs(Pi))));
167 dist2=max([Dist1,Dist2,Dist3]);