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

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

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

# S3 method for 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)
#> $par #> x1 x2 #> 1: -8.384997 3.34333 #> #> $value #> y1 #> -138.086 #> #> $instance #> <OptimInstanceSingleCrit> #> * State: Optimized #> * Objective: <ObjectiveRFun:function> #> * Search Space: #> <ParamSet> #> id class lower upper nlevels default value #> 1: x1 ParamDbl -10 10 Inf <NoDefault[3]> #> 2: x2 ParamDbl -5 5 Inf <NoDefault[3]> #> * Terminator: <TerminatorEvals> #> * Terminated: TRUE #> * Result: #> x1 x2 x_domain y1 #> 1: -8.384997 3.34333 <list[2]> -138.086 #> * Archive: #> <Archive> #> x1 x2 y1 timestamp batch_nr #> 1: -8.385 3.34 -138.1 2021-09-28 04:10:51 1 #> 2: 2.015 -3.43 9.8 2021-09-28 04:10:51 2 #> 3: -9.852 -0.34 -137.6 2021-09-28 04:10:51 3 #> 4: -0.044 -2.10 5.0 2021-09-28 04:10:51 4 #> 5: 4.658 2.73 -29.8 2021-09-28 04:10:51 5 #> 6: 7.492 -3.25 -20.2 2021-09-28 04:10:51 6 #> 7: -9.315 -1.80 -119.5 2021-09-28 04:10:51 7 #> 8: -1.953 -3.04 -5.6 2021-09-28 04:10:51 8 #> 9: -1.929 -4.36 -7.3 2021-09-28 04:10:51 9 #> 10: -2.226 4.76 -68.0 2021-09-28 04:10:51 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)
#> $par #> x1 x2 #> 1: -8.971074 0.3021246 #> #> $value #> y1 #> -130.2685 #> #> $instance #> <OptimInstanceSingleCrit> #> * State: Optimized #> * Objective: <ObjectiveRFun:function> #> * Search Space: #> <ParamSet> #> id class lower upper nlevels default value #> 1: x1 ParamDbl -10 10 Inf <NoDefault[3]> #> 2: x2 ParamDbl -5 5 Inf <NoDefault[3]> #> * Terminator: <TerminatorEvals> #> * Terminated: TRUE #> * Result: #> x1 x2 x_domain y1 #> 1: -8.971074 0.3021246 <list[2]> -130.2685 #> * Archive: #> <Archive> #> x1 x2 y1 timestamp batch_nr #> 1: 4.71 -3.040 -6.3 2021-09-28 04:10:51 1 #> 2: 9.61 2.415 -86.2 2021-09-28 04:10:51 2 #> 3: -8.97 0.302 -130.3 2021-09-28 04:10:51 3 #> 4: 3.92 1.886 -26.5 2021-09-28 04:10:51 4 #> 5: -9.38 -2.744 -128.5 2021-09-28 04:10:51 5 #> 6: -3.98 1.365 -53.9 2021-09-28 04:10:51 6 #> 7: -0.42 -0.678 -10.2 2021-09-28 04:10:51 7 #> 8: 4.13 4.486 -59.6 2021-09-28 04:10:51 8 #> 9: -6.39 -2.831 -69.5 2021-09-28 04:10:51 9 #> 10: 3.60 -0.012 -10.5 2021-09-28 04:10:51 10 #>
# 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)
#> $par #> x1 x2 #> 1: -8.079517 2.656002 #> #> $value #> z #> -123.587 #> #> $instance #> <OptimInstanceSingleCrit> #> * State: Optimized #> * Objective: <ObjectiveRFun:function> #> * Search Space: #> <ParamSet> #> id class lower upper nlevels default value #> 1: x1 ParamDbl -10 10 Inf <NoDefault[3]> #> 2: x2 ParamDbl -5 5 Inf <NoDefault[3]> #> * Terminator: <TerminatorEvals> #> * Terminated: TRUE #> * Result: #> x1 x2 x_domain z #> 1: -8.079517 2.656002 <list[2]> -123.587 #> * Archive: #> <Archive> #> x1 x2 z timestamp batch_nr #> 1: -8.08 2.66 -123.59 2021-09-28 04:10:51 1 #> 2: 5.39 4.91 -64.04 2021-09-28 04:10:51 2 #> 3: 9.41 -1.11 -48.49 2021-09-28 04:10:51 3 #> 4: -0.78 -1.85 0.96 2021-09-28 04:10:51 4 #> 5: -6.51 0.32 -73.35 2021-09-28 04:10:51 5 #> 6: -0.13 2.79 -28.09 2021-09-28 04:10:51 6 #> 7: -5.92 2.13 -79.03 2021-09-28 04:10:51 7 #> 8: -8.70 -1.46 -106.78 2021-09-28 04:10:51 8 #> 9: 6.50 -2.26 -10.83 2021-09-28 04:10:51 9 #> 10: 1.40 -1.64 7.80 2021-09-28 04:10:51 10 #>