Skip to contents

Shrinks a paradox::ParamSet towards a point. Boundaries of numeric values are shrinked to an interval around the point of half of the previous length, while for discrete variables, a random (currently not chosen) level is dropped.

Note that for paradox::p_lgl()s the value to be shrinked around is set as the default value instead of dropping a level. Also, a tag shrinked is added.

Note that the returned paradox::ParamSet has lost all its original defaults, as they may have become infeasible.

If the paradox::ParamSet has a trafo, x is expected to contain the transformed values.

Usage

shrink_ps(param_set, x, check.feasible = FALSE)

Arguments

param_set

(paradox::ParamSet)
The paradox::ParamSet to be shrinked.

x

(data.table::data.table)
data.table::data.table with one row containing the point to shrink around.

check.feasible

(logical(1))
Should feasibility of the parameters be checked? If feasibility is not checked, and invalid values are present, no shrinking will be done. Must be turned off in the case of the paradox::ParamSet having a trafo. Default is FALSE.

Examples

library(paradox)
library(data.table)
param_set = ps(
  x = p_dbl(lower = 0, upper = 10),
  x2 = p_int(lower = -10, upper = 10),
  x3 = p_fct(levels = c("a", "b", "c")),
  x4 = p_lgl()
)
x = data.table(x1 = 5, x2 = 0, x3 = "b", x4 = FALSE)
shrink_ps(param_set, x = x)
#> <ParamSet>
#>        id    class lower upper nlevels
#>    <char>   <char> <num> <num>   <num>
#> 1:      x ParamDbl     0    10     Inf
#> 2:     x2 ParamInt    -5     5      11
#> 3:     x3 ParamFct    NA    NA       2
#> 4:     x4 ParamLgl    NA    NA       2
#>                                                                                      default
#>                                                                                       <list>
#> 1: <NoDefault>\n  Public:\n    clone: function (deep = FALSE) \n    initialize: function () 
#> 2: <NoDefault>\n  Public:\n    clone: function (deep = FALSE) \n    initialize: function () 
#> 3: <NoDefault>\n  Public:\n    clone: function (deep = FALSE) \n    initialize: function () 
#> 4:                                                                                     FALSE
#>     value
#>    <list>
#> 1:       
#> 2:       
#> 3:       
#> 4: