# NOT RUN {
params = ParamSet$new(list(
ParamInt$new("int", 0, 10),
ParamInt$new("int_unbounded"),
ParamDbl$new("dbl", 0, 10),
ParamDbl$new("dbl_unbounded"),
ParamFct$new("fct", c("a", "b", "c")),
ParamUty$new("uty1"),
ParamUty$new("uty2"),
ParamUty$new("uty3"),
ParamUty$new("uty4"),
ParamUty$new("uty5")
))
params$values = list(
# tune over entire range of `int`, 0..10:
int = to_tune(),
# tune over 2..7:
int_unbounded = to_tune(2, 7),
# tune on a log scale in range 1..10:
# (you have to make sure exp(log(x)) does not overstep boundaries because
# of rounding errors; unfortunately paradox is your enemy here.)
dbl = to_tune(p_dbl(log(1 + 1e-10), log(10 - 1e-10), trafo = exp)),
# nothing keeps us from tuning a dbl over integer values
dbl_unbounded = to_tune(p_int(1, 10)),
# tune over values "a" and "b" only
fct = to_tune(c("a", "b")),
# tune over integers 2..8.
# ParamUty needs type information in form of p_xxx() in to_tune.
uty1 = to_tune(p_int(2, 8)),
# tune uty2 like a factor, trying 1, 10, and 100:
uty2 = to_tune(c(1, 10, 100)),
# tune uty3 like a factor. The factor levels are the names of the list
# ("exp", "square"), but the trafo will generate the values from the list.
# This way you can tune an objective that has function-valued inputs.
uty3 = to_tune(list(exp = exp, square = function(x) x^2)),
# tune through multiple parameters. When doing this, the ParamSet in tune()
# must have the trafo that generates a list with one element and the right
# name:
uty4 = to_tune(ps(
base = p_dbl(0, 1),
exp = p_int(0, 3),
.extra_trafo = function(x, param_set) {
list(uty4 = x$base ^ x$exp)
}
)),
# not all values need to be tuned!
uty5 = 100
)
print(params$values)
print(params$search_space())
# Change `$values` directly and generate new `$search_space()` to play around
params$values$uty3 = 8
params$values$uty2 = to_tune(c(2, 4, 8))
print(params$search_space())
# }
Run the code above in your browser using DataLab