Skip to contents

OptimizerIrace 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 OptimizerIrace.

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 OptimizerIrace. 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.

fun = function(xs, instances) {
 # function to evaluate configuration in `xs` on instance `instances`
}

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():

mlr_optimizers$get("irace")
opt("irace")

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 -> OptimizerIrace

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

OptimizerIrace$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

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 = OptimInstanceSingleCrit$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)
#> # 2023-11-13 12:08:02 UTC: Initialization
#> # Elitist race
#> # Elitist new instances: 1
#> # Elitist limit: 2
#> # nbIterations: 3
#> # minNbSurvival: 3
#> # nbParameters: 2
#> # seed: 1542028489
#> # confidence level: 0.95
#> # budget: 1000
#> # mu: 5
#> # deterministic: FALSE
#> 
#> # 2023-11-13 12:08:02 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|         46|     2.960161511|         55|00:00:00|   NA|  NA|    NA|
#> |x|          2|         55|         46|     2.960161511|        110|00:00:00|+1.00|1.00|0.0000|
#> |x|          3|         55|         46|     2.960161511|        165|00:00:00|+1.00|1.00|0.0000|
#> |x|          4|         55|         46|     2.960161511|        220|00:00:00|+1.00|1.00|0.0000|
#> |-|          5|          1|         46|     2.960161511|        275|00:00:00|   NA|  NA|    NA|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> Best-so-far configuration:          46    mean value:      2.960161511
#> Description of the best-so-far configuration:
#>    .ID.               x1               x2 .PARENT.
#> 46   46 8.69821823085658 1.55965560232289       NA
#> 
#> # 2023-11-13 12:08:02 UTC: Elite configurations (first number is the configuration ID; listed from best to worst according to the sum of ranks):
#>                  x1               x2
#> 46 8.69821823085658 1.55965560232289
#> # 2023-11-13 12:08:02 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|        100|    0.5798388170|         52|00:00:00|   NA|  NA|    NA|
#> |x|          5|         52|        100|    0.5798388170|        103|00:00:00|+1.00|1.00|0.0000|
#> |x|          3|         52|        100|    0.5798388170|        154|00:00:00|+1.00|1.00|0.0000|
#> |x|          4|         52|        100|    0.5798388170|        205|00:00:00|+1.00|1.00|0.0000|
#> |-|          2|          2|        100|    0.5798388170|        256|00:00:00|+1.00|1.00|0.0000|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> Best-so-far configuration:          46    mean value:      2.960161511
#> Description of the best-so-far configuration:
#>    .ID.               x1               x2 .PARENT.
#> 46   46 8.69821823085658 1.55965560232289       NA
#> 
#> # 2023-11-13 12:08:03 UTC: Elite configurations (first number is the configuration ID; listed from best to worst according to the sum of ranks):
#>                   x1               x2
#> 46  8.69821823085658 1.55965560232289
#> 100 9.42964315013221 2.05268249042744
#> # 2023-11-13 12:08:03 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|        163|    0.4479977085|         60|00:00:00|   NA|  NA|    NA|
#> |x|          6|         60|        163|    0.4479977085|        118|00:00:00|+1.00|1.00|0.0000|
#> |x|          5|         60|        163|    0.4479977085|        176|00:00:00|+1.00|1.00|0.0000|
#> |x|          1|         60|        163|    0.4479977085|        235|00:00:00|+1.00|1.00|0.0000|
#> |-|          4|          3|        163|    0.4479977085|        293|00:00:00|+1.00|1.00|0.0000|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> Best-so-far configuration:         100    mean value:     0.5798388170
#> Description of the best-so-far configuration:
#>     .ID.               x1               x2 .PARENT.
#> 100  100 9.42964315013221 2.05268249042744       46
#> 
#> # 2023-11-13 12:08:04 UTC: Elite configurations (first number is the configuration ID; listed from best to worst according to the sum of ranks):
#>                   x1               x2
#> 100 9.42964315013221 2.05268249042744
#> 46  8.69821823085658 1.55965560232289
#> 163 9.41754235002035 2.24561208926435
#> # 2023-11-13 12:08:04 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|        169|    0.4282209997|         21|00:00:00|   NA|  NA|    NA|
#> |x|          4|         21|        169|    0.4282209997|         39|00:00:00|+1.00|1.00|0.0000|
#> |x|          2|         21|        169|    0.4282209997|         58|00:00:00|+1.00|1.00|0.0000|
#> |x|          7|         21|        169|    0.4282209997|         76|00:00:00|+1.00|1.00|0.0000|
#> |-|          6|          4|        169|    0.4282209997|         94|00:00:00|+1.00|1.00|0.0000|
#> |!|          3|          4|        169|    0.4282209997|         96|00:00:00|+1.00|1.00|0.0000|
#> |!|          5|          4|        169|    0.4282209997|         97|00:00:00|+1.00|1.00|0.0000|
#> |-|          1|          1|        169|    0.4282209997|         98|00:00:00|   NA|  NA|    NA|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> Best-so-far configuration:         169    mean value:     0.4282209997
#> Description of the best-so-far configuration:
#>     .ID.               x1               x2 .PARENT.
#> 169  169 9.40891447445399 2.29098943275457      163
#> 
#> # 2023-11-13 12:08:04 UTC: Elite configurations (first number is the configuration ID; listed from best to worst according to the sum of ranks):
#>                   x1               x2
#> 169 9.40891447445399 2.29098943275457
#> # 2023-11-13 12:08:04 UTC: Iteration 5 of 5
#> # experimentsUsedSoFar: 922
#> # remainingBudget: 78
#> # currentBudget: 78
#> # nbConfigurations: 8
#> # 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|          8|        185|    0.4226033722|          8|00:00:00|   NA|  NA|    NA|
#> |x|          2|          8|        185|    0.4226033722|         15|00:00:00|+1.00|1.00|0.0000|
#> |x|          4|          8|        185|    0.4226033722|         22|00:00:00|+1.00|1.00|0.0000|
#> |x|          8|          8|        185|    0.4226033722|         29|00:00:00|+1.00|1.00|0.0000|
#> |-|          6|          2|        185|    0.4226033722|         36|00:00:00|+1.00|1.00|0.0000|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> Best-so-far configuration:         169    mean value:     0.4282209997
#> Description of the best-so-far configuration:
#>     .ID.               x1               x2 .PARENT.
#> 169  169 9.40891447445399 2.29098943275457      163
#> 
#> # 2023-11-13 12:08:05 UTC: Elite configurations (first number is the configuration ID; listed from best to worst according to the sum of ranks):
#>                   x1               x2
#> 169 9.40891447445399 2.29098943275457
#> 185 9.41458075579930 2.31079442498470
#> # 2023-11-13 12:08:05 UTC: Iteration 6 of 6
#> # experimentsUsedSoFar: 958
#> # remainingBudget: 42
#> # currentBudget: 42
#> # nbConfigurations: 6
#> # 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|          6|        185|    0.4226033722|          6|00:00:00|   NA|  NA|    NA|
#> |x|          9|          6|        185|    0.4226033722|         10|00:00:00|+1.00|1.00|0.0000|
#> |x|          4|          6|        185|    0.4226033722|         14|00:00:00|+1.00|1.00|0.0000|
#> |x|          1|          6|        185|    0.4226033722|         19|00:00:00|+1.00|1.00|0.0000|
#> |-|          3|          2|        185|    0.4226033722|         24|00:00:00|+1.00|1.00|0.0000|
#> |.|          8|          2|        185|    0.4226033722|         24|00:00:00|+1.00|1.00|0.0000|
#> +-+-----------+-----------+-----------+----------------+-----------+--------+-----+----+------+
#> Best-so-far configuration:         169    mean value:     0.4282209997
#> Description of the best-so-far configuration:
#>     .ID.               x1               x2 .PARENT.
#> 169  169 9.40891447445399 2.29098943275457      163
#> 
#> # 2023-11-13 12:08:05 UTC: Elite configurations (first number is the configuration ID; listed from best to worst according to the sum of ranks):
#>                   x1               x2
#> 169 9.40891447445399 2.29098943275457
#> 185 9.41458075579930 2.31079442498470
#> # 2023-11-13 12:08:05 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: 982
#> # timeUsed: 0
#> # remainingBudget: 18
#> # currentBudget: 18
#> # number of elites: 2
#> # nbConfigurations: 3
#> # Total CPU user time: 2.915, CPU sys time: 0.036, Wall-clock time: 2.952
#>          x1       x2 configuration  x_domain        y
#> 1: 9.408914 2.290989           169 <list[2]> 0.428221

# best scoring configuration
instance$result
#>          x1       x2 configuration  x_domain        y
#> 1: 9.408914 2.290989           169 <list[2]> 0.428221

# all evaluations
as.data.table(instance$archive)
#>             x1        x2           y race step instance configuration
#>   1:  8.337587 13.455032 143.4663427    1    1       10             1
#>   2:  2.357622  1.857398   4.4291131    1    1       10             2
#>   3:  4.635557  4.254584  17.4216271    1    1       10             3
#>   4:  6.190329  2.133996  20.6337066    1    1       10             4
#>   5: -1.308257  5.983118  17.8751273    1    1       10             5
#>  ---                                                                 
#> 978:  9.414581  2.310794   0.4226034    6    1        6           185
#> 979:  9.416996  2.275025   0.4355888    6    1        6           190
#> 980:  9.413195  2.306312   0.4237919    6    1        6           191
#> 981:  9.405983  2.285671   0.4296927    6    1        6           192
#> 982:  9.413416  2.290796   0.4290050    6    1        6           193
#>                timestamp batch_nr
#>   1: 2023-11-13 12:08:02        1
#>   2: 2023-11-13 12:08:02        1
#>   3: 2023-11-13 12:08:02        1
#>   4: 2023-11-13 12:08:02        1
#>   5: 2023-11-13 12:08:02        1
#>  ---                             
#> 978: 2023-11-13 12:08:05       33
#> 979: 2023-11-13 12:08:05       33
#> 980: 2023-11-13 12:08:05       33
#> 981: 2023-11-13 12:08:05       33
#> 982: 2023-11-13 12:08:05       33