rmlr3

Define parameter1 as 1 - parameter2 using R paradox package


I want to define parameter1 as 1 - parameter2 using paradox package. That is parameter 1 depends on parameter 2 (depends argument doesn't help here I suppose).

Here is my reserach space:

search_space = ps(
  # preprocessing
  interaction_branch.selection = p_fct(levels = c("nop_filter", "modelmatrix")),
  winsorizesimple.probs_high = p_fct(levels = c("0.99", "0.98", "0.97")),
  winsorizesimple.probs_low = p_dbl(lower = 0, upper = 1),
  # ranger
  ranger.ranger.max.depth = p_fct(levels = c(2L, 10L)),
  ranger.ranger.splitrule = p_fct(levels = c("gini", "extratrees")),
  ranger.ranger.mtry.ratio = p_dbl(0.5, 1),
  # kknn
  kknn.kknn.k = p_int(1, 10),
  # extra transformations
  .extra_trafo = function(x, param_set) {
    winsorizesimple.probs_high = switch(
      x$winsorizesimple.probs_high,
      "0.99" = 0.99,
      "0.98" = 0.98,
      "0.97" = 0.97
    )
    x$winsorizesimple.probs_low = 1 - winsorizesimple.probs_high
    x
  }
)

The ooutput is:

      interaction_branch.selection winsorizesimple.probs_high winsorizesimple.probs_low ranger.ranger.max.depth ranger.ranger.splitrule ranger.ranger.mtry.ratio
   1:                   nop_filter                       0.99                        -1                       2                    gini                0.5000000
   2:                   nop_filter                       0.99                        -1                       2                    gini                0.5000000
   3:                   nop_filter                       0.99                        -1                       2                    gini                0.5000000
   4:                   nop_filter                       0.99                        -1                       2                    gini                0.5000000
   5:                   nop_filter                       0.99                        -1                       2                    gini                0.6666667
  ---                                                                                                                                                           
1532:                  modelmatrix                       0.97                         2                      10              extratrees                0.8333333
1533:                  modelmatrix                       0.97                         2                      10              extratrees                1.0000000
1534:                  modelmatrix                       0.97                         2                      10              extratrees                1.0000000
1535:                  modelmatrix                       0.97                         2                      10              extratrees                1.0000000
1536:                  modelmatrix                       0.97                         2                      10              extratrees                1.0000000
      kknn.kknn.k
   1:           1
   2:           4
   3:           7
   4:          10
   5:           1
  ---            
1532:          10
1533:           1
1534:           4
1535:           7
1536:          10

I winsorizesimple.probs_high1 is 0.97, winsorizesimple.probs_low should be 0.03. Hope you can help without reprex.


Solution

  • Something went wrong when generating the design, because for me your code works.

    library(paradox)
    library(data.table)
    
    search_space = ps(
      # preprocessing
      interaction_branch.selection = p_fct(levels = c("nop_filter", "modelmatrix")),
      winsorizesimple.probs_high = p_fct(levels = c("0.99", "0.98", "0.97")),
      winsorizesimple.probs_low = p_dbl(lower = 0, upper = 1),
      # ranger
      ranger.ranger.max.depth = p_fct(levels = c(2L, 10L)),
      ranger.ranger.splitrule = p_fct(levels = c("gini", "extratrees")),
      ranger.ranger.mtry.ratio = p_dbl(0.5, 1),
      # kknn
      kknn.kknn.k = p_int(1, 10),
      # extra transformations
      .extra_trafo = function(x, param_set) {
        winsorizesimple.probs_high = switch(
          x$winsorizesimple.probs_high,
          "0.99" = 0.99,
          "0.98" = 0.98,
          "0.97" = 0.97
        )
        x$winsorizesimple.probs_low = 1 - winsorizesimple.probs_high
        x
      }
    )
    
    design = rbindlist(generate_design_grid(search_space, 3)$transpose(), fill = TRUE)
    design
    #>      interaction_branch.selection winsorizesimple.probs_high
    #>   1:                   nop_filter                       0.99
    #>   2:                   nop_filter                       0.99
    #>   3:                   nop_filter                       0.99
    #>   4:                   nop_filter                       0.99
    #>   5:                   nop_filter                       0.99
    #>  ---                                                        
    #> 644:                  modelmatrix                       0.97
    #> 645:                  modelmatrix                       0.97
    #> 646:                  modelmatrix                       0.97
    #> 647:                  modelmatrix                       0.97
    #> 648:                  modelmatrix                       0.97
    #>      winsorizesimple.probs_low ranger.ranger.max.depth ranger.ranger.splitrule
    #>   1:                      0.01                       2                    gini
    #>   2:                      0.01                       2                    gini
    #>   3:                      0.01                       2                    gini
    #>   4:                      0.01                       2                    gini
    #>   5:                      0.01                       2                    gini
    #>  ---                                                                          
    #> 644:                      0.03                      10              extratrees
    #> 645:                      0.03                      10              extratrees
    #> 646:                      0.03                      10              extratrees
    #> 647:                      0.03                      10              extratrees
    #> 648:                      0.03                      10              extratrees
    #>      ranger.ranger.mtry.ratio kknn.kknn.k
    #>   1:                     0.50           1
    #>   2:                     0.50           5
    #>   3:                     0.50          10
    #>   4:                     0.75           1
    #>   5:                     0.75           5
    #>  ---                                     
    #> 644:                     0.75           5
    #> 645:                     0.75          10
    #> 646:                     1.00           1
    #> 647:                     1.00           5
    #> 648:                     1.00          10
    

    Created on 2023-02-23 with reprex v2.0.2