X-Git-Url: https://git.auder.net/?p=morpheus.git;a=blobdiff_plain;f=pkg%2FR%2FmultiRun.R;h=1cebaab7b3e9dc60c40abf5f39fc7b577418c7d5;hp=0a5c84310482e6276f33a3611d596c7b1c4f2593;hb=cf673dee64ab0ce02ccaaba0fb63a9a4589ee8aa;hpb=cbd88fe5729bf206a784238a2637aa60e697fcdc diff --git a/pkg/R/multiRun.R b/pkg/R/multiRun.R index 0a5c843..1cebaab 100644 --- a/pkg/R/multiRun.R +++ b/pkg/R/multiRun.R @@ -11,6 +11,7 @@ #' @param prepareArgs Prepare arguments for the functions inside estimParams #' @param N Number of runs #' @param ncores Number of cores for parallel runs (<=1: sequential) +#' @param agg Aggregation method (default: lapply) #' @param verbose TRUE to indicate runs + methods numbers #' #' @return A list of nf aggregates of N results (matrices). @@ -39,8 +40,11 @@ #' model=FLXMRglm(family="binomial") ) ) #' normalize( matrix(out@@coef[1:(ncol(fargs$X)*K)], ncol=K) ) #' } ), -#' prepareArgs = function(fargs) { -#' fargs$ind <- sample(1:nrow(fargs$X),replace=TRUE) +#' prepareArgs = function(fargs,index) { +#' if (index == 1) +#' fargs$ind <- 1:nrow(fargs$X) +#' else +#' fargs$ind <- sample(1:nrow(fargs$X),replace=TRUE) #' fargs #' }, N=10, ncores=3) #' for (i in 1:2) @@ -65,7 +69,7 @@ #' model=FLXMRglm(family="binomial") ) ) #' sapply( seq_len(K), function(i) as.double( out@@components[[1]][[i]][,1] ) ) #' } ), -#' prepareArgs = function(fargs) { +#' prepareArgs = function(fargs,index) { #' library(morpheus) #' io = generateSampleIO(fargs$n, fargs$p, fargs$β, fargs$b, fargs$optargs$link) #' fargs$X = io$X @@ -78,7 +82,7 @@ #' res[[i]] <- alignMatrices(res[[i]], ref=β, ls_mode="exact")} #' @export multiRun <- function(fargs, estimParams, - prepareArgs = function(x) x, N=10, ncores=3, agg=lapply, verbose=FALSE) + prepareArgs = function(x,i) x, N=10, ncores=3, agg=lapply, verbose=FALSE) { if (!is.list(fargs)) stop("fargs: list") @@ -95,7 +99,7 @@ multiRun <- function(fargs, estimParams, estimParamAtIndex <- function(index) { - fargs <- prepareArgs(fargs) + fargs <- prepareArgs(fargs, index) if (verbose) cat("Run ",index,"\n") lapply(seq_along(estimParams), function(i) {