The TuningInstanceMultiCrit specifies a tuning problem for Tuners. The function ti() creates a TuningInstanceMultiCrit and the function tune() creates an instance internally.

The instance contains an ObjectiveTuning object that encodes the black box objective function a Tuner has to optimize. The instance allows the basic operations of querying the objective at design points ($eval_batch()). This operation is usually done by the Tuner. Evaluations of hyperparameter configurations are performed in batches by calling mlr3::benchmark() internally. The evaluated hyperparameter configurations are stored in the Archive ($archive). Before a batch is evaluated, the bbotk::Terminator is queried for the remaining budget. If the available budget is exhausted, an exception is raised, and no further evaluations can be performed from this point on. The tuner is also supposed to store its final result, consisting of a selected hyperparameter configuration and associated estimated performance values, by calling the method instance$assign_result. ## Resources ## Analysis For analyzing the tuning results, it is recommended to pass the ArchiveTuning to as.data.table(). The returned data table is joined with the benchmark result which adds the mlr3::ResampleResult for each hyperparameter evaluation. The archive provides various getters (e.g. $learners()) to ease the access. All getters extract by position (i) or unique hash (uhash). For a complete list of all getters see the methods section.

The benchmark result ($benchmark_result) allows to score the hyperparameter configurations again on a different measure. Alternatively, measures can be supplied to as.data.table(). The mlr3viz package provides visualizations for tuning results. ## Super classes bbotk::OptimInstance -> bbotk::OptimInstanceMultiCrit -> TuningInstanceMultiCrit ## Active bindings result_learner_param_vals (list()) List of param values for the optimal learner call. ## Methods ### Public methods Inherited methods ### Method new() Creates a new instance of this R6 class. #### Usage TuningInstanceMultiCrit$new(
learner,
resampling,
measures,
terminator,
search_space = NULL,
store_benchmark_result = TRUE,
store_models = FALSE,
check_values = FALSE,
allow_hotstart = FALSE,
keep_hotstart_stack = FALSE,
evaluate_default = FALSE,
callbacks = list()
)

#### Arguments

task

learner

(mlr3::Learner)
Learner to tune.

resampling

(mlr3::Resampling)
Resampling that is used to evaluated the performance of the hyperparameter configurations. Uninstantiated resamplings are instantiated during construction so that all configurations are evaluated on the same data splits. Already instantiated resamplings are kept unchanged. Specialized Tuner change the resampling e.g. to evaluate a hyperparameter configuration on different data splits. This field, however, always returns the resampling passed in construction.

measures

(list of mlr3::Measure)
Measures to optimize.

terminator

(Terminator)
Stop criterion of the tuning process.

search_space

Hyperparameter search space. If NULL (default), the search space is constructed from the TuneToken of the learner's parameter set (learner$param_set). store_benchmark_result (logical(1)) If TRUE (default), store resample result of evaluated hyperparameter configurations in archive as mlr3::BenchmarkResult. store_models (logical(1)) If TRUE, fitted models are stored in the benchmark result (archive$benchmark_result). If store_benchmark_result = FALSE, models are only stored temporarily and not accessible after the tuning. This combination is needed for measures that require a model.

check_values

(logical(1))
If TRUE, hyperparameter values are checked before evaluation and performance scores after. If FALSE (default), values are unchecked but computational overhead is reduced.

allow_hotstart

(logical(1))
Allow to hotstart learners with previously fitted models. See also mlr3::HotstartStack. The learner must support hotstarting. Sets store_models = TRUE.

keep_hotstart_stack

(logical(1))
If TRUE, mlr3::HotstartStack is kept in $objective$hotstart_stack after tuning.

evaluate_default

(logical(1))
If TRUE, learner is evaluated with hyperparameters set to their default values at the start of the optimization.

callbacks

(list of CallbackTuning)
List of callbacks.

### Method assign_result()

The Tuner object writes the best found points and estimated performance values here. For internal use.

#### Arguments

deep

Whether to make a deep clone.

## Examples

# Hyperparameter optimization on the Palmer Penguins data set

# Load learner and set search space
learner = lrn("classif.rpart",
cp = to_tune(1e-04, 1e-1, logscale = TRUE)
)

# Construct tuning instance
instance = ti(
learner = learner,
resampling = rsmp("cv", folds = 3),
measures = msrs(c("classif.ce", "time_train")),
terminator = trm("evals", n_evals = 4)
)

# Choose optimization algorithm
tuner = tnr("random_search", batch_size = 2)

# Run tuning
tuner$optimize(instance) #> cp learner_param_vals x_domain classif.ce time_train #> 1: -5.315101 <list[2]> <list[1]> 0.05799644 0.006 # Optimal hyperparameter configurations instance$result
#>           cp learner_param_vals  x_domain classif.ce time_train
#> 1: -5.315101          <list[2]> <list[1]> 0.05799644      0.006

# Inspect all evaluated configurations
as.data.table(instance\$archive)
#>           cp classif.ce  time_train x_domain_cp runtime_learners
#> 1: -6.418558 0.05799644 0.006333333 0.001631006            0.035
#> 2: -4.085352 0.05799644 0.006333333 0.016817219            0.036
#> 3: -5.322158 0.05799644 0.006333333 0.004882206            0.035
#> 4: -5.315101 0.05799644 0.006000000 0.004916781            0.035
#>              timestamp batch_nr warnings errors      resample_result
#> 1: 2022-11-18 12:11:44        1        0      0 <ResampleResult[21]>
#> 2: 2022-11-18 12:11:44        1        0      0 <ResampleResult[21]>
#> 3: 2022-11-18 12:11:44        2        0      0 <ResampleResult[21]>
#> 4: 2022-11-18 12:11:44        2        0      0 <ResampleResult[21]>