Skip to content

Commit 9f63efc

Browse files
committed
use new trafo interface
1 parent 070d9c8 commit 9f63efc

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

tests/testthat/test_trafos.R

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
test_that("simple exp trafo works", {
22
ll = lrn("classif.rpart")
33
ps = ps(
4-
cp = p_dbl(lower = -8, upper = -2)
4+
cp = p_dbl(lower = -8, upper = -2, trafo = function(x) 2^x)
55
)
6-
ps$trafo = function(x, param_set) {
7-
x$cp = 2^x$cp
8-
return(x)
9-
}
106
te = trm("evals", n_evals = 3)
117
d = data.table(cp = c(-7, -3))
128
tuner = tnr("design_points", design = d)
@@ -22,16 +18,16 @@ test_that("simple exp trafo works", {
2218
test_that("trafo where param names change", {
2319
ll = lrn("classif.rpart")
2420
ps = ps(
25-
foo = p_fct(levels = c("a", "b"))
21+
foo = p_fct(levels = c("a", "b")),
22+
.extra_trafo = function(x, param_set) {
23+
if (x$foo == "a")
24+
x$cp = 0.11
25+
else
26+
x$cp = 0.22
27+
x$foo = NULL
28+
return(x)
29+
}
2630
)
27-
ps$trafo = function(x, param_set) {
28-
if (x$foo == "a")
29-
x$cp = 0.11
30-
else
31-
x$cp = 0.22
32-
x$foo = NULL
33-
return(x)
34-
}
3531
te = trm("evals", n_evals = 3)
3632
tuner = tnr("grid_search", resolution = 2)
3733
inst = TuningInstanceSingleCrit$new(tsk("iris"), ll, rsmp("holdout"), msr("dummy.cp.classif", fun = function(pv) pv$cp), te, ps)

0 commit comments

Comments
 (0)