projects
/
valse.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
test auto-indenter
[valse.git]
/
pkg
/
R
/
EMGrank.R
diff --git
a/pkg/R/EMGrank.R
b/pkg/R/EMGrank.R
index
e30b605
..
5eea322
100644
(file)
--- a/
pkg/R/EMGrank.R
+++ b/
pkg/R/EMGrank.R
@@
-2,7
+2,6
@@
#'
#' Description de EMGrank
#'
#'
#' 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
#' @param Pi Parametre de proportion
#' @param Rho Parametre initial de variance renormalisé
#' @param mini Nombre minimal d'itérations dans l'algorithme EM
@@
-22,7
+21,7
@@
EMGrank <- function(Pi, Rho, mini, maxi, X, Y, tau, rank, fast=TRUE)
if (!fast)
{
# Function in R
if (!fast)
{
# Function in R
- return (EMGrank_R(Pi, Rho, mini, maxi, X, Y, tau, rank))
+ return (
.
EMGrank_R(Pi, Rho, mini, maxi, X, Y, tau, rank))
}
# Function in C
}
# Function in C
@@
-47,7
+46,7
@@
matricize <- function(X)
}
# R version - slow but easy to read
}
# R version - slow but easy to read
-EMGrank_R = function(Pi, Rho, mini, maxi, X, Y, tau, rank)
+
.
EMGrank_R = function(Pi, Rho, mini, maxi, X, Y, tau, rank)
{
#matrix dimensions
n = dim(X)[1]
{
#matrix dimensions
n = dim(X)[1]
@@
-70,14
+69,14
@@
EMGrank_R = function(Pi, Rho, mini, maxi, X, Y, tau, rank)
ite = 1
while (ite<=mini || (ite<=maxi && sumDeltaPhi>tau))
{
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)
{
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
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
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
@@
EMGrank_R = function(Pi, Rho, mini, maxi, X, Y, tau, rank)
phi[,,r] = s$u %*% diag(S) %*% t(s$v) %*% Rho[,,r]
}
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))
{
sumLogLLF2 = 0
for(i in seq_len(n))
{
@@
-107,7
+106,7
@@
EMGrank_R = function(Pi, Rho, mini, maxi, X, Y, tau, rank)
}
sumLogLLF2 = sumLogLLF2 + log(sumLLF1)
}
}
sumLogLLF2 = sumLogLLF2 + log(sumLLF1)
}
-
+
LLF = -1/n * sumLogLLF2
#update distance parameter to check algorithm convergence (delta(phi, Phi))
LLF = -1/n * sumLogLLF2
#update distance parameter to check algorithm convergence (delta(phi, Phi))