genoud_cache: Run the 'genoud' Optimization Function with a Cached Gradient

View source: R/genoud_cache.R

genoud_cacheR Documentation

Run the genoud Optimization Function with a Cached Gradient

Description

Run the genoud function from the rgenoud package with the objective and the gradient defined in one function. The result is global minimization of a real-valued function of a numeric vector with length d to be provided by fn. The R function fn must provide the values of the objective and its gradient.

The formal arguments of this function and their default values are those of gthe genoud function at the time when this function is written, based on version 5.8.3.0 of rgenoud.

Usage

genoud_cache(
  fn,
  nvars,
  max = FALSE,
  pop.size = 1000,
  max.generations = 100,
  wait.generations = 10,
  hard.generation.limit = TRUE,
  starting.values = NULL,
  MemoryMatrix = TRUE,
  Domains = NULL,
  default.domains = 10,
  solution.tolerance = 0.001,
  gr = NULL,
  boundary.enforcement = 0,
  lexical = FALSE,
  gradient.check = TRUE,
  BFGS = TRUE,
  data.type.int = FALSE,
  hessian = FALSE,
  unif.seed = round(runif(1, 1, 2147483647L)),
  int.seed = round(runif(1, 1, 2147483647L)),
  print.level = 2,
  share.type = 0,
  instance.number = 0,
  output.path = "stdout",
  output.append = FALSE,
  project.path = NULL,
  P1 = 50,
  P2 = 50,
  P3 = 50,
  P4 = 50,
  P5 = 50,
  P6 = 50,
  P7 = 50,
  P8 = 50,
  P9 = 0,
  P9mix = NULL,
  BFGSburnin = 0,
  BFGSfn = NULL,
  BFGShelp = NULL,
  control = list(),
  optim.method = ifelse(boundary.enforcement < 2, "BFGS", "L-BFGS-B"),
  transform = FALSE,
  debug = FALSE,
  cluster = FALSE,
  balance = FALSE,
  ...
)

Arguments

fn

A function to be minimized. This function should return a list with two named numeric elements objective and gradient representing the value of the objective (length 1) and the gradient (length d).

nvars, max, pop.size, max.generations

See genoud.

wait.generations, hard.generation.limit

See genoud.

starting.values

See genoud.

MemoryMatrix

See genoud.

Domains

See genoud.

default.domains

See genoud.

solution.tolerance

See genoud.

gr

Can not be used. This argument is for compatibility

boundary.enforcement

See genoud.

lexical

See genoud.

gradient.check

See genoud.

BFGS

See genoud.

data.type.int

See genoud.

hessian

See genoud.

unif.seed

See genoud.

int.seed

See genoud.

print.level

See genoud.

share.type

See genoud.

instance.number

See genoud.

output.path

See genoud.

output.append

See genoud.

project.path

See genoud.

P1, P2, P3, P4, P5, P6

See genoud.

P7, P8, P9, P9mix

See genoud.

BFGSburnin

See genoud.

BFGSfn

See genoud.

BFGShelp

See genoud.

control

See genoud.

optim.method

See genoud.

transform

See genoud.

debug

See genoud.

cluster

See genoud.

balance

See genoud.

...

Further arguments to be passed to the function given in fn.

Value

The result of a call to genoud.

Caution

This function is hightly experimental and has not been tested enough yet. It should be refactored on the basis of optim_cache which is more achieved.

Note

The optimization is expected to be faster than genoud if the function and its gradient are costly to evaluate separately. However this may not be the case for quite simple functions, due to the cost of setting the "cache" mechanism.

Examples


## Not run: 
## Note that in this example, gradient caching would not be worth it.

dom <- cbind(lower = rep(0.0, 2), upper = rep(1.0, 2))
library(rgenoud)

## emulate a costly-to-evaluate-alone gradient
## ===========================================
braninDer <- function(x) {
   Sys.sleep(0.01)
   branin_with_grad(x)$gradient
}

## separate objective and gradient functions
## =========================================
te <- system.time(res <- genoud(fn = branin, nvars = 2,
                                unif.seed = 123,
                                int.seed = 456,
                                Domains = dom,
                                gr = braninDer))

## gradient "cached"
## ================
teCache <- system.time(resCache <- genoud_cache(fn = branin_with_grad, nvars = 2,
                                                unif.seed = 123,
                                                int.seed = 456,
                                                Domains = dom))
rbind("genoud" = te, "genoud_cache" = teCache)
c("genoud" = res$value, "genoud_cache" = resCache$value)

## Check the use of ...
## ====================
braninShift <- function(x, shift = 0) {
    res <- branin_with_grad(x)
    res$objective <- res$objective + shift
    res
 }
 resShifted <- genoud_cache(fn = braninShift, nvars = 2,
                            unif.seed = 123,
                            int.seed = 456,
                            Domains = dom,
                            shift = 100)
c("genoud_cache" = resCache$value, "genoudShifted" = resShifted$value - 100)

## End(Not run)

libKriging/dolka documentation built on April 14, 2022, 7:17 a.m.