-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
239fe10
commit 7c478d1
Showing
36 changed files
with
1,676 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,6 @@ src/*.so | |
src/*.dll | ||
testthat-problems.rds | ||
README.md | ||
**/sascfg_personal.py | ||
.Rprofile | ||
/doc/ | ||
/Meta/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
**/fit_results.[Rr]ds | ||
slurm.out | ||
.future |
108 changes: 108 additions & 0 deletions
108
simulations/missing-data-benchmarks/R/customizations/experiment.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
stopifnot(any(grepl("simChef", search()))) | ||
|
||
# Custom new method which only kicks off the future jobs. | ||
# This is modified from the fit() method, see | ||
# https://github.com/Yu-Group/simChef/blob/main/R/experiment.R#L976C3-L980C62 | ||
Experiment$set( | ||
"public", | ||
"onlystart", | ||
function(n_reps = 1, | ||
future.globals = NULL, | ||
future.packages = NULL, | ||
future.seed = TRUE, | ||
verbose = 1, ...) { | ||
parallel_strategy <- "reps" | ||
|
||
dgp_list <- private$.get_obj_list("dgp") | ||
method_list <- private$.get_obj_list("method") | ||
|
||
if (length(dgp_list) == 0) { | ||
private$.throw_empty_list_error("dgp", "generate data from") | ||
} | ||
|
||
if (length(method_list) == 0) { | ||
private$.throw_empty_list_error("method", "fit methods in") | ||
} | ||
|
||
private$.update_fit_params() | ||
|
||
checkpoint <- FALSE | ||
n_reps_cached <- 0 | ||
n_reps_total <- n_reps | ||
fit_results <- data.frame() | ||
|
||
if (verbose >= 1) { | ||
inform(sprintf("Fitting %s...", self$name)) | ||
start_time <- Sys.time() | ||
} | ||
|
||
if (is.null(future.packages)) { | ||
future.packages <- private$.future.packages | ||
} | ||
|
||
if (is.null(future.globals)) { | ||
future.globals <- private$.future.globals | ||
} | ||
|
||
dgp_params_list <- private$.combine_vary_params("dgp") | ||
method_params_list <- private$.combine_vary_params("method") | ||
|
||
# if new_fit_params is not NULL after the if statement below, then not all | ||
# combos of (dgp_params_list, method_params_list) need to be rerun so need | ||
# to check cache ids when fitting | ||
new_fit_params <- NULL | ||
|
||
duplicate_param_names <- private$.get_duplicate_param_names() | ||
|
||
# simulations | ||
n_reps <- min(n_reps, n_reps_total - n_reps_cached) | ||
|
||
new_fit_results <- local({ | ||
|
||
# create an env with objs/funcs that the future workers need | ||
workenv <- rlang::new_environment( | ||
data = list( | ||
verbose = verbose, | ||
dgp_list = dgp_list, | ||
method_list = method_list, | ||
new_fit_params = new_fit_params, | ||
dgp_params_list = dgp_params_list, | ||
method_params_list = method_params_list, | ||
duplicate_param_names = duplicate_param_names, | ||
do_call_wrapper = function(name, | ||
fun, | ||
params, | ||
verbose, | ||
call) { | ||
tryCatch( | ||
do_call_handler( | ||
name, fun, params, verbose, call | ||
), | ||
error = identity | ||
) | ||
} | ||
), | ||
parent = rlang::ns_env() | ||
) | ||
|
||
# get the experiment compute fun | ||
compute_fun <- compute_rep | ||
|
||
environment(compute_fun) <- workenv | ||
|
||
# compute the experiment | ||
compute_fun(n_reps, | ||
future.globals, | ||
future.packages, | ||
future.seed) | ||
}) | ||
|
||
gc() | ||
|
||
new_fit_results %>% | ||
dplyr::mutate( | ||
.rep = as.character(as.numeric(.rep) + n_reps_cached) | ||
) %>% | ||
simplify_tibble() | ||
} | ||
) |
44 changes: 44 additions & 0 deletions
44
simulations/missing-data-benchmarks/R/customizations/format-fit-results.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# format the fit results | ||
format_fit_results <- function(fit_results) { | ||
fit_results %>% | ||
transmute( | ||
effect_size = str_extract(.dgp_name, "^([^_])+"), | ||
rep = .rep, | ||
dgp_name = .dgp_name, | ||
method_name = .method_name, | ||
converged = pmap( | ||
.l = list(fit, .method_name, converged), | ||
.f = function(f, method_name, conv_status) { | ||
get_convergence(method_name, f, conv_status) | ||
} | ||
), | ||
converged = unlist(converged), | ||
fit_time = fit_time, | ||
emmeans_output = pmap( | ||
.l = list(fit, .dgp_name, .method_name, data, converged), | ||
.f = function(f, dgp_name, method_name, dt, conv_status) { | ||
get_emmeans_output(method_name, f, dt, conv_status) | ||
} | ||
), | ||
covmat_estimates = pmap( | ||
.l = list(fit, .method_name, converged), | ||
.f = function(f, method_name, conv_status) { | ||
get_cov_mat_estimate(method_name, f, conv_status) | ||
} | ||
) | ||
) | ||
} | ||
|
||
# The whole process | ||
format_fit_and_save <- function(experiment) { | ||
gc() | ||
fit_results <- experiment$get_cached_results("fit") | ||
formatted_fit_results <- format_fit_results(fit_results) | ||
formatted_fit_results_file <- file.path(experiment$get_save_dir(), "formatted_fit_results.rds") | ||
saveRDS(formatted_fit_results, file = formatted_fit_results_file) | ||
formatted_fit_results | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.