1

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):

p_dbl(c(0.99, 0.98, 0.97))
zephryl
  • 14,633
  • 3
  • 11
  • 30
Mislav Sagovac
  • 185
  • 1
  • 8

1 Answers1

2

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

Sebastian
  • 865
  • 5
  • 13
  • Is there a problem if my parameter needs double and I define paramtere with `p_fct`? – Mislav Sagovac Feb 15 '23 at 14:55
  • 1
    You are referring to the second solution? There is some magic behind the scenes, you can think of the second solution as a user-friendly way to do the same thing as in the first solution (the paradox package is smart enough to create the transformation from character to double for you) – Sebastian Feb 15 '23 at 14:57
  • 1
    You might be interested in this chapter here: https://mlr3book.mlr-org.com/technical.html#sec-paradox (this will soon be moved to other chapters) – Sebastian Feb 15 '23 at 14:57
  • Btw, I have seen you are very active in mlr3 recently, may I ask where your interest is coming from? :) – Sebastian Feb 16 '23 at 07:48
  • I have tried mlr3 before, while I was doing ML. I find your package better than tidy models and maybe even better than sklearn (even I haven't used it for 2 years now). It is modular and flexible. I haven't some problems but I hope I will solve it eventually. For now, I haven't figure out how to do nested rolling window cross validation (say train on 1, 2, 3 group, validate on 4 group and test on 5 group, where group can be month, quarter etc; second fold would be 2-4 train, 5 validate (tune), 6 test). Second is preprocessing by grouping. Too much text for stack comment :) – Mislav Sagovac Feb 16 '23 at 10:47
  • That is great to hear. Yes, the whole time series situation is suboptimal, maybe we can find someone who wants to work on that in the future... If you want to discuss these things / give feedback you can also join the mattermost channel and continue discussion there! – Sebastian Feb 16 '23 at 12:35
  • I have joined the mattermost channel, so I will describe my use case there. – Mislav Sagovac Feb 16 '23 at 14:21