X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2FEMGrank.R;h=5eea322f6c47c677d843cca24205f0afea64c24a;hb=9ccdd55a1f6e9d409e8ae43b878a5e89c42e20c7;hp=0e68cb4ecdf4dd9f9270557823d76a3875a7f72e;hpb=a3105972158da4773b33d41e1ead65a942c15f80;p=valse.git diff --git a/pkg/R/EMGrank.R b/pkg/R/EMGrank.R index 0e68cb4..5eea322 100644 --- a/pkg/R/EMGrank.R +++ b/pkg/R/EMGrank.R @@ -2,7 +2,6 @@ #' #' Description de EMGrank #' -#' @param phiInit ... #' @param Pi Parametre de proportion #' @param Rho Parametre initial de variance renormalisé #' @param mini Nombre minimal d'itérations dans l'algorithme EM @@ -70,14 +69,14 @@ matricize <- function(X) ite = 1 while (ite<=mini || (ite<=maxi && sumDeltaPhi>tau)) { - #M step: Mise à jour de Beta (et donc phi) + #M step: update for Beta ( and then phi) for(r in 1:k) { - Z_indice = seq_len(n)[Z==r] #indices où Z == r + Z_indice = seq_len(n)[Z==r] #indices where Z == r if (length(Z_indice) == 0) next #U,S,V = SVD of (t(Xr)Xr)^{-1} * t(Xr) * Yr - s = svd( ginv(crossprod(matricize(X[Z_indice,]))) %*% + s = svd( MASS::ginv(crossprod(matricize(X[Z_indice,]))) %*% crossprod(matricize(X[Z_indice,]),matricize(Y[Z_indice,])) ) S = s$d #Set m-rank(r) singular values to zero, and recompose @@ -87,7 +86,7 @@ matricize <- function(X) phi[,,r] = s$u %*% diag(S) %*% t(s$v) %*% Rho[,,r] } - #Etape E et calcul de LLF + #Step E and computation of the loglikelihood sumLogLLF2 = 0 for(i in seq_len(n)) { @@ -107,7 +106,7 @@ matricize <- function(X) } sumLogLLF2 = sumLogLLF2 + log(sumLLF1) } - + LLF = -1/n * sumLogLLF2 #update distance parameter to check algorithm convergence (delta(phi, Phi))