{"id":3927,"library":"cmaes","title":"Lightweight Covariance Matrix Adaptation Evolution Strategy (CMA-ES)","description":"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.","status":"active","version":"0.13.0","language":"en","source_language":"en","source_url":"https://github.com/CyberAgentAILab/cmaes","tags":["optimization","evolutionary algorithms","CMA-ES","black-box optimization","numerical optimization","hyperparameter optimization","mixed-variable optimization","multi-objective optimization"],"install":[{"cmd":"pip install cmaes","lang":"bash","label":"PyPI"},{"cmd":"conda install -c conda-forge cmaes","lang":"bash","label":"Conda-forge"}],"dependencies":[{"reason":"Core numerical operations; sole direct dependency.","package":"numpy"}],"imports":[{"note":"The primary CMA-ES optimizer is directly available from the top-level package.","wrong":"from cmaes.core import CMA","symbol":"CMA","correct":"from cmaes import CMA"},{"note":"For mixed-variable (continuous, integer, categorical) optimization problems.","symbol":"CatCMAwM","correct":"from cmaes import CatCMAwM"},{"note":"For multi-objective mixed-variable optimization problems, typically 2 objectives.","symbol":"COMOCatCMAwM","correct":"from cmaes import COMOCatCMAwM"}],"quickstart":{"code":"import numpy as np\nfrom cmaes import CMA\n\ndef quadratic(x1, x2):\n    # Objective function to minimize\n    return (x1 - 3) ** 2 + (10 * (x2 + 2)) ** 2\n\nif __name__ == \"__main__\":\n    # Initialize CMA optimizer with an initial mean and standard deviation\n    optimizer = CMA(mean=np.zeros(2), sigma=1.3)\n\n    print(\"Starting CMA-ES optimization...\")\n    for generation in range(50):\n        solutions = []\n        # Ask for new candidate solutions\n        for _ in range(optimizer.population_size):\n            x = optimizer.ask()\n            value = quadratic(x[0], x[1])\n            solutions.append((x, value))\n        \n        # Print the best value found in the current generation\n        # (Note: CMA-ES updates distribution based on all solutions, not just the best)\n        print(f\"Generation #{generation+1}: Best value = {min(s[1] for s in solutions):.4f}\")\n        \n        # Tell the optimizer the evaluated solutions and their values\n        optimizer.tell(solutions)\n\n    print(f\"\\nOptimization finished. Final mean of the search distribution: {optimizer.mean}\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade Python environment to 3.8 or later. The current recommended version is >=3.9.","message":"Python 3.6 support was dropped in `v0.9.1`.","severity":"breaking","affected_versions":">=0.9.1"},{"fix":"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).","message":"The library offers numerous specialized optimizers (e.g., `CatCMAwM`, `COMOCatCMAwM`, `CMAwM`) for specific problem types beyond continuous, single-objective optimization.","severity":"gotcha","affected_versions":">=0.9.0"},{"fix":"For mixed-variable problems, consider `CatCMAwM`. For multi-objective problems, `COMOCatCMAwM` is available.","message":"The core `CMA` class is designed for continuous optimization problems. Using it directly for problems involving integer, categorical, or mixed variables, or for multi-objective optimization, may lead to suboptimal performance or incorrect results.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}