Function to create a CallbackBatchTuning.
Predefined callbacks are stored in the dictionary mlr_callbacks and can be retrieved with clbk()
.
Tuning callbacks can be called from different stages of the tuning process.
The stages are prefixed with on_*
.
Start Tuning
- on_optimization_begin
Start Tuner Batch
- on_optimizer_before_eval
Start Evaluation
- on_eval_after_design
- on_eval_after_benchmark
- on_eval_before_archive
End Evaluation
- on_optimizer_after_eval
End Tuner Batch
- on_tuning_result_begin
- on_result_begin
- on_result_end
- on_optimization_end
End Tuning
See also the section on parameters for more information on the stages. A tuning callback works with ContextBatchTuning.
Usage
callback_batch_tuning(
id,
label = NA_character_,
man = NA_character_,
on_optimization_begin = NULL,
on_optimizer_before_eval = NULL,
on_eval_after_design = NULL,
on_eval_after_benchmark = NULL,
on_eval_before_archive = NULL,
on_optimizer_after_eval = NULL,
on_tuning_result_begin = NULL,
on_result_begin = NULL,
on_result_end = NULL,
on_result = NULL,
on_optimization_end = NULL
)
Arguments
- id
(
character(1)
)
Identifier for the new instance.- label
(
character(1)
)
Label for the new instance.- man
(
character(1)
)
String in the format[pkg]::[topic]
pointing to a manual page for this object. The referenced help package can be opened via method$help()
.- on_optimization_begin
(
function()
)
Stage called at the beginning of the optimization. Called inOptimizer$optimize()
. The functions must have two arguments namedcallback
andcontext
.- on_optimizer_before_eval
(
function()
)
Stage called after the optimizer proposes points. Called inOptimInstance$eval_batch()
. The functions must have two arguments namedcallback
andcontext
. The argument of$eval_batch(xdt)
is available incontext
.- on_eval_after_design
(
function()
)
Stage called after the design is created. Called inObjectiveTuningBatch$eval_many()
. The functions must have two arguments namedcallback
andcontext
. The arguments of$eval_many(xss, resampling)
are available incontext
. Additionally, thedesign
is available incontext
.- on_eval_after_benchmark
(
function()
)
Stage called after hyperparameter configurations are evaluated. Called inObjectiveTuningBatch$eval_many()
. The functions must have two arguments namedcallback
andcontext
. Thebenchmark_result
is available incontext
.- on_eval_before_archive
(
function()
)
Stage called before performance values are written to the archive. Called inObjectiveTuningBatch$eval_many()
. The functions must have two arguments namedcallback
andcontext
. Theaggregated_performance
is available incontext
.- on_optimizer_after_eval
(
function()
)
Stage called after points are evaluated. Called inOptimInstance$eval_batch()
. The functions must have two arguments namedcallback
andcontext
. The new configurations and performances ininstance$archive
are available incontext
.- on_tuning_result_begin
(
function()
)
Stage called at the beginning of the result writing. Called inTuningInstanceBatch$assign_result()
. The functions must have two arguments namedcallback
andcontext
. The arguments of$assign_result(xdt, y, learner_param_vals, extra)
are available incontext
.- on_result_begin
(
function()
)
Stage called at the beginning of the result writing. Called inOptimInstance$assign_result()
. The functions must have two arguments namedcallback
andcontext
. The arguments of$assign_result(xdt, y, extra)
are available incontext
.- on_result_end
(
function()
)
Stage called after the result is written. Called inOptimInstance$assign_result()
. The functions must have two arguments namedcallback
andcontext
. The final resultinstance$result
is available incontext
.- on_result
(
function()
)
Deprecated. Useon_result_end
instead. Stage called after the result is written. Called inOptimInstance$assign_result()
. The functions must have two arguments namedcallback
andcontext
.- on_optimization_end
(
function()
)
Stage called at the end of the optimization. Called inOptimizer$optimize()
. The functions must have two arguments namedcallback
andcontext
.
Details
When implementing a callback, each function must have two arguments named callback
and context
.
A callback can write data to the state ($state
), e.g. settings that affect the callback itself.
Tuning callbacks access ContextBatchTuning.
Examples
# write archive to disk
callback_batch_tuning("mlr3tuning.backup",
on_optimization_end = function(callback, context) {
saveRDS(context$instance$archive, "archive.rds")
}
)
#> <CallbackBatchTuning:mlr3tuning.backup>
#> * Active Stages: on_optimization_end