R Interface to 'libcmaes'

A lightweight interface to the 'libcmaes' C++ library for the Covariance Matrix Adaptation Evolution Strategy (CMA-ES). CMA-ES is a state-of-the-art evolutionary algorithm for the optimization of difficult non-linear, non-convex black-box functions, as described in Hansen and Ostermeier (2001) . Supports the active, separable, and VD (diagonal plus rank-one covariance) variants of the algorithm as well as the IPOP (increasing population size) and BIPOP (bi-population) restart strategies. A patched copy of 'libcmaes' (LGPL >= 3) is bundled; see the COPYRIGHTS file for details.


libcmaesr

R-CMD-check CRANstatus

A lightweight R interface to the libcmaes C++ library for covariance matrix adaptation evolution strategy (CMA-ES). It allows for the optimization of black-box functions using the CMA-ES algorithm and its variants.

A patched copy of libcmaes is bundled with the package, so no system dependencies are needed beyond a standard C++ toolchain (Eigen headers are provided by the RcppEigen package at build time).

Installation

Install the released version from CRAN with:

install.packages("libcmaesr")

Or install the development version from GitHub with:

# install.packages("pak")
pak::pak("mlr-org/libcmaesr")

Example

This is a basic example which shows you how to solve a common test problem, the sphere function. The objective function receives a numeric vector and returns a single number. cmaes_control() collects the settings of the algorithm, and cmaes() runs the optimization.

library(libcmaesr)

fn = function(x) sum(x^2)

dim = 3
x0 = rep(0.5, dim)
lower = rep(-1, dim)
upper = rep(1, dim)

control = cmaes_control(algo = "bipop", max_fevals = 5000 * dim, seed = 123, lambda = 5)
res = cmaes(fn, x0, lower, upper, control)

res$x
#> [1] -1.102e-09 -4.948e-10  1.933e-09
res$y
#> [1] 5.195e-18
res$status_msg
#> [1] "[Success] The optimization has converged"

Batch evaluation

Set batch = TRUE to evaluate a whole generation at once. The objective function then receives a matrix with lambda rows and one column per dimension, and returns one objective value per row. This is useful when the evaluation can be vectorized or parallelized.

fn_batch = function(x) rowSums(x^2)

control = cmaes_control(algo = "acmaes", max_fevals = 1000, seed = 123, lambda = 10)
res = cmaes(fn_batch, x0, lower, upper, control, batch = TRUE)

res$y
#> [1] 2.185e-16

Algorithms

The variant is selected with the algo argument of cmaes_control(). The default is "acmaes", as recommended by the libcmaes practical hints. For multimodal problems, "ipop" or "bipop" are usually the better choice.

cmaes_algos
#>  [1] "cmaes"      "ipop"       "bipop"      "acmaes"     "aipop"      "abipop"     "sepcmaes"  
#>  [8] "sepipop"    "sepbipop"   "sepacmaes"  "sepaipop"   "sepabipop"  "vdcma"      "vdipopcma" 
#> [15] "vdbipopcma"

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("libcmaesr")

0.1.0 by Marc Becker, 2 months ago


https://libcmaesr.mlr-org.com, https://github.com/mlr-org/libcmaesr


Report a bug at https://github.com/mlr-org/libcmaesr/issues


Browse source code at https://github.com/cran/libcmaesr


Authors: Marc Becker [aut, cre, cph] (ORCID: , Bernd Bischl [aut] , Martin Binder [aut] , Lars Kotthoff [aut] , Emmanuel Benazera [ctb, cph] (author of the bundled 'libcmaes' library) , Inria [cph] (copyright holder of parts of the bundled 'libcmaes' library)


Documentation:   PDF Manual  


LGPL (>= 3) license


Imports checkmate, mlr3misc, stats

Suggests testthat, callr

Linking to RcppEigen


Suggested by bbotk, mlr3tuning.


See at CRAN