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

This package provides a common framework for optimization including

  • 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.

Various optimization methods are already implemented e.g. grid search, random search and generalized simulated annealing.

Resources

Installation

Install the last release from CRAN:

install.packages("bbotk")

Install the development version from GitHub:

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

Examples

Quick optimization with bb_optimize

library(bbotk)

# define objective function
fun = function(xs) {
  c(y = - (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

Advanced optimization

# define objective function
fun = function(xs) {
  c(y = - (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: 0.3359377 -2.310494 <list[2]> 6.755478
# best performing configuration
instance$result
##           x1        x2  x_domain        y
## 1: 0.3359377 -2.310494 <list[2]> 6.755478
# all evaluated configuration
as.data.table(instance$archive)
##             x1        x2          y           timestamp batch_nr x_domain_x1 x_domain_x2
##  1:  0.3359367 -2.310494   6.755475 2021-09-13 11:23:14        1   0.3359367   -2.310494
##  2: -0.9046005  4.567793 -55.708198 2021-09-13 11:23:14        2  -0.9046005    4.567793
##  3: -7.8034191 -2.551681 -86.308016 2021-09-13 11:23:14        3  -7.8034191   -2.551681
##  4: -8.3482136 -2.551681 -97.286514 2021-09-13 11:23:14        4  -8.3482136   -2.551681
##  5: -8.3482136 -1.985619 -98.114492 2021-09-13 11:23:14        5  -8.3482136   -1.985619
##  6:  0.3359367 -2.310494   6.755475 2021-09-13 11:23:14        6   0.3359367   -2.310494
##  7:  0.3359377 -2.310494   6.755478 2021-09-13 11:23:14        7   0.3359377   -2.310494
##  8:  0.3359357 -2.310494   6.755472 2021-09-13 11:23:14        8   0.3359357   -2.310494
##  9:  0.3359367 -2.310493   6.755474 2021-09-13 11:23:14        9   0.3359367   -2.310493
## 10:  0.3359367 -2.310495   6.755476 2021-09-13 11:23:14       10   0.3359367   -2.310495

Copy Link

Version

Install

install.packages('bbotk')

Monthly Downloads

5,371

Version

0.4.0

License

LGPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Marc Becker

Last Published

September 13th, 2021

Functions in bbotk (0.4.0)

Progressor

Progressor
ObjectiveRFun

Objective interface with custom R function
OptimInstanceSingleCrit

Optimization Instance with budget and archive
ArchiveBest

Minimal logging object for objective function evaluations
Optimizer

Optimizer
OptimInstanceMultiCrit

Optimization Instance with budget and archive
ObjectiveRFunDt

Objective interface for basic R functions.
Archive

Logging object for objective function evaluations
Objective

Objective function with domain and co-domain
is_dominated

Calculate which points are dominated
optimize_default

Default optimization function
bbotk-package

bbotk: Black-Box Optimization Toolkit
mlr_terminators_clock_time

Terminator that stops according to the clock time
bb_optimize

Black-Box Optimization
bbotk_assertions

Assertion for bbotk objects
mlr_optimizers_irace

Optimization via Iterated Racing
mlr_optimizers_nloptr

Optimization via Non-linear Optimization
OptimInstance

Optimization Instance with budget and archive
mlr_terminators_perf_reached

Terminator that stops when a performance level has been reached
mlr_terminators_combo

Combine Terminators
bbotk_reflections

Reflections for bbotk
mlr_optimizers_cmaes

Optimization via Covariance Matrix Adaptation Evolution Strategy
transform_xdt_to_xss

Calculates the transformed x-values
mlr_optimizers

Dictionary of Optimizer
Terminator

Abstract Terminator Class
mlr_optimizers_random_search

Optimization via Random Search
mlr_terminators_stagnation

Terminator that stops when optimization does not improve
mlr_terminators

Dictionary of Terminators
mlr_terminators_stagnation_batch

Terminator that stops when optimization does not improve
search_start

Get start values for optimizers.
assign_result_default

Default assign_result function
mlr_terminators_run_time

Terminator that stops according to the run time
mlr_terminators_none

Terminator that never stops.
mlr_terminators_evals

Terminator that stops after a number of evaluations
mlr_optimizers_design_points

Optimization via Design Points
mlr_optimizers_gensa

Optimization via Generalized Simulated Annealing
trm

Syntactic Sugar Terminator Construction
mult_max_to_min

Multiplication vector for output
mlr_optimizers_grid_search

Optimization via Grid Search
opt

Syntactic Sugar Optimizer Construction