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
#> 1: -0.01504319 <list[1]> 0.0002262975

# returns best scoring evaluation
instance$result
#>              x  x_domain            y
#> 1: -0.01504319 <list[1]> 0.0002262975

# allows access of data.table of full path of all evaluations
as.data.table(instance$archive$data)
#>                x            y  x_domain           timestamp batch_nr
#>   1: -0.01504319 0.0002262975 <list[1]> 2022-06-30 04:24:06        1
#>   2:  0.25016440 0.0625822272 <list[1]> 2022-06-30 04:24:06        1
#>   3:  0.16855970 0.0284123716 <list[1]> 2022-06-30 04:24:06        1
#>   4: -0.65280251 0.4261511155 <list[1]> 2022-06-30 04:24:06        1
#>   5: -0.13917968 0.0193709832 <list[1]> 2022-06-30 04:24:06        1
#>   6: -0.34992125 0.1224448824 <list[1]> 2022-06-30 04:24:06        1
#>   7: -0.25051042 0.0627554685 <list[1]> 2022-06-30 04:24:06        1
#>   8: -0.65935912 0.4347544538 <list[1]> 2022-06-30 04:24:06        1
#>   9:  0.26103796 0.0681408159 <list[1]> 2022-06-30 04:24:06        1
#>  10: -0.99469158 0.9894113330 <list[1]> 2022-06-30 04:24:06        1
#>  11: -0.44229184 0.1956220709 <list[1]> 2022-06-30 04:24:06        1
#>  12: -0.31512212 0.0993019497 <list[1]> 2022-06-30 04:24:06        1
#>  13: -0.65782835 0.4327381345 <list[1]> 2022-06-30 04:24:06        1
#>  14: -0.70569248 0.4980018709 <list[1]> 2022-06-30 04:24:06        1
#>  15: -0.66518942 0.4424769686 <list[1]> 2022-06-30 04:24:06        1
#>  16:  0.80900762 0.6544933337 <list[1]> 2022-06-30 04:24:06        1
#>  17: -0.56616989 0.3205483476 <list[1]> 2022-06-30 04:24:06        1
#>  18:  0.96180783 0.9250743032 <list[1]> 2022-06-30 04:24:06        1
#>  19: -0.06160539 0.0037952246 <list[1]> 2022-06-30 04:24:06        1
#>  20: -0.16763533 0.0281016048 <list[1]> 2022-06-30 04:24:06        1
#>  21: -0.88948185 0.7911779581 <list[1]> 2022-06-30 04:24:06        1
#>  22: -0.58072997 0.3372473037 <list[1]> 2022-06-30 04:24:06        1
#>  23: -0.53028889 0.2812063049 <list[1]> 2022-06-30 04:24:06        1
#>  24:  0.54796030 0.3002604888 <list[1]> 2022-06-30 04:24:06        1
#>  25: -0.52645061 0.2771502426 <list[1]> 2022-06-30 04:24:06        1
#>  26: -0.21115111 0.0445847915 <list[1]> 2022-06-30 04:24:06        1
#>  27: -0.99722673 0.9944611491 <list[1]> 2022-06-30 04:24:06        1
#>  28:  0.59883152 0.3585991887 <list[1]> 2022-06-30 04:24:06        1
#>  29:  0.45584947 0.2077987351 <list[1]> 2022-06-30 04:24:06        1
#>  30:  0.36612615 0.1340483546 <list[1]> 2022-06-30 04:24:06        1
#>  31: -0.29708364 0.0882586889 <list[1]> 2022-06-30 04:24:06        1
#>  32: -0.26393656 0.0696625063 <list[1]> 2022-06-30 04:24:06        1
#>  33: -0.57211109 0.3273110990 <list[1]> 2022-06-30 04:24:06        1
#>  34: -0.62497232 0.3905903981 <list[1]> 2022-06-30 04:24:06        1
#>  35: -0.72548589 0.5263297748 <list[1]> 2022-06-30 04:24:06        1
#>  36: -0.22976078 0.0527900139 <list[1]> 2022-06-30 04:24:06        1
#>  37: -0.48475707 0.2349894151 <list[1]> 2022-06-30 04:24:06        1
#>  38: -0.49748156 0.2474879019 <list[1]> 2022-06-30 04:24:06        1
#>  39:  0.35327422 0.1248026713 <list[1]> 2022-06-30 04:24:06        1
#>  40: -0.94061604 0.8847585374 <list[1]> 2022-06-30 04:24:06        1
#>  41:  0.15217381 0.0231568699 <list[1]> 2022-06-30 04:24:06        1
#>  42: -0.85150596 0.7250623965 <list[1]> 2022-06-30 04:24:06        1
#>  43:  0.69168840 0.4784328495 <list[1]> 2022-06-30 04:24:06        1
#>  44: -0.70209453 0.4929367235 <list[1]> 2022-06-30 04:24:06        1
#>  45: -0.18240948 0.0332732193 <list[1]> 2022-06-30 04:24:06        1
#>  46:  0.48293200 0.2332233175 <list[1]> 2022-06-30 04:24:06        1
#>  47: -0.22835173 0.0521445106 <list[1]> 2022-06-30 04:24:06        1
#>  48:  0.39042535 0.1524319529 <list[1]> 2022-06-30 04:24:06        1
#>  49:  0.79861587 0.6377873102 <list[1]> 2022-06-30 04:24:06        1
#>  50: -0.25748340 0.0662977024 <list[1]> 2022-06-30 04:24:06        1
#>  51: -0.38902527 0.1513406611 <list[1]> 2022-06-30 04:24:06        1
#>  52:  0.36106310 0.1303665631 <list[1]> 2022-06-30 04:24:06        1
#>  53:  0.26685364 0.0712108658 <list[1]> 2022-06-30 04:24:06        1
#>  54: -0.80929254 0.6549544160 <list[1]> 2022-06-30 04:24:06        1
#>  55:  0.51980626 0.2701985496 <list[1]> 2022-06-30 04:24:06        1
#>  56:  0.69045806 0.4767323355 <list[1]> 2022-06-30 04:24:06        1
#>  57: -0.06619027 0.0043811521 <list[1]> 2022-06-30 04:24:06        1
#>  58: -0.44678864 0.1996200878 <list[1]> 2022-06-30 04:24:06        1
#>  59: -0.10295239 0.0105991941 <list[1]> 2022-06-30 04:24:06        1
#>  60: -0.69679118 0.4855179517 <list[1]> 2022-06-30 04:24:06        1
#>  61: -0.02023281 0.0004093665 <list[1]> 2022-06-30 04:24:06        1
#>  62: -0.11410626 0.0130202382 <list[1]> 2022-06-30 04:24:06        1
#>  63: -0.04568395 0.0020870237 <list[1]> 2022-06-30 04:24:06        1
#>  64: -0.53130401 0.2822839512 <list[1]> 2022-06-30 04:24:06        1
#>  65:  0.85867793 0.7373277798 <list[1]> 2022-06-30 04:24:06        1
#>  66: -0.34775493 0.1209334882 <list[1]> 2022-06-30 04:24:06        1
#>  67: -0.50593951 0.2559747828 <list[1]> 2022-06-30 04:24:06        1
#>  68:  0.08688580 0.0075491427 <list[1]> 2022-06-30 04:24:06        1
#>  69:  0.23926427 0.0572473908 <list[1]> 2022-06-30 04:24:06        1
#>  70: -0.05701458 0.0032506622 <list[1]> 2022-06-30 04:24:06        1
#>  71:  0.53288752 0.2839691093 <list[1]> 2022-06-30 04:24:06        1
#>  72: -0.68684066 0.4717500985 <list[1]> 2022-06-30 04:24:06        1
#>  73:  0.65873766 0.4339353107 <list[1]> 2022-06-30 04:24:06        1
#>  74:  0.38982596 0.1519642774 <list[1]> 2022-06-30 04:24:06        1
#>  75:  0.52146452 0.2719252506 <list[1]> 2022-06-30 04:24:06        1
#>  76:  0.76200307 0.5806486833 <list[1]> 2022-06-30 04:24:06        1
#>  77:  0.74296686 0.5519997552 <list[1]> 2022-06-30 04:24:06        1
#>  78: -0.87681302 0.7688010763 <list[1]> 2022-06-30 04:24:06        1
#>  79: -0.09939255 0.0098788789 <list[1]> 2022-06-30 04:24:06        1
#>  80:  0.27383285 0.0749844306 <list[1]> 2022-06-30 04:24:06        1
#>  81:  0.44089135 0.1943851798 <list[1]> 2022-06-30 04:24:06        1
#>  82:  0.71039477 0.5046607291 <list[1]> 2022-06-30 04:24:06        1
#>  83: -0.40779335 0.1662954186 <list[1]> 2022-06-30 04:24:06        1
#>  84:  0.66967712 0.4484674403 <list[1]> 2022-06-30 04:24:06        1
#>  85: -0.71297241 0.5083296608 <list[1]> 2022-06-30 04:24:06        1
#>  86: -0.93998720 0.8835759271 <list[1]> 2022-06-30 04:24:06        1
#>  87:  0.94637356 0.8956229204 <list[1]> 2022-06-30 04:24:06        1
#>  88: -0.14569844 0.0212280351 <list[1]> 2022-06-30 04:24:06        1
#>  89:  0.45272029 0.2049556623 <list[1]> 2022-06-30 04:24:06        1
#>  90: -0.77225866 0.5963834384 <list[1]> 2022-06-30 04:24:06        1
#>  91:  0.78176844 0.6111618884 <list[1]> 2022-06-30 04:24:06        1
#>  92: -0.85489530 0.7308459664 <list[1]> 2022-06-30 04:24:06        1
#>  93: -0.02491310 0.0006206627 <list[1]> 2022-06-30 04:24:06        1
#>  94: -0.99821270 0.9964285884 <list[1]> 2022-06-30 04:24:06        1
#>  95:  0.52550918 0.2761598998 <list[1]> 2022-06-30 04:24:06        1
#>  96:  0.49787098 0.2478755112 <list[1]> 2022-06-30 04:24:06        1
#>  97:  0.14542205 0.0211475727 <list[1]> 2022-06-30 04:24:06        1
#>  98:  0.70668432 0.4994027212 <list[1]> 2022-06-30 04:24:06        1
#>  99:  0.92249358 0.8509943996 <list[1]> 2022-06-30 04:24:06        1
#> 100:  0.99444852 0.9889278613 <list[1]> 2022-06-30 04:24:06        1
#>                x            y  x_domain           timestamp batch_nr