add comment in constructionMdodelesLassoMLE.R
[valse.git] / .Rproj.user / 40465803 / sdb / s-B9318FF6 / 46694A18
1 {
2 "collab_server" : "",
3 "contents" : "#' Main function\n#'\n#' @param X matrix of covariates (of size n*p)\n#' @param Y matrix of responses (of size n*m)\n#' @param procedure among 'LassoMLE' or 'LassoRank'\n#' @param selecMod method to select a model among 'SlopeHeuristic', 'BIC', 'AIC'\n#' @param gamma integer for the power in the penaly, by default = 1\n#' @param mini integer, minimum number of iterations in the EM algorithm, by default = 10\n#' @param maxi integer, maximum number of iterations in the EM algorithm, by default = 100\n#' @param eps real, threshold to say the EM algorithm converges, by default = 1e-4\n#' @param kmin integer, minimum number of clusters, by default = 2\n#' @param kmax integer, maximum number of clusters, by default = 10\n#' @param rang.min integer, minimum rank in the low rank procedure, by default = 1\n#' @param rang.max integer, maximum rank in the\n#' @return a list with estimators of parameters\n#' @export\n#-----------------------------------------------------------------------\nvalse = function(X,Y,procedure,selecMod,gamma = 1,mini = 10,\n maxi = 100,eps = 1e-4,kmin = 2,kmax = 10,\n rang.min = 1,rang.max = 10) {\n ##################################\n #core workflow: compute all models\n ##################################\n \n p = dim(phiInit)[1]\n m = dim(phiInit)[2]\n \n print(\"main loop: over all k and all lambda\")\n for (k in kmin:kmax)\n {\n print(k)\n \n print(\"Parameters initialization\")\n #smallEM initializes parameters by k-means and regression model in each component,\n #doing this 20 times, and keeping the values maximizing the likelihood after 10\n #iterations of the EM algorithm.\n init = initSmallEM(k, X, Y)\n phiInit <<- init$phiInit\n rhoInit <<- init$rhoInit\n piInit\t<<- init$piInit\n gamInit <<- init$gamInit\n \n gridLambda <<- gridLambda(phiInit, rhoInit, piInit, tauInit, X, Y, gamma, mini, maxi, eps)\n \n print(\"Compute relevant parameters\")\n #select variables according to each regularization parameter\n #from the grid: A1 corresponding to selected variables, and\n #A2 corresponding to unselected variables.\n params = selectiontotale(phiInit,rhoInit,piInit,tauInit,\n mini,maxi,gamma,gridLambda,\n X,Y,thresh,eps)\n A1 <<- params$A1\n A2 <<- params$A2\n Rho <<- params$Rho\n Pi <<- params$Pi\n \n if (procedure == 'LassoMLE') {\n print('run the procedure Lasso-MLE')\n #compute parameter estimations, with the Maximum Likelihood\n #Estimator, restricted on selected variables.\n model = constructionModelesLassoMLE(\n phiInit, rhoInit,piInit,tauInit,mini,maxi,\n gamma,gridLambda,X,Y,thresh,eps,A1,A2)\n ################################################\n ### Regarder la SUITE\n r1 = runProcedure1()\n Phi2 = Phi\n Rho2 = Rho\n Pi2 = Pi\n \n if (is.null(dim(Phi2)))\n #test was: size(Phi2) == 0\n {\n Phi[, , 1:k] <<- r1$phi\n Rho[, , 1:k] <<- r1$rho\n Pi[1:k,] <<- r1$pi\n } else\n {\n Phi <<-\n array(0., dim = c(p, m, kmax, dim(Phi2)[4] + dim(r1$phi)[4]))\n Phi[, , 1:(dim(Phi2)[3]), 1:(dim(Phi2)[4])] <<- Phi2\n Phi[, , 1:k, dim(Phi2)[4] + 1] <<- r1$phi\n Rho <<-\n array(0., dim = c(m, m, kmax, dim(Rho2)[4] + dim(r1$rho)[4]))\n Rho[, , 1:(dim(Rho2)[3]), 1:(dim(Rho2)[4])] <<- Rho2\n Rho[, , 1:k, dim(Rho2)[4] + 1] <<- r1$rho\n Pi <<- array(0., dim = c(kmax, dim(Pi2)[2] + dim(r1$pi)[2]))\n Pi[1:nrow(Pi2), 1:ncol(Pi2)] <<- Pi2\n Pi[1:k, ncol(Pi2) + 1] <<- r1$pi\n }\n } else {\n print('run the procedure Lasso-Rank')\n #compute parameter estimations, with the Low Rank\n #Estimator, restricted on selected variables.\n model = constructionModelesLassoRank(Pi, Rho, mini, maxi, X, Y, eps,\n A1, rank.min, rank.max)\n \n ################################################\n ### Regarder la SUITE \n phi = runProcedure2()$phi\n Phi2 = Phi\n if (dim(Phi2)[1] == 0)\n {\n Phi[, , 1:k,] <<- phi\n } else\n {\n Phi <<- array(0, dim = c(p, m, kmax, dim(Phi2)[4] + dim(phi)[4]))\n Phi[, , 1:(dim(Phi2)[3]), 1:(dim(Phi2)[4])] <<- Phi2\n Phi[, , 1:k,-(1:(dim(Phi2)[4]))] <<- phi\n }\n }\n }\n print('Model selection')\n if (selecMod == 'SlopeHeuristic') {\n \n } else if (selecMod == 'BIC') {\n \n } else if (selecMod == 'AIC') {\n \n }\n}\n",
4 "created" : 1488803392297.000,
5 "dirty" : false,
6 "encoding" : "UTF-8",
7 "folds" : "",
8 "hash" : "360251119",
9 "id" : "46694A18",
10 "lastKnownWriteTime" : 1487870307,
11 "last_content_update" : 1487870307,
12 "path" : "~/valse/R/valse.R",
13 "project_path" : "R/valse.R",
14 "properties" : {
15 "tempName" : "Untitled1"
16 },
17 "relative_order" : 3,
18 "source_on_save" : false,
19 "source_window" : "",
20 "type" : "r_source"
21 }