Skip to content

Commit

Permalink
add doFuture with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mnwright committed Jun 12, 2024
1 parent 6b8aafd commit b20dbec
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 12 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ RoxygenNote: 7.3.1
Suggests:
ggplot2,
doParallel,
doFuture,
mlbench,
knitr,
rmarkdown,
Expand Down
11 changes: 10 additions & 1 deletion R/adversarial_rf.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @param prune Impose \code{min_node_size} by pruning?
#' @param verbose Print discriminator accuracy after each round?
#' @param parallel Compute in parallel? Must register backend beforehand, e.g.
#' via \code{doParallel}.
#' via \code{doParallel} or \code{doFuture}; see examples.
#' @param ... Extra parameters to be passed to \code{ranger}.
#'
#' @details
Expand Down Expand Up @@ -83,6 +83,15 @@
#' evi <- data.frame(Species = "setosa")
#' expct(psi, query = "Sepal.Length", evidence = evi)
#'
#' \dontrun{
#' # Parallelization with doParallel
#' doParallel::registerDoParallel(cores = 4)
#'
#' # ... or with doFuture
#' doFuture::registerDoFuture()
#' future::plan("multisession", workers = 4)
#' }
#'
#' @seealso
#' \code{\link{arf}}, \code{\link{forde}}, \code{\link{forge}}, \code{\link{expct}}, \code{\link{lik}}
#'
Expand Down
9 changes: 9 additions & 0 deletions R/arf-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
#' # Expectation of Sepal.Length for class setosa
#' evi <- data.frame(Species = "setosa")
#' expct(psi, query = "Sepal.Length", evidence = evi)
#'
#' \dontrun{
#' # Parallelization with doParallel
#' doParallel::registerDoParallel(cores = 4)
#'
#' # ... or with doFuture
#' doFuture::registerDoFuture()
#' future::plan("multisession", workers = 4)
#' }
"_PACKAGE"

## usethis namespace: start
Expand Down
11 changes: 10 additions & 1 deletion R/expct.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' @param stepsize Stepsize defining number of evidence rows handled in one for each step.
#' Defaults to nrow(evidence)/num_registered_workers for \code{parallel == TRUE}.
#' @param parallel Compute in parallel? Must register backend beforehand, e.g.
#' via \code{doParallel}.
#' via \code{doParallel} or \code{doFuture}; see examples.
#'
#' @details
#' This function computes expected values for any subset of features, optionally
Expand Down Expand Up @@ -70,6 +70,15 @@
#' evi[2, 2] <- NA_real_
#' x_synth <- expct(psi, evidence = evi)
#'
#' \dontrun{
#' # Parallelization with doParallel
#' doParallel::registerDoParallel(cores = 4)
#'
#' # ... or with doFuture
#' doFuture::registerDoFuture()
#' future::plan("multisession", workers = 4)
#' }
#'
#' @seealso
#' \code{\link{arf}}, \code{\link{adversarial_rf}}, \code{\link{forde}}, \code{\link{forge}}, \code{\link{lik}}
#'
Expand Down
11 changes: 10 additions & 1 deletion R/forde.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#' data. The gap between lower and upper bounds is expanded by a factor of
#' \code{1 + epsilon}.
#' @param parallel Compute in parallel? Must register backend beforehand, e.g.
#' via \code{doParallel}.
#' via \code{doParallel} or \code{doFuture}; see examples.
#'
#'
#' @details
Expand Down Expand Up @@ -89,6 +89,15 @@
#' evi <- data.frame(Species = "setosa")
#' expct(psi, query = "Sepal.Length", evidence = evi)
#'
#' \dontrun{
#' # Parallelization with doParallel
#' doParallel::registerDoParallel(cores = 4)
#'
#' # ... or with doFuture
#' doFuture::registerDoFuture()
#' future::plan("multisession", workers = 4)
#' }
#'
#' @seealso
#' \code{\link{arf}}, \code{\link{adversarial_rf}}, \code{\link{forge}}, \code{\link{expct}}, \code{\link{lik}}
#'
Expand Down
11 changes: 10 additions & 1 deletion R/forge.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @param stepsize Stepsize defining number of evidence rows handled in one for each step.
#' Defaults to nrow(evidence)/num_registered_workers for \code{parallel == TRUE}.
#' @param parallel Compute in parallel? Must register backend beforehand, e.g.
#' via \code{doParallel}.
#' via \code{doParallel} or \code{doFuture}; see examples.
#' @param n_synth Number of synthetic samples to generate.
#'
#' @details
Expand Down Expand Up @@ -84,6 +84,15 @@
#' n_leaves <- nrow(psi$forest)
#' evi <- data.frame(f_idx = psi$forest$f_idx, wt = rexp(n_leaves))
#' x_synth <- forge(psi, n_synth = 100, evidence = evi)
#'
#' \dontrun{
#' # Parallelization with doParallel
#' doParallel::registerDoParallel(cores = 4)
#'
#' # ... or with doFuture
#' doFuture::registerDoFuture()
#' future::plan("multisession", workers = 4)
#' }
#'
#' @seealso
#' \code{\link{arf}}, \code{\link{adversarial_rf}}, \code{\link{forde}}, \code{\link{expct}}, \code{\link{lik}}
Expand Down
11 changes: 10 additions & 1 deletion R/lik.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' However, with large samples or many trees, it can be more memory efficient
#' to split the data into batches. This has no impact on results.
#' @param parallel Compute in parallel? Must register backend beforehand, e.g.
#' via \code{doParallel}.
#' via \code{doParallel} or \code{doFuture}; see examples.
#'
#'
#' @details
Expand Down Expand Up @@ -76,6 +76,15 @@
#' Petal.Width = ">0.3")
#' lik(psi, query = iris[1, 1:3], evidence = evi)
#'
#' \dontrun{
#' # Parallelization with doParallel
#' doParallel::registerDoParallel(cores = 4)
#'
#' # ... or with doFuture
#' doFuture::registerDoFuture()
#' future::plan("multisession", workers = 4)
#' }
#'
#' @seealso
#' \code{\link{arf}}, \code{\link{adversarial_rf}}, \code{\link{forde}}, \code{\link{forge}}, \code{\link{expct}}
#'
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ post_x <- function(x, params, round = TRUE) {
#' @param row_mode Interpretation of rows in multi-row conditions.
#' @param stepsize Stepsize defining number of condition rows handled in one for each step.
#' @param parallel Compute in parallel? Must register backend beforehand, e.g.
#' via \code{doParallel}.
#' via \code{doParallel} or \code{doFuture}; see examples.
#'
#' @return List with conditions (\code{evidence_input}), prepared conditions (\code{evidence_prepped})
#' and leaves that match the conditions in evidence with continuous data (\code{cnt})
Expand Down
11 changes: 10 additions & 1 deletion man/adversarial_rf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions man/arf-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/cforde.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion man/expct.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion man/forde.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion man/forge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion man/lik.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b20dbec

Please sign in to comment.