Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
be-marc committed Sep 13, 2024
1 parent 51d9c0d commit 367583c
Show file tree
Hide file tree
Showing 19 changed files with 473 additions and 328 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ Collate:
'AcqFunctionSmsEgo.R'
'AcqOptimizer.R'
'aaa.R'
'OptimizerMbo.R'
'OptimizerAsyncMbo.R'
'OptimizerADBO.R'
'OptimizerMbo.R'
'mlr_result_assigners.R'
'ResultAssigner.R'
'ResultAssignerArchive.R'
Expand All @@ -103,7 +102,7 @@ Collate:
'SurrogateLearner.R'
'SurrogateLearnerAsync.R'
'SurrogateLearnerCollection.R'
'TunerADBO.R'
'TunerAsyncMbo.R'
'TunerMbo.R'
'mlr_loop_functions.R'
'bayesopt_ego.R'
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export(AcqFunctionPI)
export(AcqFunctionSD)
export(AcqFunctionSmsEgo)
export(AcqOptimizer)
export(OptimizerADBO)
export(OptimizerAsyncMbo)
export(OptimizerMbo)
export(ResultAssigner)
export(ResultAssignerArchive)
Expand All @@ -26,7 +26,7 @@ export(Surrogate)
export(SurrogateLearner)
export(SurrogateLearnerAsync)
export(SurrogateLearnerCollection)
export(TunerADBO)
export(TunerAsyncMbo)
export(TunerMbo)
export(acqf)
export(acqfs)
Expand Down
152 changes: 0 additions & 152 deletions R/OptimizerADBO.R

This file was deleted.

11 changes: 4 additions & 7 deletions R/OptimizerAsyncMbo.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ OptimizerAsyncMbo = R6Class("OptimizerAsyncMbo",

#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function(surrogate = NULL, acq_function = NULL, acq_optimizer = NULL) {
param_set = ps(
initialize = function(surrogate = NULL, acq_function = NULL, acq_optimizer = NULL, param_set = NULL) {
default_param_set = ps(
initial_design = p_uty(),
design_size = p_int(lower = 1, default = 10),
design_function = p_fct(c("random", "sobol", "lhs"), default = "sobol")
)
param_set = c(default_param_set, param_set)

param_set$set_values(design_size = 10, design_function = "sobol")

Expand Down Expand Up @@ -113,17 +114,13 @@ OptimizerAsyncMbo = R6Class("OptimizerAsyncMbo",
properties = function(rhs) {
assert_ro_binding(rhs)

properties_loop_function = c("single-crit", "multi-crit")
if (!is.null(self$loop_function)) {
properties_loop_function = intersect(properties_loop_function, attr(self$loop_function, "instance"))
}
properties_surrogate = "dependencies"
if (!is.null(self$surrogate)) {
if ("missings" %nin% self$surrogate$properties) {
properties_surrogate = character()
}
}
unname(c(properties_surrogate, properties_loop_function))
unname(c(properties_surrogate))
},

#' @template field_packages
Expand Down
34 changes: 34 additions & 0 deletions R/TunerAsyncMbo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' @title Asynchronous Model Based Optimization
#'
#' @name mlr_tuners_async_mbo
#'
#' @description
#' `TunerAsyncMbo` class that implements Asynchronous Model Based Optimization (MBO).
#'
#' @export
TunerAsyncMbo = R6Class("TunerAsyncMbo",
inherit = mlr3tuning::TunerAsyncFromOptimizerAsync,
public = list(

#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function(surrogate = NULL, acq_function = NULL, acq_optimizer = NULL, param_set = NULL) {
optimizer = OptimizerAsyncMbo$new(
surrogate = surrogate,
acq_function = acq_function,
acq_optimizer = acq_optimizer,
param_set = param_set
)

super$initialize(
optimizer = optimizer,
man = "mlr3tuning::mlr_tuners_async_mbo"
)
}
)
)

mlr_tuners$add("async_mbo", TunerAsyncMbo)

#' @include aaa.R
tuners[["async_mbo"]] = TunerAsyncMbo
124 changes: 124 additions & 0 deletions attic/OptimizerADBO.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# #' @title Asynchronous Decentralized Bayesian Optimization
# #' @name mlr_optimizers_adbo
# #'
# #' @description
# #' Asynchronous Decentralized Bayesian Optimization (ADBO).
# #'
# #' @note
# #' The \eqn{\lambda} parameter of the upper confidence bound acquisition function controls the trade-off between exploration and exploitation.
# #' A large \eqn{\lambda} value leads to more exploration, while a small \eqn{\lambda} value leads to more exploitation.
# #' ADBO can use periodic exponential decay to reduce \eqn{\lambda} periodically to the exploitation phase.
# #'
# #' @section Parameters:
# #' \describe{
# #' \item{`lambda`}{`numeric(1)`\cr
# #' \eqn{\lambda} value used for the confidence bound.
# #' Defaults to `1.96`.}
# #' \item{`exponential_decay`}{`lgl(1)`\cr
# #' Whether to use periodic exponential decay for \eqn{\lambda}.}
# #' \item{`rate`}{`numeric(1)`\cr
# #' Rate of the exponential decay.}
# #' \item{`t`}{`integer(1)`\cr
# #' Period of the exponential decay.}
# #' \item{`initial_design_size`}{`integer(1)`\cr
# #' Size of the initial design.}
# #' \item{`initial_design`}{`data.table`\cr
# #' Initial design.}
# #' \item{`impute_method`}{`character(1)`\cr
# #' Imputation method for missing values in the surrogate model.}
# #' \item{`n_workers`}{`integer(1)`\cr
# #' Number of workers to use.
# #' Defaults to the number of workers set by `rush::rush_plan()`}
# #' }
# #'
# #' @export
# OptimizerADBO = R6Class("OptimizerADBO",
# inherit = OptimizerAsyncMbo,

# public = list(

# #' @description
# #' Creates a new instance of this [R6][R6::R6Class] class.
# initialize = function() {
# param_set = ps(
# lambda = p_dbl(lower = 0, default = 1.96),
# exponential_decay = p_lgl(default = TRUE),
# rate = p_dbl(lower = 0, default = 0.1),
# period = p_int(lower = 1L, default = 25L),
# # impute_method = p_fct(c("mean", "random"), default = "random"),
# n_workers = p_int(lower = 1L, default = NULL, special_vals = list(NULL))
# )

# param_set$set_values(lambda = 1.96, exponential_decay = TRUE, rate = 0.1, period = 25L, design_size = 1L, impute_method = "random")

# super$initialize("adbo",
# param_set = param_set,
# param_classes = c("ParamLgl", "ParamInt", "ParamDbl", "ParamFct"),
# properties = c("dependencies", "single-crit"),
# packages = "mlr3mbo",
# label = "Asynchronous Decentralized Bayesian Optimization",
# man = "mlr3mbo::OptimizerADBO")
# }
# ),

# private = list(

# .optimize = function(inst) {
# pv = self$param_set$values
# search_space = inst$search_space
# archive = inst$archive

# # sample lambda from exponential distribution
# lambda_0 = rexp(1, 1 / pv$lambda)
# t = 0

# surrogate = default_surrogate(inst)
# surrogate$param_set$set_values(impute_method = pv$impute_method)
# acq_function = acqf("cb", lambda = runif(1, 1 , 3))
# acq_optimizer = acqo(opt("random_search", batch_size = 1000L), terminator = trm("evals", n_evals = 10000L))
# surrogate$archive = inst$archive
# acq_function$surrogate = surrogate
# acq_optimizer$acq_function = acq_function

# lg$debug("Optimizer '%s' evaluates the initial design", self$id)
# evaluate_queue_default(inst)

# lg$debug("Optimizer '%s' starts the tuning phase", self$id)

# # actual loop
# while (!inst$is_terminated) {

# # decrease lambda
# if (pv$exponential_decay) {
# lambda = lambda_0 * exp(-pv$rate * (t %% pv$period))
# t = t + 1
# } else {
# lambda = pv$lambda
# }

# # sample
# acq_function$constants$set_values(lambda = lambda)
# acq_function$surrogate$update()
# acq_function$update()
# xdt = acq_optimizer$optimize()

# # transpose point
# xss = transpose_list(xdt)
# xs = xss[[1]][inst$archive$cols_x]
# lg$trace("Optimizer '%s' draws %s", self$id, as_short_string(xs))
# xs_trafoed = trafo_xs(xs, search_space)

# # eval
# key = archive$push_running_point(xs)
# ys = inst$objective$eval(xs_trafoed)

# # push result
# extra = c(xss[[1]][c("acq_cb", ".already_evaluated")], list(lambda_0 = lambda_0, lambda = lambda))
# archive$push_result(key, ys, x_domain = xs_trafoed, extra = extra)
# }
# }
# )
# )

# #' @include aaa.R
# optimizers[["adbo"]] = OptimizerADBO
File renamed without changes.
Loading

0 comments on commit 367583c

Please sign in to comment.