I am assuming you want to do this for tuning purposes. If you don't, you have to use a p_dbl()
and set the levels as characters ("0.99"
, ...).
Note that the second solution that I am giving here is simply a shortcut for the first approach, where the transformation is explicitly defined. This means that the paradox
package will create the transformation for you, similarly to how it is done in the first of the two solutions.
library(paradox)
library(data.table)
search_space = ps(
a = p_fct(levels = c("0.99", "0.98", "0.97"), trafo = function(x, param_set) {
switch(x,
"0.99" = 0.99,
"0.98" = 0.98,
"0.97" = 0.97
)
})
)
design = rbindlist(generate_design_grid(search_space, 3)$transpose(), fill = TRUE)
design
#> a
#> 1: 0.99
#> 2: 0.98
#> 3: 0.97
class(design[[1]])
#> [1] "numeric"
# the same can be achieves as follows:
search_space = ps(
a = p_fct(levels = c(0.99, 0.98, 0.97))
)
design = rbindlist(generate_design_grid(search_space, 3)$transpose(), fill = TRUE)
design
#> a
#> 1: 0.99
#> 2: 0.98
#> 3: 0.97
class(design[[1]])
#> [1] "numeric"
Created on 2023-02-15 with reprex v2.0.2