spotKeras: spotKEras

View source: R/spotKeras.R

spotKerasR Documentation

spotKEras

Description

A wrapper that calls SPOT when optimizing a keras model with data

Usage

spotKeras(x = NULL, fun, lower, upper, control, kerasConf, kerasData, ...)

Arguments

x

is an optional start point (or set of start points), specified as a matrix. One row for each point, and one column for each optimized parameter.

fun

is the objective function. It should receive a matrix x and return a matrix y. In case the function uses external code and is noisy, an additional seed parameter may be used, see the control$seedFun argument below for details. Mostly, fun must have format y = f(x, ...). If a noisy function requires some specific seed handling, e.g., in some other non-R code, a seed can be passed to fun. For that purpose, the user must specify control$noise = TRUE and fun should be fun(x, seed, ...)

lower

is a vector that defines the lower boundary of search space. This determines also the dimensionality of the problem.

upper

is a vector that defines the upper boundary of search space.

control

is a list with control settings for spot. See spotControl.

kerasConf

List of additional parameters passed to keras as described in getKerasConf.

kerasData

dataset to use

...

additional parameters passed to fun.

Value

This function returns a result list.

Examples


### These examples require an activated Python environment as described in
### Bartz-Beielstein, T., Rehbach, F., Sen, A., and Zaefferer, M.:
### Surrogate Model Based Hyperparameter Tuning for Deep Learning with SPOT,
### June 2021. http://arxiv.org/abs/2105.14625.
PYTHON_RETICULATE <- FALSE
if(PYTHON_RETICULATE){

model <- "dl"
activeVars <- c("layers", "units", "epochs")
kerasConf <- getKerasConf()
kerasConf$active <-  activeVars
cfg <-  getModelConf("dl", active = activeVars)
lower <- cfg$lower
upper <- cfg$upper
types <- cfg$type
result <- spotKeras(x = NULL,
                  fun = funKerasMnist,
                        lower = lower,
                        upper = upper,
                        control = list(funEvals = 2,
                                       noise = TRUE,
                                       types = types,
                                       plots = FALSE,
                                       progress = TRUE,
                                       seedFun = 1,
                                       seedSPOT = 1,
                                       designControl = list(size = 1)),
                         kerasConf = kerasConf,
                         kerasData = getMnistData(kerasConf))
# The result does contain the active parameters only. To get the full vector, use
active2All(x=result$xbest, a=activeVars, model=model)
}


SPOTMisc documentation built on Sept. 5, 2022, 5:06 p.m.