Learn R Programming

⚠️There's a newer version (1.5.0) of this package.Take me there.

bbotk - Black-Box Optimization Toolkit

Package website: release | dev

bbotk is a black-box optimization framework for R. It features highly configurable search spaces via the paradox package and optimizes every user-defined objective function. The package includes several optimization algorithms e.g. Random Search, Iterated Racing, Bayesian Optimization (in mlr3mbo) and Hyperband (in mlr3hyperband). bbotk is the base package of mlr3tuning, mlr3fselect and miesmuschel.

The package includes the basic building blocks of optimization:

  • Optimizer: Objects of this class allow you to optimize an object of the class OptimInstance.
  • OptimInstance: Defines the optimization problem, consisting of an Objective, the search_space, and a Terminator. All evaluations on the OptimInstance will be automatically stored in its own Archive.
  • Objective: Objects of this class contain the objective function. The class ensures that the objective function is called in the right way and defines, whether the function should be minimized or maximized.
  • Terminator: Objects of this class control the termination of the optimization independent of the optimizer.

Resources

Installation

Install the last release from CRAN:

install.packages("bbotk")

Install the development version from GitHub:

remotes::install_github("mlr-org/bbotk")

Examples

Optimization

# define the objective function
fun = function(xs) {
  - (xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + 10
}

# set domain
domain = ps(
  x1 = p_dbl(-10, 10),
  x2 = p_dbl(-5, 5)
)

# set codomain
codomain = ps(
  y = p_dbl(tags = "maximize")
)

# create Objective object
objective = ObjectiveRFun$new(
  fun = fun,
  domain = domain,
  codomain = codomain,
  properties = "deterministic"
)

# Define termination criterion
terminator = trm("evals", n_evals = 10)

# create optimization instance
instance = OptimInstanceSingleCrit$new(
  objective = objective,
  terminator = terminator
)

# load optimizer
optimizer = opt("gensa")

# trigger optimization
optimizer$optimize(instance)
##        x1        x2  x_domain        y
## 1: 2.0452 -2.064743 <list[2]> 9.123252
# best performing configuration
instance$result
##        x1        x2  x_domain        y
## 1: 2.0452 -2.064743 <list[2]> 9.123252
# all evaluated configuration
as.data.table(instance$archive)
##            x1        x2          y           timestamp batch_nr x_domain_x1 x_domain_x2
##  1: -4.689827 -1.278761 -37.716445 2024-02-29 11:22:29        1   -4.689827   -1.278761
##  2: -5.930364 -4.400474 -54.851999 2024-02-29 11:22:29        2   -5.930364   -4.400474
##  3:  7.170817 -1.519948 -18.927907 2024-02-29 11:22:29        3    7.170817   -1.519948
##  4:  2.045200 -1.519948   7.807403 2024-02-29 11:22:29        4    2.045200   -1.519948
##  5:  2.045200 -2.064742   9.123250 2024-02-29 11:22:29        5    2.045200   -2.064742
##  6:  2.045200 -2.064742   9.123250 2024-02-29 11:22:29        6    2.045200   -2.064742
##  7:  2.045201 -2.064742   9.123250 2024-02-29 11:22:29        7    2.045201   -2.064742
##  8:  2.045199 -2.064742   9.123250 2024-02-29 11:22:29        8    2.045199   -2.064742
##  9:  2.045200 -2.064741   9.123248 2024-02-29 11:22:29        9    2.045200   -2.064741
## 10:  2.045200 -2.064743   9.123252 2024-02-29 11:22:29       10    2.045200   -2.064743

Quick optimization with bb_optimize

library(bbotk)

# define the objective function
fun = function(xs) {
  c(y1 = - (xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + 10)
}

# optimize function with random search
result = bb_optimize(fun, method = "random_search", lower = c(-10, -5), upper = c(10, 5),
  max_evals = 100)

# optimized parameters
result$par
##           x1       x2
## 1: -7.982537 4.273021
# optimal outcome
result$value
##        y1 
## -142.5479

Copy Link

Version

Install

install.packages('bbotk')

Monthly Downloads

5,373

Version

0.8.0

License

LGPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Marc Becker

Last Published

February 29th, 2024

Functions in bbotk (0.8.0)

ObjectiveRFunMany

Objective Interface with Custom R Function
ContextOptimization

Optimization Context
CallbackOptimization

Create Optimization Callback
Objective

Objective function with domain and co-domain
ObjectiveRFun

Objective interface with custom R function
ArchiveBest

Minimal logging object for objective function evaluations
ObjectiveRFunDt

Objective interface for basic R functions.
Archive

Logging object for objective function evaluations
Codomain

Codomain of Function
OptimInstance

Optimization Instance with budget and archive
bbotk.backup

Backup Archive Callback
bb_optimize

Black-Box Optimization
Progressor

Progressor
bbotk_assertions

Assertion for bbotk objects
Terminator

Abstract Terminator Class
OptimInstanceMultiCrit

Optimization Instance with budget and archive
OptimInstanceSingleCrit

Optimization Instance with budget and archive
bbotk-package

bbotk: Black-Box Optimization Toolkit
Optimizer

Optimizer
assign_result_default

Default assign_result function
mlr_optimizers

Dictionary of Optimizer
is_dominated

Calculate which points are dominated
mlr_optimizers_focus_search

Optimization via Focus Search
callback_optimization

Create Optimization Callback
mlr_optimizers_design_points

Optimization via Design Points
bbotk_reflections

Reflections for bbotk
mlr_optimizers_gensa

Optimization via Generalized Simulated Annealing
mlr_optimizers_grid_search

Optimization via Grid Search
mlr_optimizers_cmaes

Optimization via Covariance Matrix Adaptation Evolution Strategy
branin

Branin Function
mlr_optimizers_random_search

Optimization via Random Search
mlr_terminators_clock_time

Clock Time Terminator
mlr_terminators_none

None Terminator
mlr_terminators_perf_reached

Performance Level Terminator
mlr_optimizers_irace

Optimization via Iterated Racing
mlr_terminators

Dictionary of Terminators
mlr_terminators_run_time

Run Time Terminator
mlr_terminators_combo

Combine Terminators
mlr_optimizers_nloptr

Optimization via Non-linear Optimization
mlr_terminators_evals

Terminator that stops after a number of evaluations
search_start

Get start values for optimizers
mlr_terminators_stagnation_batch

Terminator that stops when optimization does not improve
mlr_terminators_stagnation

Terminator that stops when optimization does not improve
trm

Syntactic Sugar Terminator Construction
shrink_ps

Shrink a ParamSet towards a point.
opt

Syntactic Sugar Optimizer Construction
reexports

Objects exported from other packages
optimize_default

Default optimization function
nds_selection

Best points w.r.t. non dominated sorting with hypervolume contribution.
transform_xdt_to_xss

Calculates the transformed x-values