The package randomsearch optimizes a given smoof function. Use makeSingleObjectiveFunction() to wrap any function into a smoof function. It can make use of parallel resources through prallelMap. randomsearch has three internal operating modes:

Usage

obj.fun = makeSingleObjectiveFunction(
  fn = function(x) x[1]^2 + sin(x[2]),
  par.set = makeNumericParamSet(len = 2, lower = -1, upper = 2),
  minimize = TRUE
)
res = randomsearch(obj.fun, max.evals = 30)
rs = summary(res)
rs$best.x
## $x
## [1] -0.2617368 -0.8738214
rs$best.y
##          y 
## -0.6982813
tail(as.data.frame(res))
##            x1         x2          y dob eol exec.time
## 25 -0.2020821  1.5734831 1.04083356  25  NA         0
## 26 -0.8625065  0.3266002 1.06474229  26  NA         0
## 27  1.3967745 -0.6343022 1.35836350  27  NA         0
## 28  0.6828440 -0.3804058 0.09497854  28  NA         0
## 29 -0.6174050  1.2599236 1.33325597  29  NA         0
## 30  1.6851361  0.1233883 2.96275907  30  NA         0

Parallel Usage

Note: For Windows use parallelStartSocket().

obj.fun = makeSingleObjectiveFunction(
  fn = function(x) {
    Sys.sleep(runif(1))
    x[1]^2 + sin(x[2])
  },
  par.set = makeNumericParamSet(len = 2, lower = -1, upper = 2),
  minimize = TRUE
)
parallelMap::parallelStartMulticore(cpus = 2, level = "randomsearch.feval")
res = randomsearch(obj.fun, max.execbudget = 2, max.evals = 1000)
summary(res)

Multi-objective optimization

obj.fun = makeMultiObjectiveFunction(
  fn = function(x) c(x[1]^2 + sin(x[2]), cos(x[1])),
  par.set = makeNumericParamSet(len = 2, lower = -1, upper = 2),
  minimize = c(TRUE, TRUE)
)
res = randomsearch(obj.fun, max.evals = 30)
summary(res)
## Randomsearch Result: 
## Multiobjective Search Pareto Front 
##           y_1         y_2         x1         x2
## 4  -0.1517177  0.91064673 0.42594972 -0.3396433
## 6  -0.4762416  0.97319255 0.23206933 -0.5587159
## 7  -0.6152440  0.99846616 0.05539373 -0.6665937
## 9   0.4376802  0.42616485 1.13054720 -0.9981257
## 13  0.8074995  0.39769890 1.16178882 -0.5731171
## 14  1.1552992  0.22204704 1.34688290 -0.7192150
## 18  2.2268508  0.18666793 1.38302696  0.3194951
## 24  2.2964342 -0.08849494 1.65940718 -0.4748420
## 25  3.1651082 -0.23294323 1.80589941 -0.0963133
## 27  4.8156555 -0.37470133 1.95487094  1.6791533