Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Set 3 double parameters in p_db using paradox package

How can I set parameter with say 3 float values.
For example I want to search parameter X for 0.99, 0.98 and 0.97.

For p_dbl there are lower and upper parameters but not values I can use.

For example something like (this doesn’t work ofc):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

p_dbl(c(0.99, 0.98, 0.97))

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading