-
- #Step E and computation of the loglikelihood
- sumLogLLF2 = 0
- for(i in seq_len(n))
- {
- sumLLF1 = 0
- maxLogGamIR = -Inf
- for (r in seq_len(k))
- {
- dotProduct = tcrossprod(Y[i,]%*%Rho[,,r]-X[i,]%*%phi[,,r])
- logGamIR = log(Pi[r]) + log(det(Rho[,,r])) - 0.5*dotProduct
- #Z[i] = index of max (gam[i,])
- if(logGamIR > maxLogGamIR)
- {
- Z[i] = r
- maxLogGamIR = logGamIR
- }
- sumLLF1 = sumLLF1 + exp(logGamIR) / (2*pi)^(m/2)
- }
- sumLogLLF2 = sumLogLLF2 + log(sumLLF1)
- }
-
- LLF = -1/n * sumLogLLF2
-
- #update distance parameter to check algorithm convergence (delta(phi, Phi))
- deltaPhi = c( deltaPhi, max( (abs(phi-Phi)) / (1+abs(phi)) ) ) #TODO: explain?
- if (length(deltaPhi) > deltaPhiBufferSize)
- deltaPhi = deltaPhi[2:length(deltaPhi)]
- sumDeltaPhi = sum(abs(deltaPhi))
-
- #update other local variables
- Phi = phi
- ite = ite+1
+
+ # Step E and computation of the loglikelihood
+ sumLogLLF2 <- 0
+ for (i in seq_len(n))
+ {
+ sumLLF1 <- 0
+ maxLogGamIR <- -Inf
+ for (r in seq_len(k))
+ {
+ dotProduct <- tcrossprod(Y[i, ] %*% Rho[, , r] - X[i, ] %*% phi[,
+ , r])
+ logGamIR <- log(Pi[r]) + log(det(Rho[, , r])) - 0.5 * dotProduct
+ # Z[i] = index of max (gam[i,])
+ if (logGamIR > maxLogGamIR)
+ {
+ Z[i] <- r
+ maxLogGamIR <- logGamIR
+ }
+ sumLLF1 <- sumLLF1 + exp(logGamIR)/(2 * pi)^(m/2)
+ }
+ sumLogLLF2 <- sumLogLLF2 + log(sumLLF1)
+ }
+
+ LLF <- -1/n * sumLogLLF2
+
+ # update distance parameter to check algorithm convergence (delta(phi, Phi))
+ deltaPhi <- c(deltaPhi, max((abs(phi - Phi))/(1 + abs(phi)))) #TODO: explain?
+ if (length(deltaPhi) > deltaPhiBufferSize)
+ deltaPhi <- deltaPhi[2:length(deltaPhi)]
+ sumDeltaPhi <- sum(abs(deltaPhi))
+
+ # update other local variables
+ Phi <- phi
+ ite <- ite + 1