cmaes is a lightweight Python library providing an implementation of the Covariance Matrix Adaptation Evolution Strategy (CMA-ES) for numerical optimization. It offers a simple "ask-and-tell" interface and has expanded to include various advanced CMA-ES variants such as CatCMA, CMAwM, and COMO-CatCMAwM, catering to mixed-variable and multi-objective optimization problems. The library is actively maintained, currently at version 0.13.0, with frequent updates introducing new algorithms and features.
pip install cmaesVerified import paths — ran on the pinned version, not inferred.
This example demonstrates the basic "ask-and-tell" interface of the `cmaes` library using the standard `CMA` optimizer to minimize a simple quadratic function. The optimizer generates candidate solutions (`ask`), these are evaluated by the objective function, and then the results (`tell`) are used to update the search distribution for the next generation.
Upgrade Python environment to 3.8 or later. The current recommended version is >=3.9.
Carefully select and import the appropriate optimizer class (e.g., `from cmaes import CatCMAwM`) based on your problem's characteristics (e.g., mixed-variables, multi-objective).
For mixed-variable problems, consider `CatCMAwM`. For multi-objective problems, `COMOCatCMAwM` is available.
Install the library using pip: `pip install cmaes`
Ensure 'mean' is a NumPy array with a single dimension, e.g., `mean=np.array([0.0, 0.0])` or `mean=np.zeros(dimension)`.
Provide 'sigma' as a scalar value, e.g., `sigma=0.5` instead of a list or array.