Skip to content

Commit

Permalink
Merge pull request #42 from ncn-foreigners/dev
Browse files Browse the repository at this point in the history
switch from doSNOW on doParallel
  • Loading branch information
LukaszChrostowski authored Mar 11, 2024
2 parents 446e349 + 9744666 commit 2abd6a2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Imports:
RANN,
Rcpp (>= 1.0.12),
nleqslv,
doSNOW,
doParallel,
progress,
foreach,
parallel
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ importFrom(Matrix,Matrix)
importFrom(RANN,nn2)
importFrom(Rcpp,evalCpp)
importFrom(Rcpp,sourceCpp)
importFrom(doSNOW,registerDoSNOW)
importFrom(doParallel,registerDoParallel)
importFrom(foreach,"%dopar%")
importFrom(foreach,foreach)
importFrom(maxLik,maxLik)
Expand Down
18 changes: 9 additions & 9 deletions R/boot_dr.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ bootDR <- function(outcome,
#' @importFrom foreach foreach
#' @importFrom parallel makeCluster
#' @importFrom parallel stopCluster
#' @importFrom doSNOW registerDoSNOW
#' @importFrom doParallel registerDoParallel
bootDR_multicore <- function(outcome,
data,
svydesign,
Expand Down Expand Up @@ -340,15 +340,15 @@ bootDR_multicore <- function(outcome,
rep_weights <- survey::as.svrepdesign(svydesign, type = rep_type, replicates = num_boot)$repweights$weights

cl <- parallel::makeCluster(cores)
doSNOW::registerDoSNOW(cl)
doParallel::registerDoParallel(cl)
on.exit(parallel::stopCluster(cl))
## progress bar
if (verbose) {
pb <- progress::progress_bar$new(total = num_boot)
opts <- list(progress = \(n) pb$tick())
} else {
opts <- NULL
}
# if (verbose) {
# pb <- progress::progress_bar$new(total = num_boot)
# opts <- list(progress = \(n) pb$tick())
# } else {
# opts <- NULL
# }
parallel::clusterExport(cl = cl, varlist = c(
"internal_selection", "internal_outcome", "logit_model_nonprobsvy", "start_fit", "get_method", "controlSel", "theta_h_estimation",
"mle", "mu_hatDR", "probit_model_nonprobsvy", "cloglog_model_nonprobsvy", "glm_nonprobsvy", "nn_nonprobsvy", "pmm_nonprobsvy",
Expand All @@ -359,7 +359,7 @@ bootDR_multicore <- function(outcome,

k <- 1:num_boot
mu_hats <- foreach::`%dopar%`(
obj = foreach::foreach(k = k, .combine = c, .options.snow = opts),
obj = foreach::foreach(k = k, .combine = c),
ex = {
estimation_method <- get_method(est_method)
strap_nons <- sample.int(replace = TRUE, n = n_nons, prob = 1 / weights)
Expand Down
18 changes: 9 additions & 9 deletions R/boot_dr_sel.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bootDR_sel <- function(X,
#' @importFrom foreach foreach
#' @importFrom parallel makeCluster
#' @importFrom parallel stopCluster
#' @importFrom doSNOW registerDoSNOW
#' @importFrom doParallel registerDoParallel
bootDR_sel_multicore <- function(X,
svydesign,
R,
Expand Down Expand Up @@ -142,15 +142,15 @@ bootDR_sel_multicore <- function(X,
rep_weights <- survey::as.svrepdesign(svydesign, type = rep_type, replicates = num_boot)$repweights$weights

cl <- parallel::makeCluster(cores)
doSNOW::registerDoSNOW(cl)
doParallel::registerDoParallel(cl)
on.exit(parallel::stopCluster(cl))
## progress bar
if (verbose) {
pb <- progress::progress_bar$new(total = num_boot)
opts <- list(progress = \(n) pb$tick())
} else {
opts <- NULL
}
# if (verbose) {
# pb <- progress::progress_bar$new(total = num_boot)
# opts <- list(progress = \(n) pb$tick())
# } else {
# opts <- NULL
# }
parallel::clusterExport(cl = cl, varlist = c(
"internal_selection", "logit_model_nonprobsvy", "start_fit", "get_method", "controlSel", "mle",
"probit_model_nonprobsvy", "cloglog_model_nonprobsvy", "mm", "u_theta_beta_dr",
Expand All @@ -159,7 +159,7 @@ bootDR_sel_multicore <- function(X,

k <- 1:num_boot
mu_hats <- foreach::`%dopar%`(
obj = foreach::foreach(k = k, .combine = c, .options.snow = opts),
obj = foreach::foreach(k = k, .combine = c),
ex = {
strap_nons <- sample.int(replace = TRUE, n = n_nons, prob = 1 / weights)
# strap_rand <- sample.int(replace = TRUE, n = n_rand, prob = 1/weights_rand)
Expand Down
18 changes: 9 additions & 9 deletions R/boot_ipw.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ bootIPW <- function(X_rand,
#' @importFrom foreach foreach
#' @importFrom parallel makeCluster
#' @importFrom parallel stopCluster
#' @importFrom doSNOW registerDoSNOW
#' @importFrom doParallel registerDoParallel
bootIPW_multicore <- function(X_rand,
X_nons,
svydesign,
Expand Down Expand Up @@ -220,15 +220,15 @@ bootIPW_multicore <- function(X_rand,
boot_vars <- numeric(length = mu_len)

cl <- parallel::makeCluster(cores)
doSNOW::registerDoSNOW(cl)
doParallel::registerDoParallel(cl)
on.exit(parallel::stopCluster(cl))
## progress bar
if (verbose) {
pb <- progress::progress_bar$new(total = num_boot)
opts <- list(progress = \(n) pb$tick())
} else {
opts <- NULL
}
# if (verbose) {
# pb <- progress::progress_bar$new(total = num_boot)
# opts <- list(progress = \(n) pb$tick())
# } else {
# opts <- NULL
# }
###
parallel::clusterExport(cl = cl, varlist = c(
"internal_selection", "logit_model_nonprobsvy", "start_fit", "get_method", "controlSel",
Expand All @@ -239,7 +239,7 @@ bootIPW_multicore <- function(X_rand,

k <- 1:num_boot
mu_hats_boot <- foreach::`%dopar%`(
obj = foreach::foreach(k = k, .combine = c, .options.snow = opts),
obj = foreach::foreach(k = k, .combine = c),
ex = {
if (is.null(pop_totals)) {
strap_nons <- sample.int(replace = TRUE, n = n_nons, prob = 1 / weights)
Expand Down
18 changes: 9 additions & 9 deletions R/boot_mi.R
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ bootMI <- function(X_rand,
#' @importFrom foreach foreach
#' @importFrom parallel makeCluster
#' @importFrom parallel stopCluster
#' @importFrom doSNOW registerDoSNOW
#' @importFrom doParallel registerDoParallel
bootMI_multicore <- function(X_rand,
X_nons,
weights,
Expand Down Expand Up @@ -469,16 +469,16 @@ bootMI_multicore <- function(X_rand,
}

cl <- parallel::makeCluster(cores)
doSNOW::registerDoSNOW(cl)
doParallel::registerDoParallel(cl)
on.exit(parallel::stopCluster(cl))

## progress bar
if (verbose) {
pb <- progress::progress_bar$new(total = num_boot)
opts <- list(progress = \(n) pb$tick())
} else {
opts <- NULL
}
# if (verbose) {
# pb <- progress::progress_bar$new(total = num_boot)
# opts <- list(progress = \(n) pb$tick())
# } else {
# opts <- NULL
# }
###
parallel::clusterExport(cl = cl, varlist = c(
"internal_selection", "logit_model_nonprobsvy", "start_fit", "get_method", "controlSel",
Expand All @@ -496,7 +496,7 @@ bootMI_multicore <- function(X_rand,
if (method == "glm") {
k <- 1:num_boot
mu_hats <- foreach::`%dopar%`(
obj = foreach::foreach(k = k, .combine = c, .options.snow = opts),
obj = foreach::foreach(k = k, .combine = c),
ex = {
strap <- sample.int(replace = TRUE, n = n_nons, prob = 1 / weights)
weights_strap <- weights[strap]
Expand Down

0 comments on commit 2abd6a2

Please sign in to comment.