if (FALSE) {
recovery <- binaryRL::rcv_d(
data = binaryRL::Mason_2024_G2,
#+-----------------------------------------------------------------------------+#
#|----------------------------- black-box function ----------------------------|#
funcs = c("your_funcs"),
estimate = c("MLE", "MAP"),
policy = c("off", "on"),
model_names = c("TD", "RSTD", "Utility"),
#|------------------------------- simulate models -----------------------------|#
simulate_models = list(binaryRL::TD, binaryRL::RSTD, binaryRL::Utility),
rfun = list(
list(
eta = function() { stats::runif(n = 1, min = 0, max = 1) },
tau = function() { stats::rexp(n = 1, rate = 1) }
),
list(
etan = function() { stats::runif(n = 1, min = 0, max = 1) },
etap = function() { stats::runif(n = 1, min = 0, max = 1) },
tau = function() { stats::rexp(n = 1, rate = 1) }
),
list(
eta = function() { stats::runif(n = 1, min = 0, max = 1) },
gamma = function() { stats::runif(n = 1, min = 0, max = 1) },
tau = function() { stats::rexp(n = 1, rate = 1) }
),
),
#|---------------------------------- fit models -------------------------------|#
fit_models = list(binaryRL::TD, binaryRL::RSTD, binaryRL::Utility),
dfun = list(
list(
eta = function(x) { stats::dunif(x, min = 0, max = 1, log = TRUE) },
tau = function(x) { stats::dexp(x, rate = 1, log = TRUE) }
),
list(
etan = function(x) { stats::dunif(x, min = 0, max = 1, log = TRUE) },
etap = function(x) { stats::dunif(x, min = 0, max = 1, log = TRUE) },
tau = function(x) { stats::dexp(x, rate = 1, log = TRUE) }
),
list(
eta = function(x) { stats::dunif(x, min = 0, max = 1, log = TRUE) },
gamma = function(x) { stats::dunif(x, min = 0, max = 1, log = TRUE) },
tau = function(x) { stats::dexp(x, rate = 1, log = TRUE) }
),
),
#|---------------------------------- bound ------------------------------------|#
lower = list(c(0, 0), c(0, 0, 0), c(0, 0, 0)),
upper = list(c(1, 5), c(1, 1, 5), c(1, 1, 5)),
#|----------------------------- interation number -----------------------------|#
iteration_s = 100,
iteration_f = c(100, 10),
#|-------------------------------- algorithms ---------------------------------|#
nc = 1, # 1>: parallel computation across subjects
# Base R Optimization
#algorithm = "L-BFGS-B" # Gradient-Based (stats)
#|-----------------------------------------------------------------------------|#
# Specialized External Optimization
#algorithm = "GenSA" # Simulated Annealing (GenSA)
#algorithm = "GA" # Genetic Algorithm (GA)
#algorithm = "DEoptim" # Differential Evolution (DEoptim)
#algorithm = "PSO" # Particle Swarm Optimization (pso)
#algorithm = "Bayesian" # Bayesian Optimization (mlrMBO)
#algorithm = "CMA-ES" # Covariance Matrix Adapting (cmaes)
#|-----------------------------------------------------------------------------|#
# Optimization Library (nloptr)
algorithm = c("NLOPT_GN_MLSL", "NLOPT_LN_BOBYQA")
#|-------------------------------- algorithms ---------------------------------|#
#+#############################################################################+#
)
result <- dplyr::bind_rows(recovery) %>%
dplyr::select(simulate_model, fit_model, iteration, everything())
# Ensure the output directory exists
if (!dir.exists("../OUTPUT")) {
dir.create("../OUTPUT", recursive = TRUE)
}
write.csv(result, file = "../OUTPUT/result_recovery.csv", row.names = FALSE)
}
Run the code above in your browser using DataLab