Package cma implements the CMA-ES (Covariance Matrix Adaptation
Evolution Strategy).
CMA-ES is a stochastic optimizer for robust non-linear non-convex derivative- and function-value-free numerical optimization.
This release was tested with Python versions 3.8 to 3.13. The implementation is intended to be compatible with Python >= 2.7.
CMA-ES searches for a minimizer (a solution x in Rn) of an objective function f (cost function), such that f(x) is minimal. Regarding f, only a passably reliable ranking of the candidate solutions in each iteration is necessary. Neither the function values themselves, nor the gradient of f need to be available or do matter, like in the downhill simplex Nelder-Mead algorithm. Some termination criteria however depend on actual Delta f-values.
The cma module provides two independent implementations of the
CMA-ES algorithm in the classes cma.CMAEvolutionStrategy and
cma.purecma.CMAES.
In each implementation two interfaces are provided:
- functions
fmin2andpurecma.fmin: - run a complete minimization of the passed objective function with
CMA-ES.
fmin2also provides optional restarts and noise handling.
- functions
- class
CMAEvolutionStrategy(and the aliasCMA) andpurecma.CMAES: - allow for minimization such that the control of the iteration loop
remains with the user.
fmin2returns an instance ofCMAEvolutionStrategy.
- class
Additionally, fmin_con2 provides constrained optimization.
For a quick start see below or confer to the notebook(s) https://github.com/CMA-ES/pycma/blob/development/notebooks/notebook-usecases-basics.ipynb
CMAEvolutionStrategy relies, in contrast to cma.purecma, heavily on
numpy and optionally on matplotlib.pyplot (for plot etc., optional
but highly recommended).
The source code is available at https://github.com/CMA-ES/pycma.
Testing
From the system shell:
python -m cma.test -h python -m cma.test python -c "import cma.test; cma.test.main()" # the same
or from any (i)python shell:
import cma.test cma.test.main()
should run without complaints in about between 20 and 100 seconds.
Example
From a python shell:
import cma
help(cma) # "this" help message, use cma? in ipython
help(cma.fmin)
help(cma.CMAEvolutionStrategy)
help(cma.CMAOptions)
cma.CMAOptions('tol') # display 'tolerance' termination options
cma.CMAOptions('verb') # display verbosity options
x, es = cma.fmin2(cma.ff.tablet, 15 * [1], 1)
es = cma.CMAEvolutionStrategy(15 * [1], 1).optimize(cma.ff.tablet)
help(es.result)
x, es.result[0] # best evaluated solution
es.result[5] # mean solution, presumably better with noise
| Authors | |
| Nikolaus Hansen, 2008- | |
| Petr Baudis, 2014 | |
| Youhei Akimoto, 2017- | |
| See Also | |
fmin (), CMAOptions, CMAEvolutionStrategy | |
| Unknown Field: license | |
| BSD 3-Clause, see LICENSE file. |
| Module | bbobbenchmarks |
BBOB noiseless testbed. |
| Module | boundary |
A collection of variable boundaries (AKA box constraints) handling classes. |
| Module | constraints |
A collection of (nonlinear) constraints handling classes and helper functions. |
| Module | evolution |
CMA-ES (evolution strategy), the main sub-module of cma implementing in particular CMAEvolutionStrategy, fmin2 and further fmin_* functions. |
| Module | fitness |
versatile container for test objective functions. |
| Module | fitness |
Fitness surrogate model classes and handler for incremental evaluations. |
| Module | fitness |
Wrapper for objective functions like noise, rotation, gluing args |
| Module | integer |
Integer handling class IntegerCentering to be used in combination with CMA-ES. |
| Module | interfaces |
Very few interface defining base class definitions |
| Module | logger |
logger class mainly to be used with CMAEvolutionStrategy |
| Module | optimization |
Utility classes and functionalities loosely related to optimization |
| Module | options |
Parameters and Options for CMA-ES. |
| Module | purecma |
A minimalistic implemention of CMA-ES without using numpy. |
| Module | recombination |
RecombinationWeights is a list of recombination weights for the CMA-ES. |
| Module | restricted |
VD-CMA and VkD-CMA |
| Module | s |
versatile shortcuts for quick typing in an (i)python shell or even from cma.s import * in interactive sessions. |
| Module | sampler |
Collection of classes that sample from parametrized distributions and provide an update mechanism of the distribution parameters. |
| Module | sigma |
step-size adaptation classes, currently tightly linked to CMA, because hsig is computed in the base class |
| Module | test |
test module of cma package. |
| Module | transformations |
Search space transformation and encoding/decoding classes |
| Package | utilities |
various unspecific utilities |
| Module | wrapper |
Interface wrappers for the cma module. |
From __init__.py:
| Variable | __ |
Undocumented |
| Variable | __license__ |
Undocumented |
| Variable | __version__ |
Undocumented |
| Variable | version |
Undocumented |