Skip to content

Commit 917ff4e

Browse files
committed
Merge branch 'main' of github.com:mlr-org/mlr3mbo
2 parents 4355e74 + b8253c2 commit 917ff4e

File tree

9 files changed

+34
-18
lines changed

9 files changed

+34
-18
lines changed

R/ResultAssignerSurrogate.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ ResultAssignerSurrogate = R6Class("ResultAssignerSurrogate",
6666
extra = xydt[, !c(cols_x, cols_y), with = FALSE]
6767

6868
# ys are still the ones originally evaluated
69-
best_y = if (inherits(instance, c("OptimInstanceBatchSingleCrit", "OptimInstanceAsyncSingleCrit"))) {
70-
unlist(archive$data[best, on = cols_x][, cols_y, with = FALSE])
69+
if (inherits(instance, c("OptimInstanceBatchSingleCrit", "OptimInstanceAsyncSingleCrit"))) {
70+
best_y = unlist(archive$data[best, on = cols_x][, cols_y, with = FALSE])
71+
instance$assign_result(xdt = best, y = best_y, extra = extra)
7172
} else if (inherits(instance, c("OptimInstanceBatchMultiCrit", "OptimInstanceAsyncMultiCrit"))) {
72-
archive$data[best, on = cols_x][, cols_y, with = FALSE]
73+
best_y = archive$data[best, on = cols_x][, cols_y, with = FALSE]
74+
instance$assign_result(xdt = best, ydt = best_y, extra = extra)
7375
}
74-
instance$assign_result(xdt = best, y = best_y, extra = extra)
76+
7577
}
7678
),
7779

tests/testthat/setup.R

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
old_threshold_bbotk = lg$threshold
2-
lg$set_threshold("warn")
1+
old_opts = options(
2+
warnPartialMatchArgs = TRUE,
3+
warnPartialMatchAttr = TRUE,
4+
warnPartialMatchDollar = TRUE
5+
)
6+
7+
# https://github.com/HenrikBengtsson/Wishlist-for-R/issues/88
8+
old_opts = lapply(old_opts, function(x) if (is.null(x)) FALSE else x)
39

410
lg_mlr3 = lgr::get_logger("mlr3")
11+
lg_bbotk = lgr::get_logger("bbotk")
12+
lg_rush = lgr::get_logger("rush")
13+
514
old_threshold_mlr3 = lg_mlr3$threshold
6-
lg_mlr3$set_threshold("warn")
15+
old_threshold_bbotk = lg_bbotk$threshold
16+
old_threshold_rush = lg_rush$threshold
717

18+
lg_mlr3$set_threshold(0)
19+
lg_bbotk$set_threshold(0)
20+
lg_rush$set_threshold(0)

tests/testthat/teardown.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
lg$set_threshold(old_threshold_bbotk)
1+
options(old_opts)
22
lg_mlr3$set_threshold(old_threshold_mlr3)
3-
3+
lg_bbotk$set_threshold(old_threshold_bbotk)
4+
lg_rush$set_threshold(old_threshold_rush)

tests/testthat/test_ResultAssignerArchive.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test_that("ResultAssignerArchive works with OptimizerMbo and bayesopt_ego", {
2323
optimizer = opt("mbo", loop_function = bayesopt_ego, surrogate = surrogate, acq_function = acq_function, acq_optimizer = acq_optimizer, result_assigner = result_assigner)
2424
optimizer$optimize(instance)
2525
expect_true(nrow(instance$archive$data) == 5L)
26-
expect_data_table(instance$result, nrow = 1L)
26+
expect_data_table(instance$result, nrows = 1L)
2727
})
2828

2929
test_that("ResultAssignerArchive works with OptimizerMbo and bayesopt_parego", {

tests/testthat/test_ResultAssignerSurrogate.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test_that("ResultAssignerSurrogate works with OptimizerMbo and bayesopt_ego", {
4646

4747
expect_r6(result_assigner$surrogate, classes = "SurrogateLearner")
4848
expect_r6(result_assigner$surrogate$learner, classes = "Learner")
49-
expect_data_table(instance$result, nrow = 1L)
49+
expect_data_table(instance$result, nrows = 1L)
5050
})
5151

5252
test_that("ResultAssignerSurrogate works with OptimizerMbo and bayesopt_parego", {

tests/testthat/test_SurrogateLearnerCollection.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ test_that("predict_types are recognized", {
4747
learner1$predict_type = "se"
4848
learner2 = lrn("regr.rpart")
4949
learner2$predict_type = "response"
50-
surrogate = SurrogateLearnerCollection$new(learner = list(learner1, learner2), archive = inst$archive)
50+
surrogate = SurrogateLearnerCollection$new(learners = list(learner1, learner2), archive = inst$archive)
5151
surrogate$update()
5252

5353
xdt = data.table(x = seq(-1, 1, length.out = 5L))
@@ -58,7 +58,7 @@ test_that("predict_types are recognized", {
5858

5959
test_that("param_set", {
6060
inst = MAKE_INST(OBJ_1D_2, PS_1D, trm("evals", n_evals = 5L))
61-
surrogate = SurrogateLearnerCollection$new(learner = list(REGR_FEATURELESS, REGR_FEATURELESS$clone(deep = TRUE)), archive = inst$archive)
61+
surrogate = SurrogateLearnerCollection$new(learners = list(REGR_FEATURELESS, REGR_FEATURELESS$clone(deep = TRUE)), archive = inst$archive)
6262
expect_r6(surrogate$param_set, "ParamSet")
6363
expect_setequal(surrogate$param_set$ids(), c("assert_insample_perf", "perf_measures", "perf_thresholds", "catch_errors", "impute_method"))
6464
expect_equal(surrogate$param_set$class[["assert_insample_perf"]], "ParamLgl")
@@ -77,7 +77,7 @@ test_that("insample_perf", {
7777
design = MAKE_DESIGN(inst)
7878
inst$eval_batch(design)
7979

80-
surrogate = SurrogateLearnerCollection$new(learner = list(REGR_KM_DETERM, REGR_KM_DETERM$clone(deep = TRUE)), archive = inst$archive)
80+
surrogate = SurrogateLearnerCollection$new(learners = list(REGR_KM_DETERM, REGR_KM_DETERM$clone(deep = TRUE)), archive = inst$archive)
8181
expect_error({surrogate$insample_perf = c(0, 0)}, regexp = "insample_perf is read-only.")
8282
expect_error({surrogate$assert_insample_perf = 0}, regexp = "assert_insample_perf is read-only.")
8383

@@ -91,7 +91,7 @@ test_that("insample_perf", {
9191
expect_double(surrogate$insample_perf, lower = -Inf, upper = 1, any.missing = FALSE, len = 2L)
9292
expect_equal(names(surrogate$insample_perf), map_chr(surrogate$param_set$values$perf_measures, "id"))
9393

94-
surrogate_constant = SurrogateLearnerCollection$new(learner = list(REGR_FEATURELESS, REGR_FEATURELESS$clone(deep = TRUE)), archive = inst$archive)
94+
surrogate_constant = SurrogateLearnerCollection$new(learners = list(REGR_FEATURELESS, REGR_FEATURELESS$clone(deep = TRUE)), archive = inst$archive)
9595
surrogate_constant$param_set$values$assert_insample_perf = TRUE
9696
surrogate_constant$param_set$values$perf_thresholds = c(0.5, 0.5)
9797
surrogate_constant$param_set$values$perf_measures = list(mlr_measures$get("regr.rsq"), mlr_measures$get("regr.rsq"))

tests/testthat/test_TunerADBO.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test_that("TunerADBO works", {
1313
task = tsk("pima"),
1414
learner = learner,
1515
resampling = rsmp("cv", folds = 3L),
16-
measure = msr("classif.ce"),
16+
measures = msr("classif.ce"),
1717
terminator = trm("evals", n_evals = 20L),
1818
store_benchmark_result = FALSE
1919
)

tests/testthat/test_TunerAsyncMbo.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test_that("TunerAsyncMbo works", {
1313
task = tsk("pima"),
1414
learner = learner,
1515
resampling = rsmp("cv", folds = 3L),
16-
measure = msr("classif.ce"),
16+
measures = msr("classif.ce"),
1717
terminator = trm("evals", n_evals = 20L),
1818
store_benchmark_result = FALSE
1919
)

tests/testthat/test_TunerMbo.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ test_that("TunerMbo reset", {
157157
instance = TuningInstanceBatchSingleCrit$new(tsk("iris"), learner = learner, resampling = rsmp("holdout"), measure = msr("classif.ce"), terminator = trm("evals", n_evals = 5L))
158158
tuner$optimize(instance)
159159

160-
instance_mult = TuningInstanceBatchMultiCrit$new(tsk("iris"), learner = learner, resampling = rsmp("holdout"), measure = msrs(c("classif.ce", "classif.logloss")), terminator = trm("evals", n_evals = 5L))
160+
instance_mult = TuningInstanceBatchMultiCrit$new(tsk("iris"), learner = learner, resampling = rsmp("holdout"), measures = msrs(c("classif.ce", "classif.logloss")), terminator = trm("evals", n_evals = 5L))
161161

162162
expect_error(tuner$optimize(instance_mult), "does not support multi-crit objectives")
163163
expect_loop_function(tuner$loop_function)

0 commit comments

Comments
 (0)