将参数1定义为1减去参数2,使用R的paradox包。

huangapple go评论68阅读模式
英文:

Define parameter1 as 1 - parameter2 using R paradox package

问题

我想要使用paradox包将parameter1定义为1 - parameter2。这意味着parameter1依赖于parameter2(我认为depends参数在这里不起作用)。

这是我的研究空间:

search_space = ps(
  # 数据预处理
  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_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
  }
)

输出如下:

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

我理解你的需求是将winsorizesimple.probs_low从-1更改为0.01,因此这是更正后的输出。希望这对你有帮助,不需要重新生成示例。

英文:

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.

答案1

得分: 3

生成设计时出现了问题,因为对我来说,您的代码可以正常工作。

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

2023年2月23日创建,使用reprex v2.0.2

英文:

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

<sup>Created on 2023-02-23 with reprex v2.0.2</sup>

huangapple
  • 本文由 发表于 2023年2月23日 21:16:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75545365.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定