projects
/
valse.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
merge with remote
[valse.git]
/
pkg
/
R
/
EMGrank.R
diff --git
a/pkg/R/EMGrank.R
b/pkg/R/EMGrank.R
index
db40948
..
4054e25
100644
(file)
--- a/
pkg/R/EMGrank.R
+++ b/
pkg/R/EMGrank.R
@@
-8,7
+8,7
@@
#' @param maxi Nombre maximal d'itérations dans l'algorithme EM
#' @param X Régresseurs
#' @param Y Réponse
#' @param maxi Nombre maximal d'itérations dans l'algorithme EM
#' @param X Régresseurs
#' @param Y Réponse
-#' @param
tau
Seuil pour accepter la convergence
+#' @param
eps
Seuil pour accepter la convergence
#' @param rank Vecteur des rangs possibles
#'
#' @return A list ...
#' @param rank Vecteur des rangs possibles
#'
#' @return A list ...
@@
-16,12
+16,12
@@
#' LLF : log vraisemblance associé à cet échantillon, pour les valeurs estimées des paramètres
#'
#' @export
#' LLF : log vraisemblance associé à cet échantillon, pour les valeurs estimées des paramètres
#'
#' @export
-EMGrank <- function(Pi, Rho, mini, maxi, X, Y,
tau
, rank, fast = TRUE)
+EMGrank <- function(Pi, Rho, mini, maxi, X, Y,
eps
, 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,
eps
, rank))
}
# Function in C
}
# Function in C
@@
-29,7
+29,7
@@
EMGrank <- function(Pi, Rho, mini, maxi, X, Y, tau, rank, fast = TRUE)
p <- ncol(X) #nombre de covariables
m <- ncol(Y) #taille de Y (multivarié)
k <- length(Pi) #nombre de composantes dans le mélange
p <- ncol(X) #nombre de covariables
m <- ncol(Y) #taille de Y (multivarié)
k <- length(Pi) #nombre de composantes dans le mélange
- .Call("EMGrank", Pi, Rho, mini, maxi, X, Y,
tau, rank
, phi = double(p * m * k),
+ .Call("EMGrank", Pi, Rho, mini, maxi, X, Y,
eps, as.integer(rank)
, phi = double(p * m * k),
LLF = double(1), n, p, m, k, PACKAGE = "valse")
}
LLF = double(1), n, p, m, k, PACKAGE = "valse")
}
@@
-43,13
+43,13
@@
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,
eps
, rank)
{
# matrix dimensions
{
# matrix dimensions
- n <-
dim(X)[1]
- p <-
dim(X)[2]
- m <-
dim(Rho)[2]
- k <-
dim(Rho)[3]
+ n <-
nrow(X)
+ p <-
ncol(X)
+ m <-
ncol(Y)
+ k <-
length(Pi)
# init outputs
phi <- array(0, dim = c(p, m, k))
# init outputs
phi <- array(0, dim = c(p, m, k))
@@
-64,7
+64,7
@@
matricize <- function(X)
# main loop
ite <- 1
# main loop
ite <- 1
- while (ite <= mini || (ite <= maxi && sumDeltaPhi >
tau
))
+ while (ite <= mini || (ite <= maxi && sumDeltaPhi >
eps
))
{
# M step: update for Beta ( and then phi)
for (r in 1:k)
{
# M step: update for Beta ( and then phi)
for (r in 1:k)
@@
-73,8
+73,8
@@
matricize <- function(X)
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(MASS::ginv(crossprod(matricize(X[Z_indice, ])))
-
%*%
crossprod(matricize(X[Z_indice, ]), matricize(Y[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 best rank(r) approximation
# of the initial product
S <- s$d
# Set m-rank(r) singular values to zero, and recompose best rank(r) approximation
# of the initial product
@@
-92,7
+92,7
@@
matricize <- function(X)
for (r in seq_len(k))
{
dotProduct <- tcrossprod(Y[i, ] %*% Rho[, , r] - X[i, ] %*% phi[, , r])
for (r in seq_len(k))
{
dotProduct <- tcrossprod(Y[i, ] %*% Rho[, , r] - X[i, ] %*% phi[, , r])
- logGamIR <- log(Pi[r]) + log(det(Rho[, , r])) - 0.5 * dotProduct
+ logGamIR <- log(Pi[r]) + log(
g
det(Rho[, , r])) - 0.5 * dotProduct
# Z[i] = index of max (gam[i,])
if (logGamIR > maxLogGamIR)
{
# Z[i] = index of max (gam[i,])
if (logGamIR > maxLogGamIR)
{