From: emilie Date: Fri, 17 Mar 2017 14:07:20 +0000 (+0100) Subject: few last things X-Git-Url: https://git.auder.net/img/scripts/%7B%7B%20asset%28%27mixstore/js/current/R.css?a=commitdiff_plain;h=31444abc970b7fe17463bcc916e95846272158db;p=valse.git few last things --- diff --git a/pkg/R/selectiontotale.R b/pkg/R/selectiontotale.R index 7209fed..2cdac38 100644 --- a/pkg/R/selectiontotale.R +++ b/pkg/R/selectiontotale.R @@ -29,7 +29,7 @@ selectiontotale = function(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambd selectedVariables = list() Rho = list() Pi = list() - cpt = 0 + cpt = 1 #Pour chaque lambda de la grille, on calcule les coefficients for (lambdaIndex in 1:length(glambda)){ print(lambdaIndex) @@ -39,14 +39,16 @@ selectiontotale = function(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambd m = dim(phiInit)[2] #selectedVariables: list where element j contains vector of selected variables in [1,m] if (sum(params$phi) != 0){ - cpt = cpt+1 - selectedVariables[[cpt]] = sapply(1:p, function(j) { - #from boolean matrix mxk of selected variables obtain the corresponding boolean m-vector, - #and finally return the corresponding indices - c(seq_len(m)[ apply( abs(params$phi[j,,]) > thresh, 1, any ) ], rep(0, m-length(seq_len(m)[ apply( abs(params$phi[j,,]) > thresh, 1, any ) ] ) )) - }) - Rho[[cpt]] = params$rho - Pi[[cpt]] = params$pi + selectedVariables[[cpt]] = sapply(1:p, function(j) { + #from boolean matrix mxk of selected variables obtain the corresponding boolean m-vector, + #and finally return the corresponding indices + c(seq_len(m)[ apply( abs(params$phi[j,,]) > thresh, 1, any ) ], rep(0, m-length(seq_len(m)[ apply( abs(params$phi[j,,]) > thresh, 1, any ) ] ) )) + }) + if (length(unique(selectedVariables)) == length(selectedVariables)){ + Rho[[cpt]] = params$rho + Pi[[cpt]] = params$pi + cpt = cpt+1 + } } } list("selected"=selectedVariables,"Rho"=Rho,"Pi"=Pi) diff --git a/pkg/R/valse.R b/pkg/R/valse.R index 72e2d4d..9bc1f4a 100644 --- a/pkg/R/valse.R +++ b/pkg/R/valse.R @@ -16,7 +16,7 @@ #' @export #----------------------------------------------------------------------- valse = function(X,Y,procedure = 'LassoMLE',selecMod = 'DDSE',gamma = 1,mini = 10, - maxi = 50,eps = 1e-4,kmin = 2,kmax = 3, + maxi = 50,eps = 1e-4,kmin = 2,kmax = 2, rang.min = 1,rang.max = 10) { ################################## #core workflow: compute all models @@ -45,9 +45,9 @@ valse = function(X,Y,procedure = 'LassoMLE',selecMod = 'DDSE',gamma = 1,mini = 1 source('~/valse/pkg/R/gridLambda.R') grid_lambda <<- gridLambda(phiInit, rhoInit, piInit, gamInit, X, Y, gamma, mini, maxi, eps) - # if (length(grid_lambda)>50){ - # grid_lambda = grid_lambda[seq(1, length(grid_lambda), length.out = 50)] - # } + if (length(grid_lambda)>100){ + grid_lambda = grid_lambda[seq(1, length(grid_lambda), length.out = 100)] + } print("Compute relevant parameters") #select variables according to each regularization parameter #from the grid: A1 corresponding to selected variables, and @@ -56,7 +56,6 @@ valse = function(X,Y,procedure = 'LassoMLE',selecMod = 'DDSE',gamma = 1,mini = 1 params = selectiontotale(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,grid_lambda,X,Y,1e-8,eps) #params2 = selectVariables(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,grid_lambda[seq(1,length(grid_lambda), by=3)],X,Y,1e-8,eps) ## etrange : params et params 2 sont différents ... - selected <<- params$selected Rho <<- params$Rho Pi <<- params$Pi diff --git a/reports/.Rhistory b/reports/.Rhistory new file mode 100644 index 0000000..dc970cc --- /dev/null +++ b/reports/.Rhistory @@ -0,0 +1,512 @@ +a = sum(beta*c(1,gammai[i,])) +return(exp(a)/(1+exp(a))) +}) +U = runif(length(pydata)) +ydata = as.numeric(U