View source: R/process_optimize_para.R
optimize_para | R Documentation |
This is an internal helper function for fit_p
. Its primary purpose
is to provide a unified interface for users to interact with various
optimization algorithm packages. It adapts the inputs and outputs
to be compatible with eight distinct algorithms, ensuring a seamless
experience regardless of the underlying solver used.
The function provides several optimization algorithms:
1. L-BFGS-B (from stats::optim
)
2. Simulated Annealing (GenSA::GenSA
)
3. Genetic Algorithm (GA::ga
)
4. Differential Evolution (DEoptim::DEoptim
)
5. Particle Swarm Optimization (pso::psoptim
)
6. Bayesian Optimization (mlrMBO::mbo
)
7. Covariance Matrix Adapting Evolutionary Strategy (cmaes::cma_es
)
8. Nonlinear Optimization (nloptr::nloptr
)
For more information, please refer to the homepage of this package: https://yuki-961004.github.io/binaryRL/
optimize_para(
policy = "off",
estimate = "MLE",
data,
id,
n_trials,
n_params,
obj_func,
lower,
upper,
priors = NULL,
initial_params = NA,
initial_size = 50,
iteration = 10,
seed = 123,
algorithm
)
policy |
[character] Specifies the learning policy to be used.
This determines how the model updates action values based on observed or
simulated choices. It can be either
default: |
estimate |
[character] Estimation method. Can be either
default: |
data |
[data.frame] This data should include the following mandatory columns:
|
id |
[character] Specifies the ID of the subject whose optimal parameters will be fitted. This parameter accepts either string or numeric values. The provided ID must correspond to an existing subject identifier within the raw dataset provided to the function. |
n_trials |
[integer] The total number of trials in your experiment. |
n_params |
[integer] The number of free parameters in your model. |
obj_func |
[function] The objective function that the optimization algorithm package accepts.
This function must strictly take only one argument, |
lower |
[vector] Lower bounds of free parameters |
upper |
[vector] Upper bounds of free parameters |
priors |
[list]
A list specifying the prior distributions for the model parameters.
This argument is mandatory when using 1. Static MAP Estimation (Non-Hierarchical) This approach is used when you have a strong, pre-defined belief about the parameter priors and do not want the model to update them iteratively.
2. Hierarchical Bayesian Estimation via EM This approach is used to let the model learn the group-level (hierarchical) prior distributions directly from the data.
default: |
initial_params |
[vector] Initial values for the free parameters that the optimization algorithm will
search from. These are primarily relevant when using algorithms that require
an explicit starting point, such as default: |
initial_size |
[integer] This parameter corresponds to the population size in genetic
algorithms ( default: |
iteration |
[integer] The number of iterations the optimization algorithm will perform when searching for the best-fitting parameters during the fitting phase. A higher number of iterations may increase the likelihood of finding a global optimum but also increases computation time. |
seed |
[integer] Random seed. This ensures that the results are reproducible and remain the same each time the function is run. default: |
algorithm |
[character] Choose an algorithm package from
In addition, any algorithm from the |
the result of binaryRL with optimal parameters
## Not run:
binaryRL.res <- binaryRL::optimize_para(
data = binaryRL::Mason_2024_G2,
id = 1,
obj_func = binaryRL::RSTD,
n_params = 3,
n_trials = 360,
lower = c(0, 0, 0),
upper = c(1, 1, 1),
iteration = 10,
seed = 123,
algorithm = "L-BFGS-B" # Gradient-Based (stats)
#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)
#algorithm = c("NLOPT_GN_MLSL", "NLOPT_LN_BOBYQA")
)
summary(binaryRL.res)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.