| Title: | R Interface to 'libcmaes' |
| Version: | 0.1.0 |
| Copyright: | See the file COPYRIGHTS for details on the bundled 'libcmaes' copyrights |
| Description: | 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) <doi:10.1162/106365601750190398>. 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. |
| License: | LGPL (≥ 3) |
| URL: | https://libcmaesr.mlr-org.com, https://github.com/mlr-org/libcmaesr |
| BugReports: | https://github.com/mlr-org/libcmaesr/issues |
| Depends: | R (≥ 4.2.0) |
| Imports: | checkmate, mlr3misc, stats |
| LinkingTo: | RcppEigen |
| Suggests: | testthat (≥ 3.0.0), callr |
| Config/testthat/edition: | 3 |
| Config/testthat/parallel: | false |
| Encoding: | UTF-8 |
| Language: | en-US |
| NeedsCompilation: | yes |
| Config/roxygen2/version: | 8.0.0 |
| Packaged: | 2026-07-29 07:47:25 UTC; marc |
| Author: | Marc Becker |
| Maintainer: | Marc Becker <marcbecker@posteo.de> |
| Repository: | CRAN |
| Date/Publication: | 2026-08-07 10:30:02 UTC |
libcmaesr: R Interface to 'libcmaes'
Description
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) doi:10.1162/106365601750190398. 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.
Author(s)
Maintainer: Marc Becker marcbecker@posteo.de (ORCID) [copyright holder]
Authors:
Marc Becker marcbecker@posteo.de (ORCID) [copyright holder]
Bernd Bischl bernd_bischl@gmx.net (ORCID)
Martin Binder mlr.developer@mb706.com
Lars Kotthoff lk223@st-andrews.ac.uk
Other contributors:
Emmanuel Benazera (author of the bundled 'libcmaes' library) [contributor, copyright holder]
Inria (copyright holder of parts of the bundled 'libcmaes' library) [copyright holder]
See Also
Useful links:
Report bugs at https://github.com/mlr-org/libcmaesr/issues
Covariance Matrix Adaptation Evolution Strategy
Description
Implements the CMA-ES variants provided by libcmaes, see here: https://github.com/CMA-ES/libcmaes/ via a very light-weight C wrapper.
The control structure allows access to most control params of the ES, but CMAES is supposed to handle most of them internally. Quoting Niko Hansen from here: https://cma-es.github.io/:
“The CMA-ES does not require a tedious parameter tuning for its application. In fact, the choice of strategy internal parameters
is not left to the user (arguably with the exception of population size \lambda). Finding good (default) strategy
parameters is considered as part of the algorithm design, and not part of its application — the aim is to have a
well-performing algorithm as is.
The default population size \lambda is comparatively small to allow for fast convergence.
Restarts with increasing population size (Auger & Hansen 2005) improve the global search performance.
For the application of the CMA-ES, an initial solution,
an initial standard deviation (step-size, variables should be defined such that the same standard deviations can be
reasonably applied to all variables, see also here) and, possibly, the termination criteria (e.g. a function tolerance)
need to be set by the user. The most common applications are model calibration (e.g. curve fitting) and shape optimisation.”
Whether you believe in this completely for any problem is up to you, but the general idea is to run it in its defaults, and only change them if you know what you are doing.
libcmaes could handle unbounded search spaces, but this is currently not supported, you need to set lower and upper bounds.
Noisy functions / noisy handling CMAES is currently not supported.
Surrogate variants are currently not supported.
Geno-Pheno transformation is automatically applied, in the sense that we use the linear scaling to handle the bounds.
Setting gradients is currently not supported.
OpenMP is currently not supported. libcmaes uses OpenMP for the population evaluation mainly, but also for some Eigen stuff. Calling into the R Api via threading is not allowed, which would happen in the former.
The number of function evaluations is not reported. libcmaes returns the solution object of the best restart run, which only counts the evaluations of that run and therefore undercounts the total whenever restarts happen (
"ipop","bipop"and their separable variants), see https://github.com/CMA-ES/libcmaes/issues/258. Count the calls to your objective function yourself if you need this number.
In general, more details can be found here: https://github.com/CMA-ES/libcmaes/wiki/.
Usage
cmaes(objective, x0, lower, upper, control = cmaes_control(), batch = FALSE)
Arguments
objective |
( |
x0 |
( |
lower |
( |
upper |
( |
control |
( |
batch |
( |
Value
(named list). List with elements:
'x': (
numeric(n))
The best point found, length corresponds to x0, lower and upper.'y': (
numeric(1))
The objective value of the best point.'edm': (
numeric(1))
Expected distance to the minimum.'time': (
numeric(1))
The time taken to find the solution in seconds.'status_code': (
integer(1))
The status code, indicating success, failure, or the reason for stopping. See here: https://github.com/CMA-ES/libcmaes/wiki/Optimizing-a-function'status_msg': (
character(1))
A human-readable status message from libcmaes.
Examples
# minimize a simple quadratic function
objective = function(x) sum(x^2)
control = cmaes_control(seed = 1, max_fevals = 500)
res = cmaes(objective, x0 = c(0.5, 0.5), lower = c(-5, -5), upper = c(5, 5), control = control)
res$x
res$y
CMAES Algorithm Names
Description
A vector of strings containing the names of the CMAES variants. See https://cma-es.github.io/libcmaes/doc/html/classlibcmaes_1_1CMAParameters.html for details.
Usage
cmaes_algos
Value
A character vector of algorithm names.
Examples
cmaes_algos
CMA-ES Control Object
Description
Create a control object for the CMA-ES algorithm. For more information on the parameters, see here: https://cma-es.github.io/libcmaes/doc/html/classlibcmaes_1_1CMAParameters.html.
Usage
cmaes_control(
maximize = FALSE,
algo = "acmaes",
max_fevals = 100,
max_iter = NA_integer_,
ftarget = NA_real_,
f_tolerance = NA_real_,
x_tolerance = NA_real_,
lambda = NA_integer_,
sigma = NA_real_,
max_restarts = NA_integer_,
elitism = NA_integer_,
tpa = NA_integer_,
tpa_dsigma = NA_real_,
seed = NA_integer_,
quiet = TRUE,
x0_lower = NULL,
x0_upper = NULL
)
Arguments
maximize |
( |
algo |
( |
max_fevals |
( |
max_iter |
( |
ftarget |
( |
f_tolerance |
( |
x_tolerance |
( |
lambda |
( |
sigma |
( |
max_restarts |
( |
elitism |
(
NA for default handling by libcmaes. |
tpa |
( |
tpa_dsigma |
( |
seed |
( |
quiet |
( |
x0_lower |
( |
x0_upper |
( |
Value
A cmaes_control S3 object, which is a list with the passed arguments.
Examples
control = cmaes_control(algo = "bipop", max_fevals = 1000, seed = 42)
print(control)