if (FALSE) {
comparison <- binaryRL::fit_p(
data = binaryRL::Mason_2024_G2,
#+-----------------------------------------------------------------------------+#
#|----------------------------- black-box function ----------------------------|#
funcs = c("your_funcs"),
estimate = c("MLE", "MAP"),
policy = c("off", "on"),
model_name = c("TD", "RSTD", "Utility"),
#|-------------------------------- fit models ---------------------------------|#
fit_model = list(binaryRL::TD, binaryRL::RSTD, binaryRL::Utility),
priors = 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(
eta = function(x) {stats::dunif(x, min = 0, max = 1, log = TRUE)},
eta = 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, 10), c(1, 1, 10), c(1, 1, 10)),
#|----------------------------- iteration number ------------------------------|#
iteration_i = 10,
iteration_g = 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(comparison)
# Ensure the output directory exists before writing
if (!dir.exists("../OUTPUT")) {
dir.create("../OUTPUT", recursive = TRUE)
}
write.csv(result, "../OUTPUT/result_comparison.csv", row.names = FALSE)
}
Run the code above in your browser using DataLab