7 # regression data (size n*p, where n is the number of observations,
8 # and p is the number of regressors)
10 # response data (size n*m, where n is the number of observations,
11 # and m is the number of responses)
14 # Optionally user defined (some default values)
16 # power in the penalty
18 # minimum number of iterations for EM algorithm
20 # maximum number of iterations for EM algorithm
22 # threshold for stopping EM algorithm
24 # minimum number of components in the mixture
26 # maximum number of components in the mixture
31 # Computed through the workflow
33 # initialisation for the reparametrized conditional mean parameter
35 # initialisation for the reparametrized variance parameter
37 # initialisation for the proportions
39 # initialisation for the allocations probabilities in each component
41 # values for the regularization parameter grid
43 # je ne crois pas vraiment qu'il faille les mettre en sortie, d'autant plus qu'on construit
44 # une matrice A1 et A2 pour chaque k, et elles sont grandes, donc ca coute un peu cher ...
47 # collection of estimations for the reparametrized conditional mean parameters
49 # collection of estimations for the reparametrized variance parameters
51 # collection of estimations for the proportions parameters
59 #######################
60 #initialize main object
61 #######################
62 initialize = function(X,Y,...)
64 "Initialize Valse object"
70 gamma <<- ifelse (hasArg("gamma"), gamma, 1.)
71 mini <<- ifelse (hasArg("mini"), mini, as.integer(5))
72 maxi <<- ifelse (hasArg("maxi"), maxi, as.integer(10))
73 eps <<- ifelse (hasArg("eps"), eps, 1e-6)
74 kmin <<- ifelse (hasArg("kmin"), kmin, as.integer(2))
75 kmax <<- ifelse (hasArg("kmax"), kmax, as.integer(3))
76 rangmin <<- ifelse (hasArg("rangmin"), rangmin, as.integer(2))
77 rangmax <<- ifelse (hasArg("rangmax"), rangmax, as.integer(3))
80 ##################################
81 #core workflow: compute all models
82 ##################################
84 initParameters = function(k)
86 "Parameters initialization"
88 #smallEM initializes parameters by k-means and regression model in each component,
89 #doing this 20 times, and keeping the values maximizing the likelihood after 10
90 #iterations of the EM algorithm.
91 init = initSmallEM(k,X,Y,eps)
98 computeGridLambda = function()
100 "computation of the regularization grid"
101 #(according to explicit formula given by EM algorithm)
103 gridLambda <<- gridLambda(phiInit,rhoInit,piInit,tauInit,X,Y,gamma,mini,maxi,eps)
106 computeRelevantParameters = function()
108 "Compute relevant parameters"
110 #select variables according to each regularization parameter
111 #from the grid: A1 corresponding to selected variables, and
112 #A2 corresponding to unselected variables.
113 params = selectiontotale(
114 phiInit,rhoInit,piInit,tauInit,mini,maxi,gamma,gridLambda,X,Y,seuil,eps)
121 runProcedure1 = function()
123 "Run procedure 1 [EMGLLF]"
125 #compute parameter estimations, with the Maximum Likelihood
126 #Estimator, restricted on selected variables.
127 return ( constructionModelesLassoMLE(
128 phiInit,rhoInit,piInit,tauInit,mini,maxi,gamma,gridLambda,X,Y,seuil,eps,A1,A2) )
131 runProcedure2 = function()
133 "Run procedure 2 [EMGrank]"
135 #compute parameter estimations, with the Low Rank
136 #Estimator, restricted on selected variables.
137 return ( constructionModelesLassoRank(Pi,Rho,mini,maxi,X,Y,eps,
138 A1,rangmin,rangmax) )
143 "main loop: over all k and all lambda"
145 # Run the all procedure, 1 with the
146 #maximum likelihood refitting, and 2 with the Low Rank refitting.
154 computeRelevantParameters()
170 Phi = array(0., dim=c(p,m,kmax,dim(Phi2)[4]+dim(r1$phi)[4]))
171 Phi[,,1:(dim(Phi2)[3]),1:(dim(Phi2)[4])] = Phi2
172 Phi[,,1:k,dim(Phi2)[4]+1] = r1$phi
173 Rho = array(0., dim=c(m,m,kmax,dim(Rho2)[4]+dim(r1$rho)[4]))
174 Rho[,,1:(dim(Rho2)[3]),1:(dim(Rho2)[4])] = Rho2
175 Rho[,,1:k,dim(Rho2)[4]+1] = r1$rho
176 Pi = array(0., dim=c(kmax,dim(Pi2)[2]+dim(r1$pi)[2]))
177 Pi[1:nrow(Pi2),1:ncol(Pi2)] = Pi2
178 Pi[1:k,ncol(Pi2)+1] = r1$pi
182 phi = runProcedure2()$phi
184 if (dim(Phi2)[1] == 0)
190 Phi = zeros(p,m,kmax,size(Phi2,4)+size(phi,4))
192 Phi(:,:,1:size(Phi2,3),1:size(Phi2,4)) = Phi2
193 Phi(:,:,1:k,size(Phi2,4)+1:end) = phi
199 ##################################################
200 #TODO: pruning: select only one (or a few best ?!) model
201 ##################################################
203 # function[model] selectModel(