File: TuneMultiCritControlNSGA2.R

package info (click to toggle)
r-cran-mlr 2.19.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,264 kB
  • sloc: ansic: 65; sh: 13; makefile: 5
file content (44 lines) | stat: -rw-r--r-- 1,645 bytes parent folder | download | duplicates (3)
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
#' @export
#' @rdname TuneMultiCritControl
makeTuneMultiCritControlNSGA2 = function(same.resampling.instance = TRUE,
  impute.val = NULL, log.fun = "default", final.dw.perc = NULL, budget = NULL, ...) {

  args = list(...)
  if (is.null(args$popsize)) {
    if (!is.null(budget) && !is.null(args$generations)) {
      # define popsize via the number of generations and the budget
      args$popsize = budget %/% (max(args$generations) + 1L)
    } else {
      # alternatively use the nsga2-default
      args$popsize = 100L
    }
  }

  if (is.null(args$generations)) {
    if (!is.null(budget)) {
      # define generations via popsize and the budget
      args$generations = (budget %/% args$popsize) - 1L
    } else {
      # alternatively use the nsga2-default
      args$generations = 100L
    }
  }

  # adapt budget to the population size and number of generations
  if (is.null(budget)) {
    budget = (max(args$generations) + 1) * args$popsize
  } else if (budget != (max(args$generations) + 1) * args$popsize) {
    stopf("The given 'budget' (%i) contradicts the product of 'popsize' (%i) and 'max(generations) + 1' (%i)!",
      budget, args$popsize, args$generations + 1)
  }

  # sanity checks and type conversion
  args$popsize = asCount(args$popsize, positive = TRUE)
  args$generations = asInteger(args$generations, lower = 1L)
  budget = asCount(budget, positive = TRUE)

  args2 = list(same.resampling.instance = same.resampling.instance, impute.val = impute.val,
    log.fun = log.fun, final.dw.perc = final.dw.perc, budget = budget,
    cl = "TuneMultiCritControlNSGA2")
  do.call(makeTuneMultiCritControl, c(args, args2))
}