iterated_grid_search: Iterated Grid Search for Function Optimization with...

View source: R/iterated_grid_search.R

iterated_grid_searchR Documentation

Description

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.

Usage

iterated_grid_search(
  min_param,
  max_param,
  func,
  step_length = 100,
  max_iterations = 5,
  precision_threshold = 0.001,
  exp_transform = FALSE,
  ...
)

Arguments

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 func.

Value

A list with two elements:

best_param

The parameter that gives the minimum function value.

best_value

The minimum value of the function.

Examples

# 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)


tkrisztin/downscalr documentation built on June 2, 2025, 1:16 a.m.