Skip to contents

Surrogate model containing multiple mlr3::LearnerRegr. The mlr3::LearnerRegr are fit on the target variables as indicated via cols_y. Note that redundant mlr3::LearnerRegr must be deep clones.

Parameters

assert_insample_perf

logical(1)
Should the insample performance of the mlr3::LearnerRegr be asserted after updating the surrogate? If the assertion fails (i.e., the insample performance based on the perf_measure does not meet the perf_threshold), an error is thrown. Default is FALSE.

perf_measure

List of mlr3::MeasureRegr
Performance measures which should be use to assert the insample performance of the mlr3::LearnerRegr. Only relevant if assert_insample_perf = TRUE. Default is mlr3::mlr_measures_regr.rsq for each learner.

perf_threshold

List of numeric(1)
Thresholds the insample performance of the mlr3::LearnerRegr should be asserted against. Only relevant if assert_insample_perf = TRUE. Default is 0 for each learner.

catch_errors

logical(1)
Should errors during updating the surrogate be caught and propagated to the loop_function which can then handle the failed acquisition function optimization (as a result of the failed surrogate) appropriately by, e.g., proposing a randomly sampled point for evaluation? Default is TRUE.

Super class

mlr3mbo::Surrogate -> SurrogateLearnerCollection

Active bindings

print_id

(character)
Id used when printing.

n_learner

(integer(1))
Returns the number of surrogate models.

assert_insample_perf

(numeric())
Asserts whether the current insample performance meets the performance threshold.

packages

(character())
Set of required packages. A warning is signaled if at least one of the packages is not installed, but loaded (not attached) later on-demand via requireNamespace().

feature_types

(character())
Stores the feature types the surrogate can handle, e.g. "logical", "numeric", or "factor". A complete list of candidate feature types, grouped by task type, is stored in mlr_reflections$task_feature_types.

properties

(character())
Stores a set of properties/capabilities the surrogate has. A complete list of candidate properties, grouped by task type, is stored in mlr_reflections$learner_properties.

predict_type

(character(1))
Retrieves the currently active predict type, e.g. "response".

Methods

Inherited methods


Method new()

Creates a new instance of this R6 class.

Usage

SurrogateLearnerCollection$new(
  learners,
  archive = NULL,
  cols_x = NULL,
  cols_y = NULL
)

Arguments

learners

(list of mlr3::LearnerRegr).

archive

(bbotk::Archive | NULL)
bbotk::Archive of the bbotk::OptimInstance.

cols_x

(character() | NULL)
Column id's of variables that should be used as features. By default, automatically inferred based on the archive.

cols_y

(character() | NULL)
Column id's of variables that should be used as targets. By default, automatically inferred based on the archive.


Method predict()

Predict mean response and standard error. Returns a named list of data.tables. Each contains the mean response and standard error for one col_y.

Usage

SurrogateLearnerCollection$predict(xdt)

Arguments

xdt

(data.table::data.table())
New data. One row per observation.

Returns

list of data.table::data.table()s with the columns mean and se.


Method clone()

The objects of this class are cloneable with this method.

Usage

SurrogateLearnerCollection$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

if (requireNamespace("mlr3learners") &
    requireNamespace("DiceKriging") &
    requireNamespace("rgenoud") &
    requireNamespace("ranger")) {
  library(bbotk)
  library(paradox)
  library(mlr3learners)

  fun = function(xs) {
    list(y1 = xs$x^2, y2 = (xs$x - 2) ^ 2)
  }
  domain = ps(x = p_dbl(lower = -10, upper = 10))
  codomain = ps(y1 = p_dbl(tags = "minimize"), y2 = p_dbl(tags = "minimize"))
  objective = ObjectiveRFun$new(fun = fun, domain = domain, codomain = codomain)

  instance = OptimInstanceBatchMultiCrit$new(
    objective = objective,
    terminator = trm("evals", n_evals = 5))
  xdt = generate_design_random(instance$search_space, n = 4)$data

  instance$eval_batch(xdt)

  learner1 = default_gp()

  learner2 = default_rf()

  surrogate = srlrn(list(learner1, learner2), archive = instance$archive)

  surrogate$update()

  surrogate$learner

  surrogate$learner[["y2"]]$model
}
#> Loading required namespace: ranger
#> Ranger result
#> 
#> Call:
#>  ranger::ranger(dependent.variable.name = task$target_names, data = task$data(),      case.weights = task$weights$weight, keep.inbag = TRUE, num.threads = 1L,      num.trees = 100L) 
#> 
#> Type:                             Regression 
#> Number of trees:                  100 
#> Sample size:                      4 
#> Number of independent variables:  1 
#> Mtry:                             1 
#> Target node size:                 5 
#> Variable importance mode:         none 
#> Splitrule:                        variance 
#> OOB prediction error (MSE):       4791.712 
#> R squared (OOB):                  -0.404484