- # Update gam[,]; use log to avoid numerical problems
- logGam <- sapply(1:k, function(r) {
- log(piLambda[r]) + log(detRho[r]) - 0.5 *
- sum((Y[i, ] %*% rhoLambda[, , r] - X[i, ] %*% phiLambda[, , r])^2)
- })
-
- logGam <- logGam - max(logGam) #adjust without changing proportions
- gam[i, ] <- exp(logGam)
- norm_fact <- sum(gam[i, ])
- gam[i, ] <- gam[i, ] / norm_fact
- sumLogLLH <- sumLogLLH + log(norm_fact) - log((2 * base::pi)^(m/2))
+ for (r in 1:length(piLambda))
+ {
+ sqNorm2 <- sum((Y[i, ] %*% rhoLambda[, , r] - X[i, ] %*% phiLambda[, , r])^2)
+ Gam[i, r] <- piLambda[r] * exp(-0.5 * sqNorm2) * det(rhoLambda[, , r])
+ }