projects
/
morpheus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update vignette + optim code
[morpheus.git]
/
pkg
/
R
/
multiRun.R
diff --git
a/pkg/R/multiRun.R
b/pkg/R/multiRun.R
index
0a5c843
..
8b70d6d
100644
(file)
--- a/
pkg/R/multiRun.R
+++ b/
pkg/R/multiRun.R
@@
-11,12
+11,13
@@
#' @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 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).
#'
#' @examples
#' @param verbose TRUE to indicate runs + methods numbers
#'
#' @return A list of nf aggregates of N results (matrices).
#'
#' @examples
-#' \dont
run
{
+#' \dont
test
{
#' β <- matrix(c(1,-2,3,1),ncol=2)
#'
#' # Bootstrap + computeMu, morpheus VS flexmix ; assumes fargs first 3 elts X,Y,K
#' β <- matrix(c(1,-2,3,1),ncol=2)
#'
#' # Bootstrap + computeMu, morpheus VS flexmix ; assumes fargs first 3 elts X,Y,K
@@
-39,8
+40,11
@@
#' model=FLXMRglm(family="binomial") ) )
#' normalize( matrix(out@@coef[1:(ncol(fargs$X)*K)], ncol=K) )
#' } ),
#' 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)
#' fargs
#' }, N=10, ncores=3)
#' for (i in 1:2)
@@
-53,8
+57,7
@@
#' library(morpheus)
#' K <- fargs$optargs$K
#' μ <- computeMu(fargs$X, fargs$Y, fargs$optargs)
#' library(morpheus)
#' K <- fargs$optargs$K
#' μ <- computeMu(fargs$X, fargs$Y, fargs$optargs)
-#' V <- list( p=rep(1/K,K-1), β=μ, b=c(0,0) )
-#' optimParams(V,fargs$optargs)$β
+#' optimParams(fargs$K,fargs$link,fargs$optargs)$run(list(β=μ))$β
#' },
#' # flexmix
#' function(fargs) {
#' },
#' # flexmix
#' function(fargs) {
@@
-65,12
+68,13
@@
#' model=FLXMRglm(family="binomial") ) )
#' sapply( seq_len(K), function(i) as.double( out@@components[[1]][[i]][,1] ) )
#' } ),
#' 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
#' fargs$Y = io$Y
#' library(morpheus)
#' io = generateSampleIO(fargs$n, fargs$p, fargs$β, fargs$b, fargs$optargs$link)
#' fargs$X = io$X
#' fargs$Y = io$Y
-#' fargs$optargs$K = ncol(fargs$β)
+#' fargs$K = ncol(fargs$β)
+#' fargs$link = fargs$optargs$link
#' fargs$optargs$M = computeMoments(io$X,io$Y)
#' fargs
#' }, N=10, ncores=3)
#' fargs$optargs$M = computeMoments(io$X,io$Y)
#' fargs
#' }, N=10, ncores=3)
@@
-78,7
+82,7
@@
#' res[[i]] <- alignMatrices(res[[i]], ref=β, ls_mode="exact")}
#' @export
multiRun <- function(fargs, estimParams,
#' 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")
{
if (!is.list(fargs))
stop("fargs: list")
@@
-95,7
+99,7
@@
multiRun <- function(fargs, estimParams,
estimParamAtIndex <- function(index)
{
estimParamAtIndex <- function(index)
{
- fargs <- prepareArgs(fargs)
+ fargs <- prepareArgs(fargs
, index
)
if (verbose)
cat("Run ",index,"\n")
lapply(seq_along(estimParams), function(i) {
if (verbose)
cat("Run ",index,"\n")
lapply(seq_along(estimParams), function(i) {