Skip to content

Commit 0d5e8f5

Browse files
authored
refactor: pass extra information of the result in the extra parameter (#458)
* refactor: pass extra information of the result in the extra parameter * ... * ...
1 parent 89bc580 commit 0d5e8f5

12 files changed

+94
-38
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Depends:
2929
paradox (>= 1.0.1),
3030
R (>= 3.1.0)
3131
Imports:
32-
bbotk (>= 1.1.1),
32+
bbotk (>= 1.2.0),
3333
checkmate (>= 2.0.0),
3434
data.table,
3535
lgr,

NEWS.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# mlr3tuning (development version)
22

33
* fix: The `as_data_table()` functions do not unnest the `x_domain` colum anymore by default.
4-
* fix: `to_tune(internal = TRUE)` now also works if non-internal tuning parameters require have
5-
an `.extra_trafo`
4+
* fix: `to_tune(internal = TRUE)` now also works if non-internal tuning parameters require have an `.extra_trafo`.
65
* feat: It is now possible to pass an `internal_search_space` manually.
7-
This allows to use parameter transformations on the primary search space in combination with
8-
internal hyperparameter tuning.
6+
This allows to use parameter transformations on the primary search space in combination with internal hyperparameter tuning.
7+
* refactor: The `Tuner` pass extra information of the result in the `extra` parameter now.
98

109
# mlr3tuning 1.0.2
1110

R/TuningInstanceAsyncMulticrit.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#' @template param_xdt
2727
#' @template param_learner_param_vals
2828
#' @template param_internal_tuned_values
29+
#' @template param_extra
2930
#'
3031
#' @template field_internal_search_space
3132
#'
@@ -147,13 +148,18 @@ TuningInstanceAsyncMultiCrit = R6Class("TuningInstanceAsyncMultiCrit",
147148
#' For internal use.
148149
#'
149150
#' @param ydt (`numeric(1)`)\cr
150-
#' Optimal outcomes, e.g. the Pareto front.
151+
#' Optimal outcomes, e.g. the Pareto front.
151152
#' @param xydt (`data.table::data.table()`)\cr
152-
#' Point, outcome, and additional information.
153-
assign_result = function(xdt, ydt, learner_param_vals = NULL, xydt = NULL) {
153+
#' Point, outcome, and additional information.
154+
#' @param ... (`any`)\cr
155+
#' ignored.
156+
assign_result = function(xdt, ydt, learner_param_vals = NULL, extra = NULL, xydt = NULL, ...) {
157+
# workaround
158+
extra = extra %??% xydt
159+
154160
# extract internal tuned values
155-
if ("internal_tuned_values" %in% names(xydt)) {
156-
set(xdt, j = "internal_tuned_values", value = list(xydt[["internal_tuned_values"]]))
161+
if ("internal_tuned_values" %in% names(extra)) {
162+
set(xdt, j = "internal_tuned_values", value = list(extra[["internal_tuned_values"]]))
157163
}
158164

159165
# set the column with the learner param_vals that were not optimized over but set implicitly

R/TuningInstanceAsyncSingleCrit.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#' @template param_xdt
3737
#' @template param_learner_param_vals
3838
#' @template param_internal_tuned_values
39+
#' @template param_extra
3940
#'
4041
#' @template field_internal_search_space
4142
#'
@@ -159,14 +160,19 @@ TuningInstanceAsyncSingleCrit = R6Class("TuningInstanceAsyncSingleCrit",
159160
#' @param y (`numeric(1)`)\cr
160161
#' Optimal outcome.
161162
#' @param xydt (`data.table::data.table()`)\cr
162-
#' Point, outcome, and additional information.
163-
assign_result = function(xdt, y, learner_param_vals = NULL, xydt = NULL) {
163+
#' Point, outcome, and additional information (Deprecated).
164+
#' @param ... (`any`)\cr
165+
#' ignored.
166+
assign_result = function(xdt, y, learner_param_vals = NULL, extra = NULL, xydt = NULL, ...) {
167+
# workaround
168+
extra = extra %??% xydt
169+
164170
# set the column with the learner param_vals that were not optimized over but set implicitly
165171
assert_list(learner_param_vals, null.ok = TRUE, names = "named")
166172

167173
# extract internal tuned values
168-
if ("internal_tuned_values" %in% names(xydt)) {
169-
set(xdt, j = "internal_tuned_values", value = list(xydt[["internal_tuned_values"]]))
174+
if ("internal_tuned_values" %in% names(extra)) {
175+
set(xdt, j = "internal_tuned_values", value = list(extra[["internal_tuned_values"]]))
170176
}
171177

172178
if (is.null(learner_param_vals)) {

R/TuningInstanceBatchMulticrit.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#' @template param_xdt
3434
#' @template param_learner_param_vals
3535
#' @template param_internal_tuned_values
36+
#' @template param_extra
3637
#'
3738
#' @template field_internal_search_space
3839
#'
@@ -181,13 +182,18 @@ TuningInstanceBatchMultiCrit = R6Class("TuningInstanceBatchMultiCrit",
181182
#' For internal use.
182183
#'
183184
#' @param ydt (`data.table::data.table()`)\cr
184-
#' Optimal outcomes, e.g. the Pareto front.
185+
#' Optimal outcomes, e.g. the Pareto front.
185186
#' @param xydt (`data.table::data.table()`)\cr
186-
#' Point, outcome, and additional information.
187-
assign_result = function(xdt, ydt, learner_param_vals = NULL, xydt = NULL) {
187+
#' Point, outcome, and additional information (Deprecated).
188+
#' @param ... (`any`)\cr
189+
#' ignored.
190+
assign_result = function(xdt, ydt, learner_param_vals = NULL, extra = NULL, xydt = NULL, ...) {
191+
# workaround
192+
extra = extra %??% xydt
193+
188194
# extract internal tuned values
189-
if ("internal_tuned_values" %in% names(xydt)) {
190-
set(xdt, j = "internal_tuned_values", value = list(xydt[["internal_tuned_values"]]))
195+
if ("internal_tuned_values" %in% names(extra)) {
196+
set(xdt, j = "internal_tuned_values", value = list(extra[["internal_tuned_values"]]))
191197
}
192198

193199
# set the column with the learner param_vals that were not optimized over but set implicitly

R/TuningInstanceBatchSingleCrit.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#' @template param_xdt
6969
#' @template param_learner_param_vals
7070
#' @template param_internal_tuned_values
71+
#' @template param_extra
7172
#'
7273
#' @template field_internal_search_space
7374
#'
@@ -219,17 +220,21 @@ TuningInstanceBatchSingleCrit = R6Class("TuningInstanceBatchSingleCrit",
219220
#' For internal use.
220221
#'
221222
#' @param y (`numeric(1)`)\cr
222-
#' Optimal outcome.
223+
#' Optimal outcome.
223224
#' @param xydt (`data.table::data.table()`)\cr
224-
#' Point, outcome, and additional information.
225-
assign_result = function(xdt, y, learner_param_vals = NULL, xydt = NULL) {
225+
#' Point, outcome, and additional information (Deprecated).
226+
#' @param ... (`any`)\cr
227+
#' ignored.
228+
assign_result = function(xdt, y, learner_param_vals = NULL, extra = NULL, xydt = NULL, ...) {
229+
# workaround
230+
extra = extra %??% xydt
226231

227232
# set the column with the learner param_vals that were not optimized over but set implicitly
228233
assert_list(learner_param_vals, null.ok = TRUE, names = "named")
229234

230235
# extract internal tuned values
231-
if ("internal_tuned_values" %in% names(xydt)) {
232-
set(xdt, j = "internal_tuned_values", value = list(xydt[["internal_tuned_values"]]))
236+
if ("internal_tuned_values" %in% names(extra)) {
237+
set(xdt, j = "internal_tuned_values", value = list(extra[["internal_tuned_values"]]))
233238
}
234239

235240
# learner param values

man-roxygen/param_extra.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#' @param extra (`data.table::data.table()`)\cr
2+
#' Additional information.

man/TuningInstanceAsyncMultiCrit.Rd

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/TuningInstanceAsyncSingleCrit.Rd

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/TuningInstanceBatchMultiCrit.Rd

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)