Name | cma JSON |
Version |
4.3.0
JSON |
| download |
home_page | None |
Summary | CMA-ES, Covariance Matrix Adaptation Evolution Strategy for non-linear numerical optimization in Python |
upload_time | 2025-07-24 11:32:18 |
maintainer | None |
docs_url | None |
author | Youhei Akimoto, Petr Baudis |
requires_python | None |
license | None |
keywords |
optimization
cma-es
cmaes
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
CMA-ES Covariance Matrix Adaptation Evolution Strategy
======================================================
A stochastic numerical optimization algorithm for difficult (non-convex,
ill-conditioned, multi-modal, rugged, noisy) optimization problems in
continuous search spaces, implemented in Python.
Typical domain of application are unconstrained or bound-constrained
objective functions with:
* search space dimension between, say, 5 and (a few) 100,
* no gradients available,
* at least, say, 100 times dimension function evaluations needed to
get satisfactory solutions,
* non-separable, ill-conditioned, or rugged/multi-modal landscapes.
More recently nonlinear constraints handling is available too.
The CMA-ES is quite reliable, however for small budgets (fewer function
evaluations than, say, 100 times dimension) or in very small dimensions
faster methods are available.
The ``pycma`` module provides two independent implementations of the
CMA-ES algorithm in the classes ``cma.CMAEvolutionStrategy`` and
``cma.purecma.CMAES``.
Installation
------------
In the terminal command line type::
python -m pip install cma
The package will be downloaded and installed automatically. To **upgrade**
an existing installation, '``pip``' must be replaced by '``pip -U``'. For
the documentation of ``pip``, `see here`_.
.. _`see here`: http://www.pip-installer.org
Alternatively, download and unpack the ``cma-...tar.gz``. The folder
``cma`` from the ``tar`` archive can used without any installation
(for ``import`` to find it, it must be in the current folder or the Python
search paths) or can be installed by ``pip install -e .``.
Usage Example
-------------
In a Python shell::
>>> import cma
>>> help(cma)
<output omitted>
>>> es = cma.CMAEvolutionStrategy(8 * [0], 0.5)
(5_w,10)-aCMA-ES (mu_w=3.2,w_1=45%) in dimension 8 (seed=468976, Tue May 6 19:14:06 2014)
>>> help(es) # the same as help(cma.CMAEvolutionStrategy)
<output omitted>
>>> es.optimize(cma.ff.rosen)
Iterat #Fevals function value axis ratio sigma minstd maxstd min:sec
1 10 1.042661803766204e+02 1.0e+00 4.50e-01 4e-01 5e-01 0:0.0
2 20 7.322331708590002e+01 1.2e+00 3.89e-01 4e-01 4e-01 0:0.0
3 30 6.048150359372417e+01 1.2e+00 3.47e-01 3e-01 3e-01 0:0.0
100 1000 3.165939452385367e+00 1.1e+01 7.08e-02 2e-02 7e-02 0:0.2
200 2000 4.157333035296804e-01 1.9e+01 8.10e-02 9e-03 5e-02 0:0.4
300 3000 2.413696640005903e-04 4.3e+01 9.57e-03 3e-04 7e-03 0:0.5
400 4000 1.271582136805314e-11 7.6e+01 9.70e-06 8e-08 3e-06 0:0.7
439 4390 1.062554035878040e-14 9.4e+01 5.31e-07 3e-09 8e-08 0:0.8
>>> es.result_pretty() # pretty print result
termination on tolfun=1e-11
final/bestever f-value = 3.729752e-15 3.729752e-15
mean solution: [ 1. 1. 1. 1. 0.99999999 0.99999998
0.99999995 0.99999991]
std deviation: [ 2.84303359e-09 2.74700402e-09 3.28154576e-09 5.92961588e-09
1.07700123e-08 2.12590385e-08 4.09374304e-08 8.16649754e-08]
optimizes the 8-dimensional Rosenbrock function with initial solution all
zeros and initial ``sigma = 0.5``.
Pretty much the same can be achieved a little less "elaborate" with::
>>> import cma
>>> xopt, es = cma.fmin2(cma.ff.rosen, 8 * [0], 0.5)
<output omitted>
And a little more elaborate exposing the **ask-and-tell interface**::
>>> import cma
>>> es = cma.CMAEvolutionStrategy(12 * [0], 0.5)
>>> while not es.stop():
... solutions = es.ask()
... es.tell(solutions, [cma.ff.rosen(x) for x in solutions])
... es.logger.add() # write data to disc to be plotted
... es.disp()
<output omitted>
>>> es.result_pretty()
<output omitted>
>>> cma.plot() # shortcut for es.logger.plot()
.. figure:: http://www.cmap.polytechnique.fr/~nikolaus.hansen/rosen12.png
:alt: CMA-ES on Rosenbrock function in dimension 8
:target: https://cma-es.github.io/cmaes_sourcecode_page.html#example
:align: center
A single run on the 12-dimensional Rosenbrock function.
The ``CMAOptions`` class manages options for ``CMAEvolutionStrategy``,
e.g. verbosity options can be found like::
>>> import cma
>>> cma.s.pprint(cma.CMAOptions('erb'))
{'verb_log': '1 #v verbosity: write data to files every verb_log iteration, writing can be time critical on fast to evaluate functions'
'verbose': '1 #v verbosity e.v. of initial/final message, -1 is very quiet, not yet implemented'
'verb_plot': '0 #v in fmin(): plot() is called every verb_plot iteration'
'verb_disp': '100 #v verbosity: display console output every verb_disp iteration'
'verb_filenameprefix': 'outcmaes # output filenames prefix'
'verb_append': '0 # initial evaluation counter, if append, do not overwrite output files'
'verb_time': 'True #v output timings on console'}
Options are passed like::
>>> import cma
>>> es = cma.CMAEvolutionStrategy(8 * [0], 0.5,
{'verb_disp': 1}) # display each iteration
Documentations
--------------
The full package API documentation:
* `version 3+`_ (recent)
* `version 1.x`_
.. _`version 3+`: https://cma-es.github.io/apidocs-pycma/
.. _`version 1.x`: http://www.cmap.polytechnique.fr/~nikolaus.hansen/html-pythoncma/
See also
* `Github page hosting this code`_ and its `FAQ`_ (under development)
* `General CMA-ES source code page`_ with practical hints
* `CMA-ES on Wikipedia`_
.. _`Github page hosting this code`: https://github.com/CMA-ES/pycma
.. _`FAQ`: https://github.com/CMA-ES/pycma/issues?q=is:issue+label:FAQ
.. _`General CMA-ES source code page`: https://cma-es.github.io/cmaes_sourcecode_page.html
.. _`CMA-ES on Wikipedia`: http://en.wikipedia.org/wiki/CMA-ES
Dependencies
------------
* required (unless for `cma.purecma`): ``numpy`` -- array processing for numbers, strings, records, and objects
* optional (highly recommended): ``matplotlib`` -- Python plotting package (includes ``pylab``)
Use ``pip install numpy`` etc. for installation. The `cma.purecma` submodule can be used without any dependencies installed.
License: BSD-3-Clause
Raw data
{
"_id": null,
"home_page": null,
"name": "cma",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": "Nikolaus Hansen <authors_firstname.lastname@inria.fr>",
"keywords": "optimization, CMA-ES, cmaes",
"author": "Youhei Akimoto, Petr Baudis",
"author_email": "Nikolaus Hansen <authors_firstname.lastname@inria.fr>",
"download_url": "https://files.pythonhosted.org/packages/ca/fe/bd65ec131f5679900c5e874ef60d088849e299c0dba6d98cce69e56b2d98/cma-4.3.0.tar.gz",
"platform": null,
"description": "CMA-ES Covariance Matrix Adaptation Evolution Strategy\n======================================================\n\nA stochastic numerical optimization algorithm for difficult (non-convex,\nill-conditioned, multi-modal, rugged, noisy) optimization problems in\ncontinuous search spaces, implemented in Python.\n\nTypical domain of application are unconstrained or bound-constrained\nobjective functions with:\n\n* search space dimension between, say, 5 and (a few) 100,\n* no gradients available,\n* at least, say, 100 times dimension function evaluations needed to\n get satisfactory solutions,\n* non-separable, ill-conditioned, or rugged/multi-modal landscapes.\n\nMore recently nonlinear constraints handling is available too.\nThe CMA-ES is quite reliable, however for small budgets (fewer function\nevaluations than, say, 100 times dimension) or in very small dimensions\nfaster methods are available.\n\nThe ``pycma`` module provides two independent implementations of the \nCMA-ES algorithm in the classes ``cma.CMAEvolutionStrategy`` and \n``cma.purecma.CMAES``. \n\nInstallation\n------------\nIn the terminal command line type::\n\n python -m pip install cma\n\nThe package will be downloaded and installed automatically. To **upgrade**\nan existing installation, '``pip``' must be replaced by '``pip -U``'. For\nthe documentation of ``pip``, `see here`_.\n\n.. _`see here`: http://www.pip-installer.org\n\nAlternatively, download and unpack the ``cma-...tar.gz``. The folder\n``cma`` from the ``tar`` archive can used without any installation\n(for ``import`` to find it, it must be in the current folder or the Python\nsearch paths) or can be installed by ``pip install -e .``.\n\nUsage Example\n-------------\nIn a Python shell::\n\n >>> import cma\n >>> help(cma)\n <output omitted>\n >>> es = cma.CMAEvolutionStrategy(8 * [0], 0.5)\n (5_w,10)-aCMA-ES (mu_w=3.2,w_1=45%) in dimension 8 (seed=468976, Tue May 6 19:14:06 2014)\n >>> help(es) # the same as help(cma.CMAEvolutionStrategy)\n <output omitted>\n >>> es.optimize(cma.ff.rosen)\n Iterat #Fevals function value axis ratio sigma minstd maxstd min:sec\n 1 10 1.042661803766204e+02 1.0e+00 4.50e-01 4e-01 5e-01 0:0.0\n 2 20 7.322331708590002e+01 1.2e+00 3.89e-01 4e-01 4e-01 0:0.0\n 3 30 6.048150359372417e+01 1.2e+00 3.47e-01 3e-01 3e-01 0:0.0\n 100 1000 3.165939452385367e+00 1.1e+01 7.08e-02 2e-02 7e-02 0:0.2\n 200 2000 4.157333035296804e-01 1.9e+01 8.10e-02 9e-03 5e-02 0:0.4\n 300 3000 2.413696640005903e-04 4.3e+01 9.57e-03 3e-04 7e-03 0:0.5\n 400 4000 1.271582136805314e-11 7.6e+01 9.70e-06 8e-08 3e-06 0:0.7\n 439 4390 1.062554035878040e-14 9.4e+01 5.31e-07 3e-09 8e-08 0:0.8\n >>> es.result_pretty() # pretty print result\n termination on tolfun=1e-11\n final/bestever f-value = 3.729752e-15 3.729752e-15\n mean solution: [ 1. 1. 1. 1. 0.99999999 0.99999998\n 0.99999995 0.99999991]\n std deviation: [ 2.84303359e-09 2.74700402e-09 3.28154576e-09 5.92961588e-09\n 1.07700123e-08 2.12590385e-08 4.09374304e-08 8.16649754e-08]\n\noptimizes the 8-dimensional Rosenbrock function with initial solution all\nzeros and initial ``sigma = 0.5``.\n\nPretty much the same can be achieved a little less \"elaborate\" with::\n\n >>> import cma\n >>> xopt, es = cma.fmin2(cma.ff.rosen, 8 * [0], 0.5)\n <output omitted>\n\nAnd a little more elaborate exposing the **ask-and-tell interface**::\n\n >>> import cma\n >>> es = cma.CMAEvolutionStrategy(12 * [0], 0.5)\n >>> while not es.stop():\n ... solutions = es.ask()\n ... es.tell(solutions, [cma.ff.rosen(x) for x in solutions])\n ... es.logger.add() # write data to disc to be plotted\n ... es.disp()\n <output omitted>\n >>> es.result_pretty()\n <output omitted>\n >>> cma.plot() # shortcut for es.logger.plot()\n\n.. figure:: http://www.cmap.polytechnique.fr/~nikolaus.hansen/rosen12.png\n :alt: CMA-ES on Rosenbrock function in dimension 8\n :target: https://cma-es.github.io/cmaes_sourcecode_page.html#example\n :align: center \n \n A single run on the 12-dimensional Rosenbrock function. \n\n\nThe ``CMAOptions`` class manages options for ``CMAEvolutionStrategy``,\ne.g. verbosity options can be found like::\n\n >>> import cma\n >>> cma.s.pprint(cma.CMAOptions('erb'))\n {'verb_log': '1 #v verbosity: write data to files every verb_log iteration, writing can be time critical on fast to evaluate functions'\n 'verbose': '1 #v verbosity e.v. of initial/final message, -1 is very quiet, not yet implemented'\n 'verb_plot': '0 #v in fmin(): plot() is called every verb_plot iteration'\n 'verb_disp': '100 #v verbosity: display console output every verb_disp iteration'\n 'verb_filenameprefix': 'outcmaes # output filenames prefix'\n 'verb_append': '0 # initial evaluation counter, if append, do not overwrite output files'\n 'verb_time': 'True #v output timings on console'}\n\nOptions are passed like::\n\n >>> import cma\n >>> es = cma.CMAEvolutionStrategy(8 * [0], 0.5,\n {'verb_disp': 1}) # display each iteration\n\n\nDocumentations\n--------------\nThe full package API documentation:\n\n* `version 3+`_ (recent)\n* `version 1.x`_\n\n.. _`version 3+`: https://cma-es.github.io/apidocs-pycma/\n.. _`version 1.x`: http://www.cmap.polytechnique.fr/~nikolaus.hansen/html-pythoncma/\n\nSee also\n\n* `Github page hosting this code`_ and its `FAQ`_ (under development)\n* `General CMA-ES source code page`_ with practical hints\n* `CMA-ES on Wikipedia`_\n\n.. _`Github page hosting this code`: https://github.com/CMA-ES/pycma\n.. _`FAQ`: https://github.com/CMA-ES/pycma/issues?q=is:issue+label:FAQ\n.. _`General CMA-ES source code page`: https://cma-es.github.io/cmaes_sourcecode_page.html\n.. _`CMA-ES on Wikipedia`: http://en.wikipedia.org/wiki/CMA-ES\n\nDependencies\n------------\n\n* required (unless for `cma.purecma`): ``numpy`` -- array processing for numbers, strings, records, and objects\n* optional (highly recommended): ``matplotlib`` -- Python plotting package (includes ``pylab``)\n\nUse ``pip install numpy`` etc. for installation. The `cma.purecma` submodule can be used without any dependencies installed.\n\nLicense: BSD-3-Clause\n",
"bugtrack_url": null,
"license": null,
"summary": "CMA-ES, Covariance Matrix Adaptation Evolution Strategy for non-linear numerical optimization in Python",
"version": "4.3.0",
"project_urls": {
"Bug Tracker": "https://github.com/CMA-ES/pycma/issues",
"Homepage": "https://github.com/CMA-ES/pycma",
"Repository": "https://github.com/CMA-ES/pycma.git"
},
"split_keywords": [
"optimization",
" cma-es",
" cmaes"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3299351d5a95a481068d83e1f1967b9d00237e70519fc6d4d5e9e390b94e5714",
"md5": "8fdca6c4c842e15e6e72e75b8ceca794",
"sha256": "65ad8799e6438b8b82c82c11aad070727e5887915ea6f2c17d7ca0eea940c57a"
},
"downloads": -1,
"filename": "cma-4.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8fdca6c4c842e15e6e72e75b8ceca794",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 295869,
"upload_time": "2025-07-24T11:32:13",
"upload_time_iso_8601": "2025-07-24T11:32:13.722874Z",
"url": "https://files.pythonhosted.org/packages/32/99/351d5a95a481068d83e1f1967b9d00237e70519fc6d4d5e9e390b94e5714/cma-4.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cafebd65ec131f5679900c5e874ef60d088849e299c0dba6d98cce69e56b2d98",
"md5": "6ec76f541915ca9d78886cd483941341",
"sha256": "faa8933e9d55e199c052dd114d123d8d9a3ca914d932629e8b6e77200681a206"
},
"downloads": -1,
"filename": "cma-4.3.0.tar.gz",
"has_sig": false,
"md5_digest": "6ec76f541915ca9d78886cd483941341",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 284531,
"upload_time": "2025-07-24T11:32:18",
"upload_time_iso_8601": "2025-07-24T11:32:18.261694Z",
"url": "https://files.pythonhosted.org/packages/ca/fe/bd65ec131f5679900c5e874ef60d088849e299c0dba6d98cce69e56b2d98/cma-4.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-24 11:32:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "CMA-ES",
"github_project": "pycma",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"circle": true,
"appveyor": true,
"lcname": "cma"
}