- # if (length(col.sel) == 1)
- # {
- # delta <- (Y %*% rhoLambda[, , r] - (X[, col.sel] %*% t(phiLambda[col.sel, , r])))
- # } else delta <- (Y %*% rhoLambda[, , r] - (X[, col.sel] %*% phiLambda[col.sel, , r]))
- # densite <- densite + piLambda[r] * det(rhoLambda[, , r])/(sqrt(2 * base::pi))^m *
- # exp(-rowSums(delta^2)/2)
+ # # 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 -> change the LLH
+ # gam <- exp(logGam)
+ # norm_fact <- sum(gam)
+ # sumLogLLH <- sumLogLLH + log(norm_fact) - m/2* log(2 * base::pi)