Fix multiRun, add vignette = JSS article master
authorBenjamin Auder <benjamin.auder@somewhere>
Mon, 20 Apr 2026 21:35:29 +0000 (23:35 +0200)
committerBenjamin Auder <benjamin.auder@somewhere>
Mon, 20 Apr 2026 21:35:29 +0000 (23:35 +0200)
pkg/.gitignore [deleted file]
pkg/DESCRIPTION
pkg/LICENSE
pkg/R/multiRun.R
pkg/inst/doc/JSS_article.pdf [new file with mode: 0644]
pkg/vignettes/.gitignore [deleted file]
pkg/vignettes/JSS_article.pdf [deleted file]

diff --git a/pkg/.gitignore b/pkg/.gitignore
deleted file mode 100644 (file)
index 236428a..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-/inst/doc
-/vignettes/*.R
-/vignettes/*.html
index e9866ae..9f5c9c4 100644 (file)
@@ -7,7 +7,7 @@ Description: Mixture of logistic regressions parameters (H)estimation with
     (General Linear Model). For more details see chapter 3 in the PhD thesis of
                Mor-Absa Loum: <https://theses.fr/s156435>, available here
                <https://theses.hal.science/tel-01877796/document>.
-Version: 1.0-5
+Version: 1.0-6
 Authors@R: c(person(given = "Benjamin",
                     family = "Auder",
                     role = c("aut", "cre"),
@@ -29,7 +29,7 @@ Suggests:
     parallel,
     testthat (>= 3.0.0),
     roxygen2
-License: ISC + file LICENSE
+License: MIT + file LICENSE
 Date: 2026-04-20
 RoxygenNote: 7.3.3
 URL: https://github.com/yagu0/morpheus
index 64fe734..34c9bc4 100644 (file)
@@ -1,13 +1,2 @@
-Copyright (C) 2016-2026 Benjamin AUDER, Mor-Absa LOUM
-
-Permission to use, copy, modify, and/or distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
-OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
-CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+YEAR: 2016-2026
+COPYRIGHT HOLDER: Benjamin Auder, Mor-Absa Loum
index e2633c1..767f6f9 100644 (file)
@@ -11,6 +11,7 @@
 #'
 #' @param fargs List of arguments for the estimation functions
 #' @param estimParams List of nf function(s) to apply on fargs
+#' @param packages Vector of packages to load on each node (default: morpheus)
 #' @param prepareArgs Prepare arguments for the functions inside estimParams
 #' @param N Number of runs
 #' @param ncores Number of cores for parallel runs (<=1: sequential)
 #' res <- multiRun(list(X=io$X,Y=io$Y,K=2), list(
 #'   # morpheus
 #'   function(fargs) {
-#'     library(morpheus)
 #'     ind <- fargs$ind
 #'     computeMu(fargs$X[ind,], fargs$Y[ind], list(K=fargs$K))
 #'   },
 #'   # flexmix
 #'   function(fargs) {
-#'     library(flexmix)
 #'     ind <- fargs$ind
 #'     K <- fargs$K
 #'     dat <- as.data.frame( cbind(fargs$Y[ind],fargs$X[ind,]) )
@@ -43,6 +42,7 @@
 #'       model=FLXMRglm(family="binomial") ) )
 #'     normalize( matrix(out@@coef[1:(ncol(fargs$X)*K)], ncol=K) )
 #'   } ),
+#'   packages = c("morpheus", "flexmix"),
 #'   prepareArgs = function(fargs,index) {
 #'     if (index == 1)
 #'       fargs$ind <- 1:nrow(fargs$X)
@@ -57,7 +57,6 @@
 #' res <- multiRun(list(n=1000,p=1/2,β=β,b=c(0,0),link="logit"), list(
 #'   # morpheus
 #'   function(fargs) {
-#'     library(morpheus)
 #'     K <- fargs$K
 #'     μ <- computeMu(fargs$X, fargs$Y, list(K=fargs$K))
 #'     o <- optimParams(fargs$X, fargs$Y, fargs$K, fargs$link, fargs$M)
@@ -65,7 +64,6 @@
 #'   },
 #'   # flexmix
 #'   function(fargs) {
-#'     library(flexmix)
 #'     K <- fargs$K
 #'     dat <- as.data.frame( cbind(fargs$Y,fargs$X) )
 #'     out <- refit( flexmix( cbind(V1, 1 - V1) ~ ., data=dat, k=K,
@@ -73,6 +71,7 @@
 #'     sapply( seq_len(K), function(i)
 #'       as.double( out@@components[[1]][[i]][2:(1+ncol(fargs$X)),1] ) )
 #'   } ),
+#'   packages = c("morpheus", "flexmix"),
 #'   prepareArgs = function(fargs,index) {
 #'     library(morpheus)
 #'     io <- generateSampleIO(fargs$n, fargs$p, fargs$β, fargs$b, fargs$link)
@@ -86,7 +85,7 @@
 #' for (i in 1:2)
 #'   res[[i]] <- alignMatrices(res[[i]], ref=β, ls_mode="exact")}
 #' @export
-multiRun <- function(fargs, estimParams,
+multiRun <- function(fargs, estimParams, packages = c("morpheus"),
   prepareArgs = function(x,i) x, N=10, ncores=3, agg=lapply, verbose=FALSE)
 {
   if (!is.list(fargs))
@@ -118,15 +117,23 @@ multiRun <- function(fargs, estimParams,
     })
   }
 
+  loadPackages <- function() {
+    for (p in packages)
+      library(p, character.only = TRUE)
+  }
+
   if (ncores > 1)
   {
     cl <- parallel::makeCluster(ncores, outfile="")
-    parallel::clusterExport(cl, c("fargs","verbose"), environment())
+    parallel::clusterExport(cl, c("fargs", "verbose", "loadPackages"), environment())
+    parallel::clusterEvalQ(cl, loadPackages() )
     list_res <- parallel::clusterApplyLB(cl, 1:N, estimParamAtIndex)
     parallel::stopCluster(cl)
   }
-  else
+  else {
+    loadPackages()
     list_res <- lapply(1:N, estimParamAtIndex)
+  }
 
   # De-interlace results: output one list per function
   nf <- length(estimParams)
diff --git a/pkg/inst/doc/JSS_article.pdf b/pkg/inst/doc/JSS_article.pdf
new file mode 100644 (file)
index 0000000..0b930dc
--- /dev/null
@@ -0,0 +1 @@
+#$# git-fat 51b69cedf9b3a4397c353799b5e03a0b6254219a               404201
diff --git a/pkg/vignettes/.gitignore b/pkg/vignettes/.gitignore
deleted file mode 100644 (file)
index 097b241..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-*.html
-*.R
diff --git a/pkg/vignettes/JSS_article.pdf b/pkg/vignettes/JSS_article.pdf
deleted file mode 100644 (file)
index 3ff1fb4..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#$# git-fat f33784b937cb1fbbc0d7d700075dec297dcb2504               769072