The ps()
short form constructor uses Domain
objects (p_dbl
, p_fct
, ...) to construct ParamSet
s in a
succinct and readable way.
For more specifics also see the documentation of Domain
.
ps(..., .extra_trafo = NULL, .allow_dangling_dependencies = FALSE)
... | ( |
---|---|
.extra_trafo | ( |
.allow_dangling_dependencies | ( |
A ParamSet
object.
pars = ps( a = p_int(0, 10), b = p_int(upper = 20), c = p_dbl(), e = p_fct(letters[1:3]), f = p_uty(custom_check = checkmate::check_function) ) print(pars)#> <ParamSet> #> id class lower upper levels default value #> 1: a ParamInt 0 10 <NoDefault[3]> #> 2: b ParamInt -Inf 20 <NoDefault[3]> #> 3: c ParamDbl -Inf Inf <NoDefault[3]> #> 4: e ParamFct NA NA a,b,c <NoDefault[3]> #> 5: f ParamUty NA NA <NoDefault[3]>pars = ps( a = p_dbl(0, 1, trafo = exp), b = p_dbl(0, 1, trafo = exp), .extra_trafo = function(x, ps) { x$c <- x$a + x$b x } ) # See how the addition happens after exp()ing: pars$trafo(list(a = 0, b = 0))#> $a #> [1] 1 #> #> $b #> [1] 1 #> #> $c #> [1] 2 #>pars$values = list( a = to_tune(ps(x = p_int(0, 1), .extra_trafo = function(x, param_set) list(a = x$x) )), # make 'y' depend on 'x', but they are defined in different ParamSets # Therefore we need to allow dangling dependencies here. b = to_tune(ps(y = p_int(0, 1, requires = x == 1), .extra_trafo = function(x, param_set) list(b = x$y), .allow_dangling_dependencies = TRUE )) ) pars$search_space()#> <ParamSet> #> id class lower upper levels default parents value #> 1: x ParamInt 0 1 <NoDefault[3]> #> 2: y ParamInt 0 1 <NoDefault[3]> x #> Trafo is set.