OptimizerBatchIrace
class that implements iterated racing. Calls
irace::irace()
from package irace.
Source
Lopez-Ibanez M, Dubois-Lacoste J, Caceres LP, Birattari M, Stuetzle T (2016). “The irace package: Iterated racing for automatic algorithm configuration.” Operations Research Perspectives, 3, 43–58. doi:10.1016/j.orp.2016.09.002 .
Parameters
instances
list()
A list of instances where the configurations executed on.targetRunnerParallel
function()
A function that executes the objective function with a specific parameter configuration and instance. A default function is provided, see section "Target Runner and Instances".
For the meaning of all other parameters, see irace::defaultScenario()
. Note
that we have removed all control parameters which refer to the termination of
the algorithm. Use TerminatorEvals instead. Other terminators do not work
with OptimizerBatchIrace
.
In contrast to irace::defaultScenario()
, we set digits = 15
.
This represents double parameters with a higher precision and avoids rounding errors.
Target Runner and Instances
The irace package uses a targetRunner
script or R function to evaluate a
configuration on a particular instance. Usually it is not necessary to
specify a targetRunner
function when using OptimizerBatchIrace
. A default
function is used that forwards several configurations and instances to the
user defined objective function. As usually, the user defined function has
a xs
, xss
or xdt
parameter depending on the used Objective class.
For irace, the function needs an additional instances
parameter.
Archive
The Archive holds the following additional columns:
"race"
(integer(1)
)
Race iteration."step"
(integer(1)
)
Step number of race."instance"
(integer(1)
)
Identifies instances across races and steps."configuration"
(integer(1)
)
Identifies configurations across races and steps.
Result
The optimization result (instance$result
) is the best performing elite of
the final race. The reported performance is the average performance estimated
on all used instances.
Dictionary
This Optimizer can be instantiated via the dictionary
mlr_optimizers or with the associated sugar function opt()
:
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
-> OptimizerBatchIrace
Examples
# \donttest{
library(data.table)
search_space = domain = ps(
x1 = p_dbl(-5, 10),
x2 = p_dbl(0, 15)
)
codomain = ps(y = p_dbl(tags = "minimize"))
# branin function with noise
# the noise generates different instances of the branin function
# the noise values are passed via the `instances` parameter
fun = function(xdt, instances) {
ys = branin(xdt[["x1"]], xdt[["x2"]], noise = as.numeric(instances))
data.table(y = ys)
}
# define objective with instances as a constant
objective = ObjectiveRFunDt$new(
fun = fun,
domain = domain,
codomain = codomain,
constants = ps(instances = p_uty()))
instance = OptimInstanceBatchSingleCrit$new(
objective = objective,
search_space = search_space,
terminator = trm("evals", n_evals = 1000))
# create instances of branin function
instances = rnorm(10, mean = 0, sd = 0.1)
# load optimizer irace and set branin instances
optimizer = opt("irace", instances = instances)
# modifies the instance by reference
optimizer$optimize(instance)
#> # 2024-11-08 08:27:55 UTC: Initialization
#> # Elitist race
#> # Elitist new instances: 1
#> # Elitist limit: 2
#> # nbIterations: 3
#> # minNbSurvival: 3
#> # nbParameters: 2
#> # seed: 1825109359
#> # confidence level: 0.95
#> # budget: 1000
#> # mu: 5
#> # deterministic: FALSE
#>
#> # 2024-11-08 08:27:56 UTC: Iteration 1 of 3
#> # experimentsUsedSoFar: 0
#> # remainingBudget: 1000
#> # currentBudget: 333
#> # nbConfigurations: 55
#> # Markers:
#> x No test is performed.
#> c Configurations are discarded only due to capping.
#> - The test is performed and some configurations are discarded.
#> = The test is performed but no configuration is discarded.
#> ! The test is performed and configurations could be discarded but elite configurations are preserved.
#> . All alive configurations are elite and nothing is discarded
#>
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> | | Instance| Alive| Best| Mean best| Exp so far| W time| rho|KenW| Qvar|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> |x| 1| 55| 8| 1.073433210| 55|00:00:00| NA| NA| NA|
#> |x| 2| 55| 8| 1.073433210| 110|00:00:00|+1.00|1.00|0.0000|
#> |x| 3| 55| 8| 1.073433210| 165|00:00:00|+1.00|1.00|0.0000|
#> |x| 4| 55| 8| 1.073433210| 220|00:00:00|+1.00|1.00|0.0000|
#> |-| 5| 1| 8| 1.073433210| 275|00:00:00| NA| NA| NA|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> Best-so-far configuration: 8 mean value: 1.073433210
#> Description of the best-so-far configuration:
#> .ID. x1 x2 .PARENT.
#> 8 8 -2.92801648145542 11.0913207870908 NA
#>
#> # 2024-11-08 08:27:57 UTC: Elite configurations (first number is the configuration ID; listed from best to worst according to the sum of ranks):
#> x1 x2
#> 8 -2.92801648145542 11.0913207870908
#> # 2024-11-08 08:27:57 UTC: Iteration 2 of 3
#> # experimentsUsedSoFar: 275
#> # remainingBudget: 725
#> # currentBudget: 362
#> # nbConfigurations: 52
#> # Markers:
#> x No test is performed.
#> c Configurations are discarded only due to capping.
#> - The test is performed and some configurations are discarded.
#> = The test is performed but no configuration is discarded.
#> ! The test is performed and configurations could be discarded but elite configurations are preserved.
#> . All alive configurations are elite and nothing is discarded
#>
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> | | Instance| Alive| Best| Mean best| Exp so far| W time| rho|KenW| Qvar|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> |x| 6| 52| 103| 0.3998430081| 52|00:00:00| NA| NA| NA|
#> |x| 3| 52| 103| 0.3998430081| 103|00:00:00|+1.00|1.00|0.0000|
#> |x| 4| 52| 103| 0.3998430081| 154|00:00:00|+1.00|1.00|0.0000|
#> |x| 2| 52| 103| 0.3998430081| 205|00:00:00|+1.00|1.00|0.0000|
#> |-| 1| 2| 103| 0.3998430081| 256|00:00:00|+1.00|1.00|0.0000|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> Best-so-far configuration: 8 mean value: 1.073433210
#> Description of the best-so-far configuration:
#> .ID. x1 x2 .PARENT.
#> 8 8 -2.92801648145542 11.0913207870908 NA
#>
#> # 2024-11-08 08:27:58 UTC: Elite configurations (first number is the configuration ID; listed from best to worst according to the sum of ranks):
#> x1 x2
#> 8 -2.92801648145542 11.0913207870908
#> 103 -3.16155757545009 12.3295144232742
#> # 2024-11-08 08:27:59 UTC: Iteration 3 of 3
#> # experimentsUsedSoFar: 531
#> # remainingBudget: 469
#> # currentBudget: 469
#> # nbConfigurations: 60
#> # Markers:
#> x No test is performed.
#> c Configurations are discarded only due to capping.
#> - The test is performed and some configurations are discarded.
#> = The test is performed but no configuration is discarded.
#> ! The test is performed and configurations could be discarded but elite configurations are preserved.
#> . All alive configurations are elite and nothing is discarded
#>
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> | | Instance| Alive| Best| Mean best| Exp so far| W time| rho|KenW| Qvar|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> |x| 7| 60| 159| 0.3981674475| 60|00:00:00| NA| NA| NA|
#> |x| 4| 60| 159| 0.3981674475| 118|00:00:00|+1.00|1.00|0.0000|
#> |x| 1| 60| 159| 0.3981674475| 176|00:00:00|+1.00|1.00|0.0000|
#> |x| 3| 60| 159| 0.3981674475| 234|00:00:00|+1.00|1.00|0.0000|
#> |-| 5| 3| 159| 0.3981674475| 293|00:00:00|+1.00|1.00|0.0000|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> Best-so-far configuration: 103 mean value: 0.3998430081
#> Description of the best-so-far configuration:
#> .ID. x1 x2 .PARENT.
#> 103 103 -3.16155757545009 12.3295144232742 8
#>
#> # 2024-11-08 08:28:00 UTC: Elite configurations (first number is the configuration ID; listed from best to worst according to the sum of ranks):
#> x1 x2
#> 103 -3.16155757545009 12.3295144232742
#> 8 -2.92801648145542 11.0913207870908
#> 159 -3.14774655885740 12.2798809912712
#> # 2024-11-08 08:28:01 UTC: Iteration 4 of 4
#> # experimentsUsedSoFar: 824
#> # remainingBudget: 176
#> # currentBudget: 176
#> # nbConfigurations: 21
#> # Markers:
#> x No test is performed.
#> c Configurations are discarded only due to capping.
#> - The test is performed and some configurations are discarded.
#> = The test is performed but no configuration is discarded.
#> ! The test is performed and configurations could be discarded but elite configurations are preserved.
#> . All alive configurations are elite and nothing is discarded
#>
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> | | Instance| Alive| Best| Mean best| Exp so far| W time| rho|KenW| Qvar|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> |x| 8| 21| 159| 0.3981674475| 21|00:00:00| NA| NA| NA|
#> |x| 3| 21| 159| 0.3981674475| 39|00:00:00|+1.00|1.00|0.0000|
#> |x| 6| 21| 159| 0.3981674475| 58|00:00:00|+1.00|1.00|0.0000|
#> |x| 4| 21| 159| 0.3981674475| 76|00:00:00|+1.00|1.00|0.0000|
#> |-| 2| 3| 159| 0.3981674475| 95|00:00:00|+1.00|1.00|0.0000|
#> |.| 7| 3| 159| 0.3981674475| 95|00:00:00|+1.00|1.00|0.0000|
#> |.| 1| 3| 159| 0.3981674475| 95|00:00:00|+1.00|1.00|0.0000|
#> |.| 5| 3| 159| 0.3981674475| 95|00:00:00|+1.00|1.00|0.0000|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> Best-so-far configuration: 159 mean value: 0.3981674475
#> Description of the best-so-far configuration:
#> .ID. x1 x2 .PARENT.
#> 159 159 -3.1477465588574 12.2798809912712 103
#>
#> # 2024-11-08 08:28:01 UTC: Elite configurations (first number is the configuration ID; listed from best to worst according to the sum of ranks):
#> x1 x2
#> 159 -3.14774655885740 12.2798809912712
#> 103 -3.16155757545009 12.3295144232742
#> 8 -2.92801648145542 11.0913207870908
#> # 2024-11-08 08:28:02 UTC: Iteration 5 of 5
#> # experimentsUsedSoFar: 919
#> # remainingBudget: 81
#> # currentBudget: 81
#> # nbConfigurations: 10
#> # Markers:
#> x No test is performed.
#> c Configurations are discarded only due to capping.
#> - The test is performed and some configurations are discarded.
#> = The test is performed but no configuration is discarded.
#> ! The test is performed and configurations could be discarded but elite configurations are preserved.
#> . All alive configurations are elite and nothing is discarded
#>
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> | | Instance| Alive| Best| Mean best| Exp so far| W time| rho|KenW| Qvar|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> |x| 9| 10| 186| 0.3978954629| 10|00:00:00| NA| NA| NA|
#> |x| 4| 10| 186| 0.3978954629| 17|00:00:00|+1.00|1.00|0.0000|
#> |x| 2| 10| 186| 0.3978954629| 24|00:00:00|+1.00|1.00|0.0000|
#> |x| 8| 10| 186| 0.3978954629| 31|00:00:00|+1.00|1.00|0.0000|
#> |-| 6| 4| 186| 0.3978954629| 38|00:00:00|+1.00|1.00|0.0000|
#> |!| 1| 4| 186| 0.3978954629| 39|00:00:00|+1.00|1.00|0.0000|
#> |!| 7| 4| 186| 0.3978954629| 40|00:00:00|+1.00|1.00|0.0000|
#> |!| 5| 4| 186| 0.3978954629| 41|00:00:00|+1.00|1.00|0.0000|
#> |-| 3| 1| 186| 0.3978954629| 42|00:00:00| NA| NA| NA|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> Best-so-far configuration: 186 mean value: 0.3978954629
#> Description of the best-so-far configuration:
#> .ID. x1 x2 .PARENT.
#> 186 186 -3.14284930587778 12.2772967302377 159
#>
#> # 2024-11-08 08:28:02 UTC: Elite configurations (first number is the configuration ID; listed from best to worst according to the sum of ranks):
#> x1 x2
#> 186 -3.14284930587778 12.2772967302377
#> # 2024-11-08 08:28:03 UTC: Iteration 6 of 6
#> # experimentsUsedSoFar: 961
#> # remainingBudget: 39
#> # currentBudget: 39
#> # nbConfigurations: 4
#> # Markers:
#> x No test is performed.
#> c Configurations are discarded only due to capping.
#> - The test is performed and some configurations are discarded.
#> = The test is performed but no configuration is discarded.
#> ! The test is performed and configurations could be discarded but elite configurations are preserved.
#> . All alive configurations are elite and nothing is discarded
#>
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> | | Instance| Alive| Best| Mean best| Exp so far| W time| rho|KenW| Qvar|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> |x| 10| 4| 191| 0.3978876231| 4|00:00:00| NA| NA| NA|
#> |x| 7| 4| 191| 0.3978876231| 7|00:00:00|+1.00|1.00|0.0000|
#> |x| 9| 4| 191| 0.3978876231| 10|00:00:00|+1.00|1.00|0.0000|
#> |x| 2| 4| 191| 0.3978876231| 13|00:00:00|+1.00|1.00|0.0000|
#> |-| 1| 2| 191| 0.3978876231| 16|00:00:00|+1.00|1.00|0.0000|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> Best-so-far configuration: 186 mean value: 0.3978954629
#> Description of the best-so-far configuration:
#> .ID. x1 x2 .PARENT.
#> 186 186 -3.14284930587778 12.2772967302377 159
#>
#> # 2024-11-08 08:28:03 UTC: Elite configurations (first number is the configuration ID; listed from best to worst according to the sum of ranks):
#> x1 x2
#> 186 -3.14284930587778 12.2772967302377
#> 191 -3.14178905230286 12.2757551293537
#> # 2024-11-08 08:28:03 UTC: Stopped because there is not enough budget left to race more than the minimum (3)
#> # You may either increase the budget or set 'minNbSurvival' to a lower value
#> # Iteration: 7
#> # nbIterations: 7
#> # experimentsUsedSoFar: 977
#> # timeUsed: 0
#> # remainingBudget: 23
#> # currentBudget: 23
#> # number of elites: 2
#> # nbConfigurations: 3
#> # Total CPU user time: 8.457, CPU sys time: 0.056, Wall-clock time: 8.517
#> x1 x2 configuration x_domain y
#> <num> <num> <num> <list> <num>
#> 1: -3.142849 12.2773 186 <list[2]> 0.3978955
# best scoring configuration
instance$result
#> x1 x2 configuration x_domain y
#> <num> <num> <num> <list> <num>
#> 1: -3.142849 12.2773 186 <list[2]> 0.3978955
# all evaluations
as.data.table(instance$archive)
#> x1 x2 y race step instance configuration
#> <num> <num> <num> <num> <int> <int> <num>
#> 1: -0.7221691 5.2076993 21.2414221 1 1 1 1
#> 2: -0.4145214 8.2480630 21.2416783 1 1 1 2
#> 3: 9.4870697 8.7013141 38.5257538 1 1 1 3
#> 4: -4.9395193 0.5963386 281.6835388 1 1 1 4
#> 5: -1.2505081 10.1388590 16.8123758 1 1 1 5
#> ---
#> 973: -3.1417891 12.2757551 0.3978876 6 1 8 191
#> 974: -3.1389998 12.2628889 0.3979542 6 1 8 192
#> 975: -3.1381210 12.2702256 0.3979579 6 1 1 190
#> 976: -3.1417891 12.2757551 0.3978876 6 1 1 191
#> 977: -3.1389998 12.2628889 0.3979542 6 1 1 192
#> timestamp batch_nr
#> <POSc> <int>
#> 1: 2024-11-08 08:27:56 1
#> 2: 2024-11-08 08:27:56 1
#> 3: 2024-11-08 08:27:56 1
#> 4: 2024-11-08 08:27:56 1
#> 5: 2024-11-08 08:27:56 1
#> ---
#> 973: 2024-11-08 08:28:03 33
#> 974: 2024-11-08 08:28:03 33
#> 975: 2024-11-08 08:28:03 34
#> 976: 2024-11-08 08:28:03 34
#> 977: 2024-11-08 08:28:03 34
# }