Skip to contents

OptimizerBatchFocusSearch 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 classes

bbotk::Optimizer -> bbotk::OptimizerBatch -> OptimizerBatchFocusSearch

Methods

Inherited methods


Method new()

Creates a new instance of this R6 class.


Method clone()

The objects of this class are cloneable with this method.

Usage

OptimizerBatchFocusSearch$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 = OptimInstanceBatchSingleCrit$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.03039435 <list[1]> 0.0009238167

# returns best scoring evaluation
instance$result
#>              x  x_domain            y
#>          <num>    <list>        <num>
#> 1: -0.03039435 <list[1]> 0.0009238167

# 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.85309290 0.7277674905 <list[1]> 2024-12-18 10:02:35        1
#>   2:  0.10475519 0.0109736497 <list[1]> 2024-12-18 10:02:35        1
#>   3:  0.15413139 0.0237564850 <list[1]> 2024-12-18 10:02:35        1
#>   4:  0.37489549 0.1405466293 <list[1]> 2024-12-18 10:02:35        1
#>   5: -0.51056354 0.2606751291 <list[1]> 2024-12-18 10:02:35        1
#>   6: -0.91076568 0.8294941298 <list[1]> 2024-12-18 10:02:35        1
#>   7:  0.81970911 0.6719230305 <list[1]> 2024-12-18 10:02:35        1
#>   8: -0.85863756 0.7372584621 <list[1]> 2024-12-18 10:02:35        1
#>   9:  0.99378295 0.9876045454 <list[1]> 2024-12-18 10:02:35        1
#>  10:  0.22370483 0.0500438532 <list[1]> 2024-12-18 10:02:35        1
#>  11: -0.65488231 0.4288708381 <list[1]> 2024-12-18 10:02:35        1
#>  12:  0.81888193 0.6705676158 <list[1]> 2024-12-18 10:02:35        1
#>  13: -0.92509767 0.8558056920 <list[1]> 2024-12-18 10:02:35        1
#>  14:  0.18710758 0.0350092468 <list[1]> 2024-12-18 10:02:35        1
#>  15: -0.52604489 0.2767232266 <list[1]> 2024-12-18 10:02:35        1
#>  16:  0.81259453 0.6603098758 <list[1]> 2024-12-18 10:02:35        1
#>  17:  0.63774597 0.4067199198 <list[1]> 2024-12-18 10:02:35        1
#>  18:  0.39965871 0.1597270880 <list[1]> 2024-12-18 10:02:35        1
#>  19: -0.55999934 0.3135992626 <list[1]> 2024-12-18 10:02:35        1
#>  20:  0.45598188 0.2079194719 <list[1]> 2024-12-18 10:02:35        1
#>  21: -0.56583108 0.3201648059 <list[1]> 2024-12-18 10:02:35        1
#>  22: -0.08753960 0.0076631822 <list[1]> 2024-12-18 10:02:35        1
#>  23: -0.33440048 0.1118236833 <list[1]> 2024-12-18 10:02:35        1
#>  24:  0.13670534 0.0186883492 <list[1]> 2024-12-18 10:02:35        1
#>  25: -0.49558855 0.2456080112 <list[1]> 2024-12-18 10:02:35        1
#>  26: -0.07197287 0.0051800935 <list[1]> 2024-12-18 10:02:35        1
#>  27:  0.83532101 0.6977611961 <list[1]> 2024-12-18 10:02:35        1
#>  28:  0.94568844 0.8943266176 <list[1]> 2024-12-18 10:02:35        1
#>  29:  0.63816489 0.4072544310 <list[1]> 2024-12-18 10:02:35        1
#>  30:  0.80584760 0.6493903486 <list[1]> 2024-12-18 10:02:35        1
#>  31:  0.16273209 0.0264817325 <list[1]> 2024-12-18 10:02:35        1
#>  32:  0.54601696 0.2981345231 <list[1]> 2024-12-18 10:02:35        1
#>  33:  0.99024605 0.9805872452 <list[1]> 2024-12-18 10:02:35        1
#>  34:  0.42194250 0.1780354729 <list[1]> 2024-12-18 10:02:35        1
#>  35: -0.57011481 0.3250308950 <list[1]> 2024-12-18 10:02:35        1
#>  36: -0.41648474 0.1734595387 <list[1]> 2024-12-18 10:02:35        1
#>  37:  0.44351946 0.1967095102 <list[1]> 2024-12-18 10:02:35        1
#>  38:  0.73323141 0.5376282957 <list[1]> 2024-12-18 10:02:35        1
#>  39: -0.52309379 0.2736271100 <list[1]> 2024-12-18 10:02:35        1
#>  40: -0.99100738 0.9820956350 <list[1]> 2024-12-18 10:02:35        1
#>  41:  0.88703293 0.7868274161 <list[1]> 2024-12-18 10:02:35        1
#>  42: -0.12372560 0.0153080239 <list[1]> 2024-12-18 10:02:35        1
#>  43:  0.50120666 0.2512081125 <list[1]> 2024-12-18 10:02:35        1
#>  44:  0.33563153 0.1126485232 <list[1]> 2024-12-18 10:02:35        1
#>  45: -0.18405360 0.0338757266 <list[1]> 2024-12-18 10:02:35        1
#>  46: -0.29750237 0.0885076602 <list[1]> 2024-12-18 10:02:35        1
#>  47:  0.47618312 0.2267503666 <list[1]> 2024-12-18 10:02:35        1
#>  48:  0.32857099 0.1079588926 <list[1]> 2024-12-18 10:02:35        1
#>  49: -0.82955060 0.6881541974 <list[1]> 2024-12-18 10:02:35        1
#>  50:  0.71226431 0.5073204521 <list[1]> 2024-12-18 10:02:35        1
#>  51: -0.84603336 0.7157724405 <list[1]> 2024-12-18 10:02:35        1
#>  52:  0.70568961 0.4979978210 <list[1]> 2024-12-18 10:02:35        1
#>  53: -0.78730608 0.6198508608 <list[1]> 2024-12-18 10:02:35        1
#>  54: -0.03039435 0.0009238167 <list[1]> 2024-12-18 10:02:35        1
#>  55: -0.50556178 0.2555927126 <list[1]> 2024-12-18 10:02:35        1
#>  56:  0.37313842 0.1392322814 <list[1]> 2024-12-18 10:02:35        1
#>  57: -0.67275360 0.4525974112 <list[1]> 2024-12-18 10:02:35        1
#>  58:  0.90564960 0.8202011973 <list[1]> 2024-12-18 10:02:35        1
#>  59: -0.35629090 0.1269432039 <list[1]> 2024-12-18 10:02:35        1
#>  60: -0.27693177 0.0766912033 <list[1]> 2024-12-18 10:02:35        1
#>  61:  0.77544683 0.6013177939 <list[1]> 2024-12-18 10:02:35        1
#>  62:  0.65602884 0.4303738331 <list[1]> 2024-12-18 10:02:35        1
#>  63: -0.79868708 0.6379010591 <list[1]> 2024-12-18 10:02:35        1
#>  64:  0.81210316 0.6595115352 <list[1]> 2024-12-18 10:02:35        1
#>  65:  0.54546073 0.2975274068 <list[1]> 2024-12-18 10:02:35        1
#>  66: -0.23325866 0.0544096020 <list[1]> 2024-12-18 10:02:35        1
#>  67:  0.99930491 0.9986103119 <list[1]> 2024-12-18 10:02:35        1
#>  68: -0.30140190 0.0908431071 <list[1]> 2024-12-18 10:02:35        1
#>  69:  0.89463653 0.8003745249 <list[1]> 2024-12-18 10:02:35        1
#>  70: -0.56780005 0.3223968943 <list[1]> 2024-12-18 10:02:35        1
#>  71: -0.93581458 0.8757489324 <list[1]> 2024-12-18 10:02:35        1
#>  72: -0.70936831 0.5032034038 <list[1]> 2024-12-18 10:02:35        1
#>  73:  0.70876778 0.5023517602 <list[1]> 2024-12-18 10:02:35        1
#>  74: -0.57370138 0.3291332711 <list[1]> 2024-12-18 10:02:35        1
#>  75: -0.57937852 0.3356794739 <list[1]> 2024-12-18 10:02:35        1
#>  76: -0.92095862 0.8481647798 <list[1]> 2024-12-18 10:02:35        1
#>  77:  0.88954961 0.7912985024 <list[1]> 2024-12-18 10:02:35        1
#>  78: -0.51014403 0.2602469263 <list[1]> 2024-12-18 10:02:35        1
#>  79:  0.56224514 0.3161195931 <list[1]> 2024-12-18 10:02:35        1
#>  80: -0.42352566 0.1793739877 <list[1]> 2024-12-18 10:02:35        1
#>  81:  0.75071582 0.5635742433 <list[1]> 2024-12-18 10:02:35        1
#>  82: -0.40849981 0.1668720962 <list[1]> 2024-12-18 10:02:35        1
#>  83:  0.96705082 0.9351872806 <list[1]> 2024-12-18 10:02:35        1
#>  84:  0.17967511 0.0322831462 <list[1]> 2024-12-18 10:02:35        1
#>  85:  0.51831676 0.2686522634 <list[1]> 2024-12-18 10:02:35        1
#>  86:  0.67215061 0.4517864450 <list[1]> 2024-12-18 10:02:35        1
#>  87:  0.52563894 0.2762962946 <list[1]> 2024-12-18 10:02:35        1
#>  88: -0.16546015 0.0273770604 <list[1]> 2024-12-18 10:02:35        1
#>  89: -0.72385032 0.5239592832 <list[1]> 2024-12-18 10:02:35        1
#>  90: -0.83831008 0.7027637850 <list[1]> 2024-12-18 10:02:35        1
#>  91:  0.31196525 0.0973223186 <list[1]> 2024-12-18 10:02:35        1
#>  92:  0.20400772 0.0416191491 <list[1]> 2024-12-18 10:02:35        1
#>  93:  0.31399166 0.0985907621 <list[1]> 2024-12-18 10:02:35        1
#>  94: -0.34136567 0.1165305225 <list[1]> 2024-12-18 10:02:35        1
#>  95:  0.95894844 0.9195821122 <list[1]> 2024-12-18 10:02:35        1
#>  96:  0.43037227 0.1852202894 <list[1]> 2024-12-18 10:02:35        1
#>  97:  0.74526061 0.5554133765 <list[1]> 2024-12-18 10:02:35        1
#>  98:  0.96656749 0.9342527204 <list[1]> 2024-12-18 10:02:35        1
#>  99: -0.56287401 0.3168271557 <list[1]> 2024-12-18 10:02:35        1
#> 100:  0.32906013 0.1082805681 <list[1]> 2024-12-18 10:02:35        1
#>                x            y  x_domain           timestamp batch_nr