simulation : model selection adding rep arg to set repetitions

This commit is contained in:
Louis Lacoste 2024-06-25 12:07:01 +02:00
parent 7d3309543a
commit f2e44922dd

View file

@ -31,8 +31,22 @@ alpha <- 0.25 + matrix(
prob_order <- seq(1, 3)
prob_order <- t(sapply(combinat::permn(prob_order), function(v) v))
# Arguments
arg <- commandArgs(trailingOnly = TRUE)
repetitions <- seq.int(3)
rep <- 3L
if (length(arg) == 0L) {
message("No arguments provided, using default.")
} else {
if ("--rep" %in% arg) {
rep <- as.integer(arg[(which(arg == "--rep") + 1L)])
} else {
message("No rep number provided, defaulting to 3.")
}
}
repetitions <- seq(1, rep)
conditions <- tidyr::crossing(
epsilon_pi = epsilons_pi,
@ -42,37 +56,6 @@ conditions <- tidyr::crossing(
repetition = repetitions
)
# To speed up computations and debug adding an argument based selection
if (!exists("arg")) {
arg <- commandArgs(trailingOnly = TRUE)
}
if (identical(arg, character(0))) {
cat(
"\nNo arguments provided,",
"assuming you want to go over all the conditions."
)
arg <- c(1, nrow(conditions))
batch_name <- "default"
} else {
if (!is.na(arg[3])) {
batch_name <- arg[3]
} else {
batch_name <- "default"
}
arg <- as.numeric(arg[-3])
}
if (arg[1] < 1 | arg[1] > nrow(conditions)) {
warning(paste("Arg 1 was invalid, set to 1."))
arg[1] <- 1
}
if (arg[2] > nrow(conditions) | arg[2] < 1) {
warning(paste("Arg 2 was invalid, set to", nrow(conditions)))
arg[2] <- nrow(conditions)
}
choosed_conditions <- seq.int(from = arg[1], to = arg[2])
conditions <- conditions[choosed_conditions, ]
# Data params
main_dir <- file.path("code", "results", "simulations", "model_selection")
@ -89,10 +72,13 @@ if (!dir.exists(temp_dir)) {
file_save <- file.path(main_dir, paste0(
"model_selection", start_time, "_",
batch_name, ".Rds"
batch_name, "_rep_", repetitions, ".Rds"
))
message("Starting model selection simulation.")
message(
"Starting model selection simulation with ", rep,
" repetitions per condition"
)
tictoc::tic()
with_progress({
row_conditions <- seq_len(nrow(conditions))