bracket: R6 class to create single bracket objects

Description Usage Format Value Fields Methods Examples

Description

An R6Class that consits of multiple algorithm objects

Usage

1

Format

R6Class object

Value

Bracket object

Fields

max.perf

[logical()]
TRUE if to maximize the performance (e.g. accuracy of a neural net), FALSE if to minimize the performance (e.g. find the minimum of the branin function).

max.ressources

[integer()]
The maximum amount of resource that can be allocated to a single configuration

prop.discard

[integer()]
An input that controls the proportion of configurations discarded in each round of successive halving

s

[integer()]
The s'th bracket object to create. Note that s is in
(0,...,floor(log(max.ressources, base = prop.discard)))

B

[integer()]
The total budget for the bracket. Note that B is given by
(max(s) + 1)*max.ressources

id

[string]
An id for each Algorithm object in the bracket object

par.set


The parameter set to sample from

sample.fun


The function to sample from par.set

train.fun


The function to carry out training

performance.fun

The function to measure the performance

Methods

$run() computes the whole bracket
$step() computes one iteration of successive halving
$getTopKModels(k) displays the best k models
$filterTopKModels(k) filters the best k models and deletes the remaining models from the bracket object
$getPerformances() computes the performance of all remaining models
$visPerformances() visualizes the performance of the bracket

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# we need some packages
library("ggplot2")
library("smoof")
library("data.table")
library("dplyr")

# simple example for the branin function, a minimization problem
problem = makeBraninFunction()
opt = data.table(x1 = getGlobalOptimum(problem)$param$x1, x2 = getGlobalOptimum(problem)$param$x2)
# the three red dots are global minima
autoplot(problem) + geom_point(data = opt, aes(x = x1, y = x2), shape = 20, colour = "red", size = 5)

# config space
configSpace = makeParamSet(
    makeNumericParam(id = "x1", lower = -5, upper = 10.1))

# sample fun
sample.fun = function(par.set, n.configs, ...) {
  sampleValues(par = par.set, n = n.configs)
}

# init fun
init.fun = function(r, config) {
  x1 = unname(unlist(config))
  x2 = runif(1, 0, 15)
  mod = c(x1, x2)
  return(mod)
}

# train fun
train.fun = function(mod, budget) {
  for(i in seq_len(budget)) {
    mod.new = c(mod[[1]], mod[[2]] + rnorm(1, sd = 3))
    if(performance.fun(mod.new) < performance.fun(mod))
      mod = mod.new
  }
  return(mod)
}

# performance fun
performance.fun = function(model) {
  problem(c(model[[1]], model[[2]]))
}

###### make branin bracket object #####
brack = bracket$new(
  max.perf = FALSE,
  max.ressources = 81,
  prop.discard = 3,
  s = 4,
  B = (4 + 1)*81,
  id = "branin",
  par.set = configSpace,
  sample.fun = sample.fun,
  train.fun = train.fun,
  performance.fun = performance.fun)
  
# the data matrix shows us the hyperparameters, the current budget and the performance
brack$bracket.storage$data.matrix
# run the bracket
brack$run()
# inspect the data matrix again
brack$bracket.storage$data.matrix
# visualize the the bracket
brack$visPerformances()
# access the performance of the best model
brack$getPerformances()

ja-thomas/hyperbandr documentation built on April 15, 2018, 12:19 p.m.