View source: R/iterated_grid_search.R
iterated_grid_search | R Documentation |
Performs an iterated grid search over a given range to find the parameter that minimizes a provided function. The search starts by evaluating the function over a sequence of points between a specified minimum and maximum value. The search range is iteratively refined around the minimum point until the maximum number of iterations is reached or the desired precision is achieved. Optionally, the search grid can be transformed exponentially.
iterated_grid_search(
min_param,
max_param,
func,
step_length = 100,
max_iterations = 5,
precision_threshold = 0.001,
exp_transform = FALSE,
...
)
min_param |
Numeric. The minimum value of the parameter range to start the search. |
max_param |
Numeric. The maximum value of the parameter range to start the search. |
func |
Function. The function to be minimized. It should accept a numeric parameter and return a numeric value. |
step_length |
Integer. The number of points to evaluate in each iteration. Default is 100. |
max_iterations |
Integer. The maximum number of iterations to perform. Default is 5. |
precision_threshold |
Numeric. The precision threshold for stopping the search. Once the difference between the min and max of the refined range is less than this value, the search will stop. Default is 1e-3. |
exp_transform |
Logical. If TRUE, the search grid will be transformed exponentially (on the log scale). Default is FALSE. |
... |
Additional parameters to be passed to the function |
A list with two elements:
The parameter that gives the minimum function value.
The minimum value of the function.
# Define a sample function to minimize
test_function <- function(x, a = 1) { a * (x - 3)^2 + 2 }
# Perform the iterated grid search with additional parameter and exponential transform
result <- iterated_grid_search(min_param = 0, max_param = 10, func = test_function, a = 2, exp_transform = TRUE)
print(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.