Skip to contents

OptimizerFocusSearch class that implements a Focus Search.

Focus Search starts with evaluating n_points drawn uniformly at random. For 1 to maxit batches, n_points are then drawn uniformly at random and if the best value of a batch outperforms the previous best value over all batches evaluated so far, the search space is shrinked around this new best point prior to the next batch being sampled and evaluated.

For details on the shrinking, see shrink_ps.

Depending on the Terminator this procedure simply restarts after maxit is reached.

Dictionary

This Optimizer can be instantiated via the dictionary mlr_optimizers or with the associated sugar function opt():

mlr_optimizers$get("focus_search")
opt("focus_search")

Parameters

n_points

integer(1)
Number of points to evaluate in each random search batch.

maxit

integer(1)
Number of random search batches to run.

Progress Bars

$optimize() supports progress bars via the package progressr combined with a Terminator. Simply wrap the function in progressr::with_progress() to enable them. We recommend to use package progress as backend; enable with progressr::handlers("progress").

Super class

bbotk::Optimizer -> OptimizerFocusSearch

Methods

Inherited methods


Method new()

Creates a new instance of this R6 class.

Usage


Method clone()

The objects of this class are cloneable with this method.

Usage

OptimizerFocusSearch$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

search_space = domain = ps(x = p_dbl(lower = -1, upper = 1))

codomain = ps(y = p_dbl(tags = "minimize"))

objective_function = function(xs) {
  list(y = as.numeric(xs)^2)
}

objective = ObjectiveRFun$new(
 fun = objective_function,
 domain = domain,
 codomain = codomain)

instance = OptimInstanceSingleCrit$new(
 objective = objective,
 search_space = search_space,
 terminator = trm("evals", n_evals = 10))


optimizer = opt("focus_search")

# modifies the instance by reference
optimizer$optimize(instance)
#>               x  x_domain            y
#>           <num>    <list>        <num>
#> 1: 0.0003830018 <list[1]> 1.466903e-07

# returns best scoring evaluation
instance$result
#>               x  x_domain            y
#>           <num>    <list>        <num>
#> 1: 0.0003830018 <list[1]> 1.466903e-07

# allows access of data.table of full path of all evaluations
as.data.table(instance$archive$data)
#>                  x            y  x_domain           timestamp batch_nr
#>              <num>        <num>    <list>              <POSc>    <int>
#>   1: -0.9770409241 9.546090e-01 <list[1]> 2024-02-29 15:30:03        1
#>   2:  0.7764991359 6.029509e-01 <list[1]> 2024-02-29 15:30:03        1
#>   3:  0.9926938377 9.854411e-01 <list[1]> 2024-02-29 15:30:03        1
#>   4:  0.0003830018 1.466903e-07 <list[1]> 2024-02-29 15:30:03        1
#>   5: -0.2820659513 7.956120e-02 <list[1]> 2024-02-29 15:30:03        1
#>   6:  0.5498260446 3.023087e-01 <list[1]> 2024-02-29 15:30:03        1
#>   7:  0.1689505018 2.854427e-02 <list[1]> 2024-02-29 15:30:03        1
#>   8:  0.2679527421 7.179867e-02 <list[1]> 2024-02-29 15:30:03        1
#>   9:  0.7173323096 5.145656e-01 <list[1]> 2024-02-29 15:30:03        1
#>  10:  0.1337886774 1.789941e-02 <list[1]> 2024-02-29 15:30:03        1
#>  11: -0.4940059613 2.440419e-01 <list[1]> 2024-02-29 15:30:03        1
#>  12:  0.8376064291 7.015845e-01 <list[1]> 2024-02-29 15:30:03        1
#>  13:  0.7347004097 5.397847e-01 <list[1]> 2024-02-29 15:30:03        1
#>  14: -0.5029226062 2.529311e-01 <list[1]> 2024-02-29 15:30:03        1
#>  15: -0.1942375763 3.772824e-02 <list[1]> 2024-02-29 15:30:03        1
#>  16:  0.5392603520 2.908017e-01 <list[1]> 2024-02-29 15:30:03        1
#>  17: -0.7610292509 5.791655e-01 <list[1]> 2024-02-29 15:30:03        1
#>  18: -0.6106100767 3.728447e-01 <list[1]> 2024-02-29 15:30:03        1
#>  19: -0.6708615036 4.500552e-01 <list[1]> 2024-02-29 15:30:03        1
#>  20:  0.3264131625 1.065456e-01 <list[1]> 2024-02-29 15:30:03        1
#>  21:  0.7131500090 5.085829e-01 <list[1]> 2024-02-29 15:30:03        1
#>  22:  0.8530928968 7.277675e-01 <list[1]> 2024-02-29 15:30:03        1
#>  23:  0.1047551893 1.097365e-02 <list[1]> 2024-02-29 15:30:03        1
#>  24:  0.1541313888 2.375649e-02 <list[1]> 2024-02-29 15:30:03        1
#>  25:  0.3748954912 1.405466e-01 <list[1]> 2024-02-29 15:30:03        1
#>  26: -0.5105635407 2.606751e-01 <list[1]> 2024-02-29 15:30:03        1
#>  27: -0.9107656833 8.294941e-01 <list[1]> 2024-02-29 15:30:03        1
#>  28:  0.8197091133 6.719230e-01 <list[1]> 2024-02-29 15:30:03        1
#>  29: -0.8586375616 7.372585e-01 <list[1]> 2024-02-29 15:30:03        1
#>  30:  0.9937829468 9.876045e-01 <list[1]> 2024-02-29 15:30:03        1
#>  31:  0.2237048349 5.004385e-02 <list[1]> 2024-02-29 15:30:03        1
#>  32: -0.6548823086 4.288708e-01 <list[1]> 2024-02-29 15:30:03        1
#>  33:  0.8188819303 6.705676e-01 <list[1]> 2024-02-29 15:30:03        1
#>  34: -0.9250976662 8.558057e-01 <list[1]> 2024-02-29 15:30:03        1
#>  35:  0.1871075807 3.500925e-02 <list[1]> 2024-02-29 15:30:03        1
#>  36: -0.5260448903 2.767232e-01 <list[1]> 2024-02-29 15:30:03        1
#>  37:  0.8125945334 6.603099e-01 <list[1]> 2024-02-29 15:30:03        1
#>  38:  0.6377459681 4.067199e-01 <list[1]> 2024-02-29 15:30:03        1
#>  39:  0.3996587144 1.597271e-01 <list[1]> 2024-02-29 15:30:03        1
#>  40: -0.5599993416 3.135993e-01 <list[1]> 2024-02-29 15:30:03        1
#>  41:  0.4559818767 2.079195e-01 <list[1]> 2024-02-29 15:30:03        1
#>  42: -0.5658310754 3.201648e-01 <list[1]> 2024-02-29 15:30:03        1
#>  43: -0.0875396035 7.663182e-03 <list[1]> 2024-02-29 15:30:03        1
#>  44: -0.3344004834 1.118237e-01 <list[1]> 2024-02-29 15:30:03        1
#>  45:  0.1367053371 1.868835e-02 <list[1]> 2024-02-29 15:30:03        1
#>  46: -0.4955885503 2.456080e-01 <list[1]> 2024-02-29 15:30:03        1
#>  47: -0.0719728665 5.180094e-03 <list[1]> 2024-02-29 15:30:03        1
#>  48:  0.8353210138 6.977612e-01 <list[1]> 2024-02-29 15:30:03        1
#>  49:  0.9456884358 8.943266e-01 <list[1]> 2024-02-29 15:30:03        1
#>  50:  0.6381648933 4.072544e-01 <list[1]> 2024-02-29 15:30:03        1
#>  51:  0.8058475964 6.493903e-01 <list[1]> 2024-02-29 15:30:03        1
#>  52:  0.1627320880 2.648173e-02 <list[1]> 2024-02-29 15:30:03        1
#>  53:  0.5460169623 2.981345e-01 <list[1]> 2024-02-29 15:30:03        1
#>  54:  0.9902460529 9.805872e-01 <list[1]> 2024-02-29 15:30:03        1
#>  55:  0.4219424995 1.780355e-01 <list[1]> 2024-02-29 15:30:03        1
#>  56: -0.5701148086 3.250309e-01 <list[1]> 2024-02-29 15:30:03        1
#>  57: -0.4164847401 1.734595e-01 <list[1]> 2024-02-29 15:30:03        1
#>  58:  0.4435194586 1.967095e-01 <list[1]> 2024-02-29 15:30:03        1
#>  59:  0.7332314067 5.376283e-01 <list[1]> 2024-02-29 15:30:03        1
#>  60: -0.5230937870 2.736271e-01 <list[1]> 2024-02-29 15:30:03        1
#>  61: -0.9910073839 9.820956e-01 <list[1]> 2024-02-29 15:30:03        1
#>  62:  0.8870329284 7.868274e-01 <list[1]> 2024-02-29 15:30:03        1
#>  63: -0.1237255991 1.530802e-02 <list[1]> 2024-02-29 15:30:03        1
#>  64:  0.5012066565 2.512081e-01 <list[1]> 2024-02-29 15:30:03        1
#>  65:  0.3356315289 1.126485e-01 <list[1]> 2024-02-29 15:30:03        1
#>  66: -0.1840535970 3.387573e-02 <list[1]> 2024-02-29 15:30:03        1
#>  67: -0.2975023701 8.850766e-02 <list[1]> 2024-02-29 15:30:03        1
#>  68:  0.4761831230 2.267504e-01 <list[1]> 2024-02-29 15:30:03        1
#>  69:  0.3285709857 1.079589e-01 <list[1]> 2024-02-29 15:30:03        1
#>  70: -0.8295505997 6.881542e-01 <list[1]> 2024-02-29 15:30:03        1
#>  71:  0.7122643134 5.073205e-01 <list[1]> 2024-02-29 15:30:03        1
#>  72: -0.8460333566 7.157724e-01 <list[1]> 2024-02-29 15:30:03        1
#>  73:  0.7056896067 4.979978e-01 <list[1]> 2024-02-29 15:30:03        1
#>  74: -0.7873060782 6.198509e-01 <list[1]> 2024-02-29 15:30:03        1
#>  75: -0.0303943530 9.238167e-04 <list[1]> 2024-02-29 15:30:03        1
#>  76: -0.5055617793 2.555927e-01 <list[1]> 2024-02-29 15:30:03        1
#>  77:  0.3731384212 1.392323e-01 <list[1]> 2024-02-29 15:30:03        1
#>  78: -0.6727536037 4.525974e-01 <list[1]> 2024-02-29 15:30:03        1
#>  79:  0.9056495996 8.202012e-01 <list[1]> 2024-02-29 15:30:03        1
#>  80: -0.3562908978 1.269432e-01 <list[1]> 2024-02-29 15:30:03        1
#>  81: -0.2769317664 7.669120e-02 <list[1]> 2024-02-29 15:30:03        1
#>  82:  0.7754468350 6.013178e-01 <list[1]> 2024-02-29 15:30:03        1
#>  83:  0.6560288356 4.303738e-01 <list[1]> 2024-02-29 15:30:03        1
#>  84: -0.7986870846 6.379011e-01 <list[1]> 2024-02-29 15:30:03        1
#>  85:  0.8121031555 6.595115e-01 <list[1]> 2024-02-29 15:30:03        1
#>  86:  0.5454607289 2.975274e-01 <list[1]> 2024-02-29 15:30:03        1
#>  87: -0.2332586590 5.440960e-02 <list[1]> 2024-02-29 15:30:03        1
#>  88:  0.9993049144 9.986103e-01 <list[1]> 2024-02-29 15:30:03        1
#>  89: -0.3014019029 9.084311e-02 <list[1]> 2024-02-29 15:30:03        1
#>  90:  0.8946365323 8.003745e-01 <list[1]> 2024-02-29 15:30:03        1
#>  91: -0.5678000478 3.223969e-01 <list[1]> 2024-02-29 15:30:03        1
#>  92: -0.9358145823 8.757489e-01 <list[1]> 2024-02-29 15:30:03        1
#>  93: -0.7093683132 5.032034e-01 <list[1]> 2024-02-29 15:30:03        1
#>  94:  0.7087677759 5.023518e-01 <list[1]> 2024-02-29 15:30:03        1
#>  95: -0.5737013780 3.291333e-01 <list[1]> 2024-02-29 15:30:03        1
#>  96: -0.5793785239 3.356795e-01 <list[1]> 2024-02-29 15:30:03        1
#>  97: -0.9209586200 8.481648e-01 <list[1]> 2024-02-29 15:30:03        1
#>  98:  0.8895496065 7.912985e-01 <list[1]> 2024-02-29 15:30:03        1
#>  99: -0.5101440251 2.602469e-01 <list[1]> 2024-02-29 15:30:03        1
#> 100:  0.5622451361 3.161196e-01 <list[1]> 2024-02-29 15:30:03        1
#>                  x            y  x_domain           timestamp batch_nr