mlr-org / miesmuschel

Flexible Mixed Integer Evolutionary Strategies
Other
15 stars 4 forks source link

Sumo hyperband #57

Closed mb706 closed 3 years ago

mb706 commented 3 years ago

SumoHB: SUrrogate MOdel assited HyperBand

The Code

A lot of this is boilerplate, unfortunately. The magic happens mainly here:

Try it out

Installation

remotes::install_github("mlr-org/miesmuschel@sumo_hyperband")

Example Code

library("miesmuschel")
library("bbotk")
library("mlr3")
library("mlr3learners")

# some multi-fidelity objective, 'b' is our budget
# b corresponds to sampling a noisy variable multiple times.
objective <- ObjectiveRFun$new(
  fun = function(xs) {
    z <- exp(-xs$x^2 - xs$y^2) + 2 * exp(-(2 - xs$x)^2 - (2 - xs$y)^2)
    z <- z + rnorm(1, sd = 1 / sqrt(xs$b))
    list(Obj = z)
  },
  domain = ps(x = p_dbl(-2, 4), y = p_dbl(-2, 4),
    b = p_int(1, tags = "budget")),
  codomain = ps(Obj = p_dbl(tags = "maximize"))
)

oi <- OptimInstanceSingleCrit$new(objective,
  search_space = objective$domain$search_space(list(
      x = to_tune(),
      y = to_tune(),
      b = to_tune(p_int(1, 32, logscale = TRUE, tags = "budget"))
    )),
  terminator = trm("gens", generations = 6)
)

# The star of the show!
tuner_sumo <- OptimizerSumoHB$new(ftr("surprog", lrn("regr.ranger")))

# This many individuals survive to the next round.
tuner_sumo$param_set$values$survival_fraction = 2/3

# Batch size / Size of a generation
tuner_sumo$param_set$values$mu = 30

# Generate this many individuals and select the single best
# (according to the surrogate model) from them to get the first proposition
tuner_sumo$param_set$values$filtor.filter_rate_first = 100

# For each following proposition, generate this many more individuals and
# selet the (remaining) best
tuner_sumo$param_set$values$filtor.filter_rate_per_sample = 10

# Run optimization
tuner_sumo$optimize(oi)

# look at the result
library("ggplot2")
oi$archive$data[, id := sapply(paste(x, y), function(x) substr(digest::digest(x), 1, 5))]
ggplot(oi$archive$data,
  aes(x = dob, y = Obj, group = id, color = as.numeric(as.factor(id)))
) + geom_line() + geom_point()
codecov[bot] commented 3 years ago

Codecov Report

Merging #57 (b7ca3b0) into master (c1c6718) will not change coverage. The diff coverage is 100.00%.

:exclamation: Current head b7ca3b0 differs from pull request most recent head 05086bc. Consider uploading reports for the commit 05086bc to get more accurate results Impacted file tree graph

@@            Coverage Diff             @@
##            master       #57    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           26        34     +8     
  Lines          979      1288   +309     
==========================================
+ Hits           979      1288   +309     
Impacted Files Coverage Δ
R/MutatorMaybe.R 100.00% <ø> (ø)
R/MutatorProxy.R 100.00% <ø> (ø)
R/RecombinatorMaybe.R 100.00% <ø> (ø)
R/RecombinatorProxy.R 100.00% <ø> (ø)
R/SelectorProxy.R 100.00% <ø> (ø)
R/Filtor.R 100.00% <100.00%> (ø)
R/FiltorMaybe.R 100.00% <100.00%> (ø)
R/FiltorNull.R 100.00% <100.00%> (ø)
R/FiltorProxy.R 100.00% <100.00%> (ø)
R/FiltorSurrogateProgressive.R 100.00% <100.00%> (ø)
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c1c6718...05086bc. Read the comment docs.