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

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

Define parameter1 as 1 - parameter2 using R paradox package

问题

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

这是我的研究空间:

  1. search_space = ps(
  2. # 数据预处理
  3. interaction_branch.selection = p_fct(levels = c("nop_filter", "modelmatrix")),
  4. winsorizesimple.probs_high = p_fct(levels = c("0.99", "0.98", "0.97")),
  5. winsorizesimple.probs_low = p_dbl(lower = 0, upper = 1),
  6. # ranger
  7. ranger.ranger.max.depth = p_fct(levels = c(2L, 10L)),
  8. ranger.ranger.splitrule = p_fct(levels = c("gini", "extratrees")),
  9. ranger.ranger.mtry.ratio = p_dbl(0.5, 1),
  10. # kknn
  11. kknn.kknn.k = p_int(1, 10),
  12. # 额外的转换
  13. .extra_trafo = function(x, param_set) {
  14. winsorizesimple.probs_high = switch(
  15. x$winsorizesimple.probs_high,
  16. "0.99" = 0.99,
  17. "0.98" = 0.98,
  18. "0.97" = 0.97
  19. )
  20. x$winsorizesimple.probs_low = 1 - winsorizesimple.probs_high
  21. x
  22. }
  23. )

输出如下:

  1. interaction_branch.selection winsorizesimple.probs_high winsorizesimple.probs_low ranger.ranger.max.depth ranger.ranger.splitrule ranger.ranger.mtry.ratio kknn.kknn.k
  2. 1: nop_filter 0.99 0.01 2 gini 0.5000000 1
  3. 2: nop_filter 0.99 0.01 2 gini 0.5000000 4
  4. 3: nop_filter 0.99 0.01 2 gini 0.5000000 7
  5. 4: nop_filter 0.99 0.01 2 gini 0.5000000 10
  6. 5: nop_filter 0.99 0.01 2 gini 0.6666667 1
  7. ---
  8. 1532: modelmatrix 0.97 0.03 10 extratrees 0.8333333 10
  9. 1533: modelmatrix 0.97 0.03 10 extratrees 1.0000000 1
  10. 1534: modelmatrix 0.97 0.03 10 extratrees 1.0000000 4
  11. 1535: modelmatrix 0.97 0.03 10 extratrees 1.0000000 7
  12. 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:

  1. search_space = ps(
  2. # preprocessing
  3. interaction_branch.selection = p_fct(levels = c("nop_filter", "modelmatrix")),
  4. winsorizesimple.probs_high = p_fct(levels = c("0.99", "0.98", "0.97")),
  5. winsorizesimple.probs_low = p_dbl(lower = 0, upper = 1),
  6. # ranger
  7. ranger.ranger.max.depth = p_fct(levels = c(2L, 10L)),
  8. ranger.ranger.splitrule = p_fct(levels = c("gini", "extratrees")),
  9. ranger.ranger.mtry.ratio = p_dbl(0.5, 1),
  10. # kknn
  11. kknn.kknn.k = p_int(1, 10),
  12. # extra transformations
  13. .extra_trafo = function(x, param_set) {
  14. winsorizesimple.probs_high = switch(
  15. x$winsorizesimple.probs_high,
  16. "0.99" = 0.99,
  17. "0.98" = 0.98,
  18. "0.97" = 0.97
  19. )
  20. x$winsorizesimple.probs_low = 1 - winsorizesimple.probs_high
  21. x
  22. }
  23. )

The ooutput is:

  1. interaction_branch.selection winsorizesimple.probs_high winsorizesimple.probs_low ranger.ranger.max.depth ranger.ranger.splitrule ranger.ranger.mtry.ratio
  2. 1: nop_filter 0.99 -1 2 gini 0.5000000
  3. 2: nop_filter 0.99 -1 2 gini 0.5000000
  4. 3: nop_filter 0.99 -1 2 gini 0.5000000
  5. 4: nop_filter 0.99 -1 2 gini 0.5000000
  6. 5: nop_filter 0.99 -1 2 gini 0.6666667
  7. ---
  8. 1532: modelmatrix 0.97 2 10 extratrees 0.8333333
  9. 1533: modelmatrix 0.97 2 10 extratrees 1.0000000
  10. 1534: modelmatrix 0.97 2 10 extratrees 1.0000000
  11. 1535: modelmatrix 0.97 2 10 extratrees 1.0000000
  12. 1536: modelmatrix 0.97 2 10 extratrees 1.0000000
  13. kknn.kknn.k
  14. 1: 1
  15. 2: 4
  16. 3: 7
  17. 4: 10
  18. 5: 1
  19. ---
  20. 1532: 10
  21. 1533: 1
  22. 1534: 4
  23. 1535: 7
  24. 1536: 10

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

答案1

得分: 3

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

  1. library(paradox)
  2. library(data.table)
  3. search_space = ps(
  4. # preprocessing
  5. interaction_branch.selection = p_fct(levels = c("nop_filter", "modelmatrix")),
  6. winsorizesimple.probs_high = p_fct(levels = c("0.99", "0.98", "0.97")),
  7. winsorizesimple.probs_low = p_dbl(lower = 0, upper = 1),
  8. # ranger
  9. ranger.ranger.max.depth = p_fct(levels = c(2L, 10L)),
  10. ranger.ranger.splitrule = p_fct(levels = c("gini", "extratrees")),
  11. ranger.ranger.mtry.ratio = p_dbl(0.5, 1),
  12. # kknn
  13. kknn.kknn.k = p_int(1, 10),
  14. # extra transformations
  15. .extra_trafo = function(x, param_set) {
  16. winsorizesimple.probs_high = switch(
  17. x$winsorizesimple.probs_high,
  18. "0.99" = 0.99,
  19. "0.98" = 0.98,
  20. "0.97" = 0.97
  21. )
  22. x$winsorizesimple.probs_low = 1 - winsorizesimple.probs_high
  23. x
  24. }
  25. )
  26. design = rbindlist(generate_design_grid(search_space, 3)$transpose(), fill = TRUE)
  27. design
  28. #> interaction_branch.selection winsorizesimple.probs_high
  29. #> 1: nop_filter 0.99
  30. #> 2: nop_filter 0.99
  31. #> 3: nop_filter 0.99
  32. #> 4: nop_filter 0.99
  33. #> 5: nop_filter 0.99
  34. #> ---
  35. #> 644: modelmatrix 0.97
  36. #> 645: modelmatrix 0.97
  37. #> 646: modelmatrix 0.97
  38. #> 647: modelmatrix 0.97
  39. #> 648: modelmatrix 0.97
  40. #> winsorizesimple.probs_low ranger.ranger.max.depth ranger.ranger.splitrule
  41. #> 1: 0.01 2 gini
  42. #> 2: 0.01 2 gini
  43. #> 3: 0.01 2 gini
  44. #> 4: 0.01 2 gini
  45. #> 5: 0.01 2 gini
  46. #> ---
  47. #> 644: 0.03 10 extratrees
  48. #> 645: 0.03 10 extratrees
  49. #> 646: 0.03 10 extratrees
  50. #> 647: 0.03 10 extratrees
  51. #> 648: 0.03 10 extratrees
  52. #> ranger.ranger.mtry.ratio kknn.kknn.k
  53. #> 1: 0.50 1
  54. #> 2: 0.50 5
  55. #> 3: 0.50 10
  56. #> 4: 0.75 1
  57. #> 5: 0.75 5
  58. #> ---
  59. #> 644: 0.75 5
  60. #> 645: 0.75 10
  61. #> 646: 1.00 1
  62. #> 647: 1.00 5
  63. #> 648: 1.00 10

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

英文:

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

  1. library(paradox)
  2. library(data.table)
  3. search_space = ps(
  4. # preprocessing
  5. interaction_branch.selection = p_fct(levels = c("nop_filter", "modelmatrix")),
  6. winsorizesimple.probs_high = p_fct(levels = c("0.99", "0.98", "0.97")),
  7. winsorizesimple.probs_low = p_dbl(lower = 0, upper = 1),
  8. # ranger
  9. ranger.ranger.max.depth = p_fct(levels = c(2L, 10L)),
  10. ranger.ranger.splitrule = p_fct(levels = c("gini", "extratrees")),
  11. ranger.ranger.mtry.ratio = p_dbl(0.5, 1),
  12. # kknn
  13. kknn.kknn.k = p_int(1, 10),
  14. # extra transformations
  15. .extra_trafo = function(x, param_set) {
  16. winsorizesimple.probs_high = switch(
  17. x$winsorizesimple.probs_high,
  18. "0.99" = 0.99,
  19. "0.98" = 0.98,
  20. "0.97" = 0.97
  21. )
  22. x$winsorizesimple.probs_low = 1 - winsorizesimple.probs_high
  23. x
  24. }
  25. )
  26. design = rbindlist(generate_design_grid(search_space, 3)$transpose(), fill = TRUE)
  27. design
  28. #> interaction_branch.selection winsorizesimple.probs_high
  29. #> 1: nop_filter 0.99
  30. #> 2: nop_filter 0.99
  31. #> 3: nop_filter 0.99
  32. #> 4: nop_filter 0.99
  33. #> 5: nop_filter 0.99
  34. #> ---
  35. #> 644: modelmatrix 0.97
  36. #> 645: modelmatrix 0.97
  37. #> 646: modelmatrix 0.97
  38. #> 647: modelmatrix 0.97
  39. #> 648: modelmatrix 0.97
  40. #> winsorizesimple.probs_low ranger.ranger.max.depth ranger.ranger.splitrule
  41. #> 1: 0.01 2 gini
  42. #> 2: 0.01 2 gini
  43. #> 3: 0.01 2 gini
  44. #> 4: 0.01 2 gini
  45. #> 5: 0.01 2 gini
  46. #> ---
  47. #> 644: 0.03 10 extratrees
  48. #> 645: 0.03 10 extratrees
  49. #> 646: 0.03 10 extratrees
  50. #> 647: 0.03 10 extratrees
  51. #> 648: 0.03 10 extratrees
  52. #> ranger.ranger.mtry.ratio kknn.kknn.k
  53. #> 1: 0.50 1
  54. #> 2: 0.50 5
  55. #> 3: 0.50 10
  56. #> 4: 0.75 1
  57. #> 5: 0.75 5
  58. #> ---
  59. #> 644: 0.75 5
  60. #> 645: 0.75 10
  61. #> 646: 1.00 1
  62. #> 647: 1.00 5
  63. #> 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:

确定