From: Benjamin Auder Date: Fri, 14 Apr 2017 15:49:38 +0000 (+0200) Subject: attempt to fix ugly code... X-Git-Url: https://git.auder.net/img/js/css/vendor/current/gitweb.css?a=commitdiff_plain;h=f7e157cdbcf2d60224c2d6773da9c698174e9aee;p=valse.git attempt to fix ugly code... --- diff --git a/pkg/R/EMGLLF.R b/pkg/R/EMGLLF.R index 5ef231e..ee7a4fc 100644 --- a/pkg/R/EMGLLF.R +++ b/pkg/R/EMGLLF.R @@ -145,11 +145,18 @@ EMGLLF <- function(phiInit, rhoInit, piInit, gamInit, mini, maxi, gamma, lambda, { S[j, mm, r] <- -rho[mm, mm, r] * ps2[j, mm, r] + sum(phi[-j, mm, r] * Gram2[j, -j, r]) - if (abs(S[j, mm, r]) <= n * lambda * (pi[r]^gamma)) - phi[j, mm, r] <- 0 else if (S[j, mm, r] > n * lambda * (pi[r]^gamma)) + if (abs(S[j, mm, r]) <= n * lambda * (pi[r]^gamma)) + { + phi[j, mm, r] <- 0 + } else if (S[j, mm, r] > n * lambda * (pi[r]^gamma)) + { phi[j, mm, r] <- (n * lambda * (pi[r]^gamma) - S[j, mm, r])/Gram2[j, - j, r] else phi[j, mm, r] <- -(n * lambda * (pi[r]^gamma) + S[j, mm, r])/Gram2[j, - j, r] + j, r] + } else + { + phi[j, mm, r] <- -(n * lambda * (pi[r]^gamma) + S[j, mm, r])/Gram2[j, + j, r] + } } } } @@ -162,11 +169,8 @@ EMGLLF <- function(phiInit, rhoInit, piInit, gamInit, mini, maxi, gamma, lambda, for (i in 1:n) { # Update gam[,] - for (r in 1:k) - { - gam1[i, r] <- pi[r] * exp(-0.5 * sum((Y[i, ] %*% rho[, , r] - X[i, - ] %*% phi[, , r])^2)) * detRho[r] - } + for (r in 1:k) gam1[i, r] <- pi[r] * exp(-0.5 * sum((Y[i, ] %*% rho[, + , r] - X[i, ] %*% phi[, , r])^2)) * detRho[r] } gam <- gam1/rowSums(gam1) sumLogLLH <- sum(log(rowSums(gam)) - log((2 * base::pi)^(m/2)))