File: TuneControlRandom.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 (40 lines) | stat: -rw-r--r-- 1,548 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
#' @title Create control object for hyperparameter tuning with random search.
#'
#' @description
#' Random search. All kinds of parameter types can be handled.
#'
#' @inherit TuneControl
#' @param budget (`integer(1)`)\cr
#'   Maximum budget for tuning. This value restricts the number of function
#'   evaluations. The `budget` equals the number of iterations (`maxit`) performed by
#'   the random search algorithm.
#' @param maxit (`integer(1)` | NULL)\cr
#'   Number of iterations for random search.
#'   Default is 100.
#' @return ([TuneControlRandom])
#' @aliases TuneControlRandom
#' @family tune
#' @export
makeTuneControlRandom = function(same.resampling.instance = TRUE, maxit = NULL, tune.threshold = FALSE,
  tune.threshold.args = list(), log.fun = "default", final.dw.perc = NULL, budget = NULL) {

  # if we dont get neither budget nor maxit, set it to default, otherwise take one of the 2
  if (is.null(budget) && is.null(maxit)) {
    budget = maxit = 100L
  }
  if (!is.null(maxit)) {
    maxit = asCount(maxit)
  }
  if (!is.null(budget)) {
    budget = asCount(budget)
  }
  maxit = coalesce(maxit, budget)
  budget = coalesce(budget, maxit)
  if (budget != maxit) {
    stopf("The parameters budget (%i) and maxit (%i) differ.", budget, maxit)
  }

  makeTuneControl(same.resampling.instance = same.resampling.instance,
    maxit = maxit, start = NULL, tune.threshold = tune.threshold, tune.threshold.args = tune.threshold.args, final.dw.perc = final.dw.perc,
    log.fun = log.fun, budget = budget, cl = "TuneControlRandom")
}