paradox icon indicating copy to clipboard operation
paradox copied to clipboard

sugar for trafos and composition of trafos

Open berndbischl opened this issue 6 years ago • 6 comments

see this here, simply for rounding all doubles to ints (for tuners which need this) or doing 2^x, etc

ps = ParamSet$new(params = list(
   ParamDbl$new("cp", lower = 0.001, upper = 0.1),
   ParamInt$new("minsplit", lower = 1, upper = 10)
))
 ps$trafo = function(x, param_set) {
   cl = param_set$class
   for (n in names(x)) {
     if (cl[n] == "ParamInt")
       x[[n]] = round(x[[n]])
   }
   return(x)
 }

wouldnt it be nice to have some simple shorthand function which do common operations? and which are composable (which they are as they are functions)

so

ps$trafo = round_int("minsplit") %>% log_scale("cp") ? or similar?

@mllg @mb706 @jakob-r

berndbischl avatar Aug 15 '19 22:08 berndbischl

or don think this is very hard to do, each is a 2-5 liner

of course I always forget that base R doesnt have a "compose" function and i dont want to import the Funtional-package for this... :(

berndbischl avatar Aug 15 '19 22:08 berndbischl

For quick type conversion specifically you could vectorize the as function? I've included as.list to ensure each can take a different class. A similar argument could be used for other quick coercions

y = data.frame(c(1.1,2.2,3.3), c(“integer”,“logical”,“complex”), stringsAsFactors = FALSE)
z <- Vectorize(function(x, y) as.list(as(x,y)))
z(y[,1], y[,2])

RaphaelS1 avatar Aug 16 '19 18:08 RaphaelS1

ps %>%
  add_trafo(round, c("minsplit", "other_param")) %>%
  add_trafo(exp, c("cp", "yet_another_param"))

mb706 avatar Aug 16 '19 20:08 mb706

Do we still want that? Since we can now do this

search_space = ps(
  minsplit = p_dbl(lower = 1, upper = 10, , trafo = round)
)

generate_design_grid(search_space, 3)$transpose() 

be-marc avatar Jan 12 '21 16:01 be-marc

I think we can close @mb706 ?

jakob-r avatar Jan 14 '21 10:01 jakob-r

i would like to keep this open at least one engine call, so we can discuss it together

berndbischl avatar Jan 14 '21 11:01 berndbischl