1

The survival SVM model using hybrid approach requires gamma.mu to be a vector as below. How can we tune gamma.mu in this case?

lrn("surv.svm", type = "hybrid", diff.meth = "makediff3", gamma.mu=c(0.1, 0.1))
Ali Alhadab
  • 101
  • 5
  • Just like any other tuning in mlr3, see e.g. https://mlr3book.mlr-org.com/optimization.html#autotuner. Just specify the two values in the parameter space. – Lars Kotthoff Feb 19 '22 at 20:48

1 Answers1

4

You need to tune parts of the vector separately then combine in a transformation. You might find this tutorial helpful. Example below

library(mlr3)
library(mlr3proba)
library(mlr3tuning)
library(mlr3extralearners)

t = tgen("simsurv")$generate(5)

search_space = ps(
  gamma = p_dbl(1e-3, 1e3),
  mu = p_dbl(1e-3, 1e3)
)
search_space$trafo = function(x, param_set) {
  x$gamma.mu = c(x$gamma, x$mu)
  x$gamma = x$mu = NULL
  x
}

AutoTuner$new(
  lrn("surv.svm", type = "hybrid", diff.meth = "makediff3",
        gamma.mu = c(0.1, 0.1)),
  rsmp("holdout"),
  msr("surv.cindex"),
  trm("evals", n_evals = 3),
  tnr("grid_search", resolution = 2),
  search_space
)$train(t)$predict(t)
#> INFO  [21:40:21.261] [bbotk] Starting to optimize 2 parameter(s) with '<OptimizerGridSearch>' and '<TerminatorEvals> [n_evals=3]' 
#> INFO  [21:40:21.275] [bbotk] Evaluating 1 configuration(s) 
#> INFO  [21:40:21.294] [mlr3] Running benchmark with 1 resampling iterations 
#> INFO  [21:40:21.315] [mlr3] Applying learner 'surv.svm' on task 'simsurv' 
#> INFO  [21:40:21.425] [bbotk] Finished optimizing after 3 evaluation(s) 
#> INFO  [21:40:21.425] [bbotk] Result: 
#> INFO  [21:40:21.426] [bbotk]  gamma   mu learner_param_vals  x_domain surv.cindex 
#> INFO  [21:40:21.426] [bbotk]  0.001 1000          <list[3]> <list[1]>           1
#> <PredictionSurv> for 5 observations:
#>  row_ids     time status      crank  response
#>        1 5.000000  FALSE -22.915171 22.915171
#>        2 5.000000  FALSE  -1.442179  1.442179
#>        3 3.640326   TRUE   3.849970 -3.849970
#>        4 0.268220   TRUE   4.269720 -4.269720
#>        5 5.000000  FALSE  -2.670886  2.670886

Created on 2022-02-19 by the reprex package (v2.0.1)

RaphaelS
  • 839
  • 4
  • 14
  • Thanks @RaphaelS. Can the search space for a vector with the transformation be defined instead the lrn() like below? ``` lrn("surv.svm", type = "hybrid", diff.meth = "makediff3", gamma.mu = to_tune(p_dbl(-5, 1, trafo = function(x) )), kernel = to_tune(p-fct(c("lin_kernel", "add_kernel", "rbf_kernel")))) ``` – Ali Alhadab Feb 21 '22 at 03:13
  • I don't think so because the transformation is applied at a parameter set level not parameter level. But maybe someone else in the team will correct me if I'm wrong – RaphaelS Feb 21 '22 at 07:44
  • I think it is possible lrn("surv.svm", type = "hybrid", diff.meth = "makediff3", ps(gamma = p_dbl(0, 10), mu = p_dbl(0, 10), .extra_trafo = function(x, param_set) { x$surv.svm.gamma.mu = c(x$gamma, x$mu) x$gamma = x$mu = NULL x})) – Ali Alhadab Feb 24 '22 at 18:56