File: checkTunerParset.R

package info (click to toggle)
r-cran-mlr 2.13-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,760 kB
  • sloc: ansic: 65; sh: 13; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 2,289 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# check this:
# - tune algo exists
# - parameters are not empty
# - threshold tuning can be done
# - algo can handle these parameters
# - algo can handle dependencies

checkTunerParset = function(learner, par.set, measures, control) {
  cl = getClass1(control)

  if (getParamNr(par.set) == 0L)
    stop("No parameters were passed!")

  x = setdiff(names(par.set$pars), names(getParamSet(learner)$pars))
  if (length(x) > 0L)
    stopf("Can only tune parameters for which learner parameters exist: %s", collapse(x))

  checkParsOk = function(algo, ok)
    if (length(filterParams(par.set, type = ok)$pars) < length(par.set$pars))
      stopf("%s can only be applied to: %s!", algo, collapse(ok))

  checkStart = function() {
    if (!is.null(control$start)) {
      if (length(control$start) != length(par.set$pars))
        stop("Length of 'start' has to match number of parameters in 'par.set'!")
      x = setdiff(names(control$start), names(getParamSet(learner)$pars))
      if (length(x))
        stopf("'start' contains parameters for which no learner parameters exist: %s", collapse(x))
    }
  }

  if (control$tune.threshold && (learner$type != "classif" || learner$predict.type != "prob"))
    stop("Using 'tune.threshold' requires a classif learner with predict.type = 'prob'!")

  # check special conditions for some tuners
  if (inherits(control, "TuneControlCMAES")) {
    checkParsOk("CMAES", c("numeric", "integer", "numericvector", "integervector"))
    checkStart()
  }
  if (inherits(control, "TuneControlGenSA")) {
    checkParsOk("GenSA", c("numeric", "integer", "numericvector", "integervector"))
    checkStart()
  }
  if (inherits(control, "TuneControlNSGA2")) {
    checkParsOk("NSGA2", c("numeric", "integer", "numericvector", "integervector"))
  }

  # check requires / dependent params
  if (hasRequires(par.set) && cl %nin% c("TuneControlRandom", "TuneControlGrid",
      "TuneControlDesign", "TuneControlIrace", "TuneControlMBO", "TuneMultiCritControlRandom",
      "TuneMultiCritControlMBO"))
    stopf("Tuning algorithm for '%s' cannot handle dependent parameters!", cl)

  if (inherits(control, "TuneMultiCritControl"))
    if (length(control$impute.val) != length(measures))
      stop("Length of 'impute.val' must coincide with number of measures!")


}