Skip to content

Add CMAES optimizer from nevergrad #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ repos:
additional_dependencies:
- hatchling
- ruff
- iminuit
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
Expand Down
1 change: 1 addition & 0 deletions .tools/envs/testenv-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies:
- DFO-LS>=1.5.3 # dev, tests
- Py-BOBYQA # dev, tests
- fides==0.7.4 # dev, tests
- nevergrad # dev, tests
- kaleido # dev, tests
- pandas-stubs # dev, tests
- types-cffi # dev, tests
Expand Down
1 change: 1 addition & 0 deletions .tools/envs/testenv-numpy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
- DFO-LS>=1.5.3 # dev, tests
- Py-BOBYQA # dev, tests
- fides==0.7.4 # dev, tests
- nevergrad # dev, tests
- kaleido # dev, tests
- types-cffi # dev, tests
- types-openpyxl # dev, tests
Expand Down
1 change: 1 addition & 0 deletions .tools/envs/testenv-others.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
- DFO-LS>=1.5.3 # dev, tests
- Py-BOBYQA # dev, tests
- fides==0.7.4 # dev, tests
- nevergrad # dev, tests
- kaleido # dev, tests
- pandas-stubs # dev, tests
- types-cffi # dev, tests
Expand Down
1 change: 1 addition & 0 deletions .tools/envs/testenv-pandas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
- DFO-LS>=1.5.3 # dev, tests
- Py-BOBYQA # dev, tests
- fides==0.7.4 # dev, tests
- nevergrad # dev, tests
- kaleido # dev, tests
- types-cffi # dev, tests
- types-openpyxl # dev, tests
Expand Down
64 changes: 62 additions & 2 deletions docs/source/algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -3984,8 +3984,6 @@ iminuit).
- Values greater than 1 specify the maximum number of restart attempts.
```

(nevergrad-algorithms)=

## Nevergrad Optimizers

optimagic supports some algorithms from the
Expand Down Expand Up @@ -4041,6 +4039,68 @@ these optimizers, you need to have
for speed. Default is False.
- **special_speed_quasi_opp_init** (bool): Whether to use special quasi-opposition
initialization for speed. Default is False.

```

```{eval-rst}
.. dropdown:: nevegrad_cmaes

.. code-block::

"nevergrad_cmaes"

The Covariance Matrix Adaptation Evolution Strategy (CMA-ES) is a stochastic derivative-free numerical optimization algorithm for difficult (non-convex, ill-conditioned, multi-modal, rugged, noisy) optimization problems in continuous search spaces.

The version available through nevergrad wraps an external implementation `pycma <https://github.com/CMA-ES/pycma>`_.

The original method can be found in
:cite:`Hansen2023`.

The fast implementation relies on fcmaes which can be installed with `pip install fcmaes`.

**Optimizer Parameters:**

- **scale** (float): Scale of the search.

- **elitist** (bool): Whether to switch to elitist mode, i.e., `+` mode instead of `,` mode, where the best point in the population is always retained.
- **population_size** (Optional[int]): Population size. Should be

.. math::

\text{population_size} = n \times \text{num_workers} \quad \text{for integer } n \geq 1

Default is

.. math::

\max\left( \text{num_workers},\ 4 + \left\lfloor 3 \cdot \log(\text{dimension}) \right\rfloor \right)

- **popsize_factor** (float): Factor used in the formula for computing the population size.
- Default is `3.0`.

- **diagonal** (bool): Use the diagonal version of CMA, which is advised for high-dimensional problems.

- **high_speed** (bool): Use a metamodel for recommendation to speed up optimization.

- **use_fast_implementation** (bool): Use the fast CMA-ES implementation.
- Cannot be used with `diagonal=True`.
- Produces equivalent results and is preferable for high dimensions or when objective function evaluations are fast.

- **stopping.maxfun** (int): The maximum number of criterion
evaluations.
- **stopping.maxiter** (int): The maximum number of iterations.
- **convergence_ftol_abs** (float): stopping criteria on the f tolerance.
- **convergence_ftol_rel** (float): relative stopping criteria on the f tolerance.
- **convergence_xtol_abs** (float): stopping criteria on the x tolerance.

- **seed** (int): seed used by the internal random number generator.

- **learning_rate_rank_one_update** (float): Multiplier for the rank-one update learning rate of the covariance matrix.
- Default is `1.0`.

- **learning_rate_rank_mu_update** (float): Multiplier for the rank-mu update learning rate of the covariance matrix.
- Default is `1.0`.

```

## References
Expand Down
11 changes: 11 additions & 0 deletions docs/source/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,17 @@ @article{JAMES1975343
author = {F. James and M. Roos}
}


@misc{Hansen2023,
title={The CMA Evolution Strategy: A Tutorial},
author={Nikolaus Hansen},
year={2023},
eprint={1604.00772},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/1604.00772},
}

@InProceedings{Kennedy1995,
author={Kennedy, J. and Eberhart, R.},
booktitle={Proceedings of ICNN'95 - International Conference on Neural Networks},
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
- DFO-LS>=1.5.3 # dev, tests
- Py-BOBYQA # dev, tests
- fides==0.7.4 # dev, tests
- nevergrad # dev, tests
- kaleido # dev, tests
- pre-commit>=4 # dev
- -e . # dev
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies = [
"annotated-types",
"typing-extensions",
"iminuit",
"nevergrad",
]
dynamic = ["version"]
keywords = [
Expand Down Expand Up @@ -350,6 +351,7 @@ module = [
"cyipopt",
"nlopt",
"bokeh",
"nevergrad",
"bokeh.layouts",
"bokeh.models",
"bokeh.plotting",
Expand Down
Loading
Loading