|
15 | 15 | #' |
16 | 16 | #' Termination is handled via a [bbotk::Terminator] part of the [bbotk::OptimInstance] to be optimized. |
17 | 17 | #' |
| 18 | +#' Note that in general the [Surrogate] is updated one final time on all available data after the optimization process has terminated. |
| 19 | +#' However, in certain scenarios this is not always possible or meaningful, e.g., when using [bayesopt_parego()] for multi-objective optimization |
| 20 | +#' which uses a surrogate that relies on a scalarization of the objectives. |
| 21 | +#' It is therefore recommended to manually inspect the [Surrogate] after optimization if it is to be used, e.g., for visualization purposes to make |
| 22 | +#' sure that it has been properly updated on all available data. |
| 23 | +#' If this final update of the [Surrogate] could not be performed successfully, a warning will be logged. |
| 24 | +#' |
18 | 25 | #' @section Archive: |
19 | 26 | #' The [bbotk::Archive] holds the following additional columns that are specific to MBO algorithms: |
20 | 27 | #' * `[acq_function$id]` (`numeric(1)`)\cr |
@@ -274,6 +281,7 @@ OptimizerMbo = R6Class("OptimizerMbo", |
274 | 281 |
|
275 | 282 | .optimize = function(inst) { |
276 | 283 | # FIXME: this needs more checks for edge cases like eips or loop_function bayesopt_parego then default_surrogate should use one learner |
| 284 | + |
277 | 285 | if (is.null(self$loop_function)) { |
278 | 286 | self$loop_function = default_loop_function(inst) |
279 | 287 | } |
@@ -303,6 +311,17 @@ OptimizerMbo = R6Class("OptimizerMbo", |
303 | 311 | check_packages_installed(self$packages, msg = sprintf("Package '%%s' required but not installed for Optimizer '%s'", format(self))) |
304 | 312 |
|
305 | 313 | invoke(self$loop_function, instance = inst, surrogate = self$surrogate, acq_function = self$acq_function, acq_optimizer = self$acq_optimizer, .args = self$args) |
| 314 | + |
| 315 | + on.exit({ |
| 316 | + tryCatch( |
| 317 | + { |
| 318 | + self$surrogate$update() |
| 319 | + }, surrogate_update_error = function(error_condition) { |
| 320 | + logger = lgr::get_logger("bbotk") |
| 321 | + logger$warn("Could not update the surrogate a final time after the optimization process has terminated.") |
| 322 | + } |
| 323 | + ) |
| 324 | + }) |
306 | 325 | }, |
307 | 326 |
|
308 | 327 | .assign_result = function(inst) { |
|
0 commit comments