1 EMGLLF = function(Pi, Rho, mini, maxi, X, Y, tau, rank){
9 phi = array(0, dim=c(p,m,k))
15 Phi = array(0, dim=c(p,m,k))
18 deltaPhiBufferSize = 20
22 while(ite<=mini || (ite<=maxi && sumDeltaPhi>tau)){
23 #M step: Mise à jour de Beta (et donc phi)
26 Z_vec = Z_bin$vec #vecteur 0 et 1 aux endroits o? Z==r
27 Z_indice = Z_bin$indice
28 if(sum(Z_indice) == 0){
31 #U,S,V = SVD of (t(Xr)Xr)^{-1} * t(Xr) * Yr
32 [U,S,V] = svd(ginv(crossprod(X[Z_indice,]))%*% (X[Z_indice,])%*%Y[Z_indice,] )
33 #Set m-rank(r) singular values to zero, and recompose
34 #best rank(r) approximation of the initial product
36 phi[,,r] = U %*%S%*%t(V)%*%Rho[,,r]
39 #Etape E et calcul de LLF
45 dotProduct = tcrossprod(Y[i,]%*%Rho[,,r]-X[i,]%*%phi[,,r])
46 logGamIR = log(Pi[r]) + log(det(Rho[,,r])) - 0.5*dotProduct
47 #Z[i] = index of max (gam[i,])
48 if(logGamIR > maxLogGamIR){
50 maxLogGamIR = logGamIR
52 sumLLF1 = sumLLF1 + exp(logGamIR) / (2*pi)^(m/2)
54 sumLogLLF2 = sumLogLLF2 + log(sumLLF1)
57 LLF = -1/n * sumLogLLF2
59 #update distance parameter to check algorithm convergence (delta(phi, Phi))
60 deltaPhi = c(deltaPhi, max(max(max((abs(phi-Phi))/(1+abs(phi))))) )
61 if(length(deltaPhi) > deltaPhiBufferSize){
62 deltaPhi = deltaPhi[2:length(deltaPhi)]
64 sumDeltaPhi = sum(abs(deltaPhi))
66 #update other local variables
71 return(list(phi=phi, LLF=LLF))