9 # regression data (size n*p, where n is the number of observations,
10 # and p is the number of regressors)
12 # response data (size n*m, where n is the number of observations,
13 # and m is the number of responses)
16 # Optionally user defined (some default values)
18 # power in the penalty
20 # minimum number of iterations for EM algorithm
22 # maximum number of iterations for EM algorithm
24 # threshold for stopping EM algorithm
26 # minimum number of components in the mixture
28 # maximum number of components in the mixture
30 # ranks for the Lasso-Rank procedure
34 # Computed through the workflow
36 # initialisation for the reparametrized conditional mean parameter
38 # initialisation for the reparametrized variance parameter
40 # initialisation for the proportions
42 # initialisation for the allocations probabilities in each component
44 # values for the regularization parameter grid
45 gridLambda = "numeric",
46 # je ne crois pas vraiment qu'il faille les mettre en sortie, d'autant plus qu'on construit
47 # une matrice A1 et A2 pour chaque k, et elles sont grandes, donc ca coute un peu cher ...
50 # collection of estimations for the reparametrized conditional mean parameters
52 # collection of estimations for the reparametrized variance parameters
54 # collection of estimations for the proportions parameters
62 #######################
63 #initialize main object
64 #######################
65 initialize = function(X,Y,...)
67 "Initialize Valse object"
73 gamma <<- ifelse (hasArg("gamma"), gamma, 1.)
74 mini <<- ifelse (hasArg("mini"), mini, as.integer(5))
75 maxi <<- ifelse (hasArg("maxi"), maxi, as.integer(10))
76 eps <<- ifelse (hasArg("eps"), eps, 1e-6)
77 kmin <<- ifelse (hasArg("kmin"), kmin, as.integer(2))
78 kmax <<- ifelse (hasArg("kmax"), kmax, as.integer(3))
79 rank.min <<- ifelse (hasArg("rank.min"), rank.min, as.integer(2))
80 rank.max <<- ifelse (hasArg("rank.max"), rank.max, as.integer(3))
81 thresh <<- 1e-15 #immutable (TODO:?)
84 ##################################
85 #core workflow: compute all models
86 ##################################
88 initParameters = function(k)
90 "Parameters initialization"
92 #smallEM initializes parameters by k-means and regression model in each component,
93 #doing this 20 times, and keeping the values maximizing the likelihood after 10
94 #iterations of the EM algorithm.
95 init = initSmallEM(k,X,Y)
102 computeGridLambda = function()
104 "computation of the regularization grid"
105 #(according to explicit formula given by EM algorithm)
107 gridLambda <<- gridLambda(phiInit,rhoInit,piInit,tauInit,X,Y,gamma,mini,maxi,eps)
110 computeRelevantParameters = function()
112 "Compute relevant parameters"
114 #select variables according to each regularization parameter
115 #from the grid: A1 corresponding to selected variables, and
116 #A2 corresponding to unselected variables.
117 params = selectiontotale(
118 phiInit,rhoInit,piInit,tauInit,mini,maxi,gamma,gridLambda,X,Y,thresh,eps)
125 runProcedure1 = function()
127 "Run procedure 1 [EMGLLF]"
129 #compute parameter estimations, with the Maximum Likelihood
130 #Estimator, restricted on selected variables.
131 return ( constructionModelesLassoMLE(
132 phiInit,rhoInit,piInit,tauInit,mini,maxi,gamma,gridLambda,X,Y,thresh,eps,A1,A2) )
135 runProcedure2 = function()
137 "Run procedure 2 [EMGrank]"
139 #compute parameter estimations, with the Low Rank
140 #Estimator, restricted on selected variables.
141 return ( constructionModelesLassoRank(Pi,Rho,mini,maxi,X,Y,eps,
142 A1,rank.min,rank.max) )
147 "main loop: over all k and all lambda"
149 # Run the whole procedure, 1 with the
150 #maximum likelihood refitting, and 2 with the Low Rank refitting.
158 computeRelevantParameters()
167 if (is.null(dim(Phi2))) #test was: size(Phi2) == 0
169 Phi[,,1:k] <<- r1$phi
170 Rho[,,1:k] <<- r1$rho
174 Phi <<- array(0., dim=c(p,m,kmax,dim(Phi2)[4]+dim(r1$phi)[4]))
175 Phi[,,1:(dim(Phi2)[3]),1:(dim(Phi2)[4])] <<- Phi2
176 Phi[,,1:k,dim(Phi2)[4]+1] <<- r1$phi
177 Rho <<- array(0., dim=c(m,m,kmax,dim(Rho2)[4]+dim(r1$rho)[4]))
178 Rho[,,1:(dim(Rho2)[3]),1:(dim(Rho2)[4])] <<- Rho2
179 Rho[,,1:k,dim(Rho2)[4]+1] <<- r1$rho
180 Pi <<- array(0., dim=c(kmax,dim(Pi2)[2]+dim(r1$pi)[2]))
181 Pi[1:nrow(Pi2),1:ncol(Pi2)] <<- Pi2
182 Pi[1:k,ncol(Pi2)+1] <<- r1$pi
186 phi = runProcedure2()$phi
188 if (dim(Phi2)[1] == 0)
193 Phi <<- array(0., dim=c(p,m,kmax,dim(Phi2)[4]+dim(phi)[4]))
194 Phi[,,1:(dim(Phi2)[3]),1:(dim(Phi2)[4])] <<- Phi2
195 Phi[,,1:k,-(1:(dim(Phi2)[4]))] <<- phi
201 ##################################################
202 #TODO: pruning: select only one (or a few best ?!) model
203 ##################################################
205 # function[model] selectModel(
209 # Give at least the slope heuristic and BIC, and AIC ?