mlr-org / paradox

ParamHelpers Next Generation
https://paradox.mlr-org.com
GNU Lesser General Public License v3.0
28 stars 7 forks source link

Other parameters besides Uty should have repr #366

Open sebffischer opened 2 years ago

sebffischer commented 2 years ago

In the cubist regr learner, there is a parameter whose default is sample.int(4096, size = 1) which should be displayed in the help page of the learner constructed by rd_info.

When doing the usual ps(a = p_int(default = sample.int(4096))) the default is set to the evaluation of sample.int(4096) which is undesireable:

library(paradox)
p = ps(a  = p_int(default = sample.int(4096, 1)))
mlr3misc::rd_info(p)
#> [1] "\n|Id |Type    |Default |Range                                |\n|:--|:-------|:-------|:------------------------------------|\n|a  |integer |551     |\\eqn{(-\\infty, \\infty)}{(-Inf, Inf)} |"

The only solution I found is also a little hacky because it sets the default to a random value and sets the repr to something else

p = ParamSet$new(list(ParamUty$new("a", default = 0, repr = "sample.int(4096, 1)")))
mlr3misc::rd_info(p)
#> [1] "\n|Id |Type    |Default             |\n|:--|:-------|:-------------------|\n|a  |untyped |sample.int(4096, 1) |"

This does currently not work with p_uty().