bb_optimize {bbotk}R Documentation

Black-Box Optimization

Description

This function optimizes a function or Objective with a given method.

Usage

bb_optimize(
  x,
  method = "random_search",
  max_evals = 1000,
  max_time = NULL,
  ...
)

## S3 method for class ''function''
bb_optimize(
  x,
  method = "random_search",
  max_evals = 1000,
  max_time = NULL,
  lower = NULL,
  upper = NULL,
  maximize = FALSE,
  ...
)

## S3 method for class 'Objective'
bb_optimize(
  x,
  method = "random_search",
  max_evals = 1000,
  max_time = NULL,
  search_space = NULL,
  ...
)

Arguments

x

(function | Objective).

method

(character(1) | Optimizer)
Key to retrieve optimizer from mlr_optimizers dictionary or Optimizer.

max_evals

(integer(1))
Number of allowed evaluations.

max_time

(integer(1))
Maximum allowed time in seconds.

...

(named list())
Named arguments passed to objective function. Ignored if Objective is optimized.

lower

(numeric())
Lower bounds on the parameters. If named, names are used to create the domain.

upper

(numeric())
Upper bounds on the parameters.

maximize

(logical())
Logical vector used to create the codomain e.g. c(TRUE, FALSE) -> ps(y1 = p_dbl(tags = "maximize"), y2 = pd_dbl(tags = "minimize")). If named, names are used to create the codomain.

search_space

(paradox::ParamSet).

Value

list of

Note

If both max_evals and max_time are NULL, TerminatorNone is used. This is useful if the Optimizer can terminate itself. If both are given, TerminatorCombo is created and the optimization stops if the time or evaluation budget is exhausted.

Examples

# function and bounds
fun = function(xs) {
  -(xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + 10
}

bb_optimize(fun, lower = c(-10, -5), upper = c(10, 5), max_evals = 10)

# function and constant
fun = function(xs, c) {
  -(xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + c
}

bb_optimize(fun, lower = c(-10, -5), upper = c(10, 5), max_evals = 10, c = 1)

# objective
fun = function(xs) {
  c(z = -(xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + 10)
}

# define domain and codomain using a `ParamSet` from paradox
domain = ps(x1 = p_dbl(-10, 10), x2 = p_dbl(-5, 5))
codomain = ps(z = p_dbl(tags = "minimize"))
objective = ObjectiveRFun$new(fun, domain, codomain)

bb_optimize(objective, method = "random_search", max_evals = 10)

[Package bbotk version 1.0.1 Index]