X-Git-Url: https://git.auder.net/?p=valse.git;a=blobdiff_plain;f=R%2FdiscardSimilarModels.R;h=5f6a8c8e3f3a37aa64491030e4b9fdedaf89d89e;hp=8b1207708098370ff161a19f4712ee6b76178e2d;hb=31463ab809c0195273ff2760606ea65361d721ab;hpb=d1531659214edd6eaef0ac9ec835455614bba16c diff --git a/R/discardSimilarModels.R b/R/discardSimilarModels.R index 8b12077..5f6a8c8 100644 --- a/R/discardSimilarModels.R +++ b/R/discardSimilarModels.R @@ -1,4 +1,4 @@ -#' Discard models which have the same relevant variables +#' Discard models which have the same relevant variables - for EMGLLF #' #' @param B1 array of relevant coefficients (of size p*m*length(gridlambda)) #' @param B2 array of irrelevant coefficients (of size p*m*length(gridlambda)) @@ -7,25 +7,47 @@ #' @param pi weight parameters (of size K*size(gridLambda)) #' #' @return a list with update B1, B2, glambda, rho and pi, and ind the vector of indices -#' of selected models. +#' of selected models. +#' @export +discardSimilarModels_EMGLLF = function(B1,B2,glambda,rho,pi) +{ + ind = c() + for (j in 1:length(glambda)) + { + for (ll in 1:(l-1)) + { + if(B1[,,l] == B1[,,ll]) + ind = c(ind, l) + } + } + ind = unique(ind) + B1 = B1[,,-ind] + glambda = glambda[-ind] + B2 = B2[,,-ind] + rho = rho[,,,-ind] + pi = pi[,-ind] + + return (list("B1"=B1,"B2"=B2,"glambda"=glambda,"rho"=rho,"pi"=pi,"ind"=ind)) +} + +#' Discard models which have the same relevant variables +#' - for Lasso-rank procedure (focus on columns) +#' +#' @param B1 array of relevant coefficients (of size p*m*length(gridlambda)) +#' @param rho covariance matrix +#' @param pi weight parameters +#' +#' @return a list with B1, in, rho, pi #' @export -discardSimilarModels = function(B1,B2,glambda,rho,pi) +discardSimilarModels_EMGrank = function(B1,rho,pi) { - ind = c() - for (j in 1:length(glambda)) - { - for (ll in 1:(l-1)) - { - if(B1[,,l] == B1[,,ll]) - ind = c(ind, l) - } - } - ind = unique(ind) - B1 = B1[,,-ind] - glambda = glambda[-ind] - B2 = B2[,,-ind] - rho = rho[,,,-ind] - pi = pi[,-ind] - - return (list(B1=B1,B2=B2,glambda=glambda,rho=rho,pi=pi,ind=ind)) + ind = c() + dim_B1 = dim(B1) + B2 = array(0,dim=c(dim_B1[1],dim_B1[2],dim_B1[3])) + sizeLambda=dim_B1[3] + glambda = rep(0,sizeLambda) + + suppressmodel = discardSimilarModels_EMGLLF(B1,B2,glambda,rho,pi) + return (list("B1" = suppressmodel$B1, "ind" = suppressmodel$ind, + "rho" = suppressmodel$rho, "pi" = suppressmodel$pi)) }