Cmaes

Latest version: v0.11.1

Safety actively analyzes 701264 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 4

2405.09962

CatCMA is a method for mixed-category optimization problems, which is the problem of simultaneously optimizing continuous and categorical variables. CatCMA employs the joint probability distribution of multivariate Gaussian and categorical distributions as the search distribution.

![CatCMA](https://github.com/CyberAgentAILab/cmaes/assets/27720055/f91443b6-d71b-4849-bfc3-095864f7c58c)

Usage is like below:

python
import numpy as np
from cmaes import CatCMA


def sphere_com(x, c):
dim_co = len(x)
dim_ca = len(c)
if dim_co < 2:
raise ValueError("dimension must be greater one")
sphere = sum(x * x)
com = dim_ca - sum(c[:, 0])
return sphere + com


def rosenbrock_clo(x, c):
dim_co = len(x)
dim_ca = len(c)
if dim_co < 2:
raise ValueError("dimension must be greater one")
rosenbrock = sum(100 * (x[:-1] ** 2 - x[1:]) ** 2 + (x[:-1] - 1) ** 2)
clo = dim_ca - (c[:, 0].argmin() + c[:, 0].prod() * dim_ca)
return rosenbrock + clo


def mc_proximity(x, c, cat_num):
dim_co = len(x)
dim_ca = len(c)
if dim_co < 2:
raise ValueError("dimension must be greater one")
if dim_co != dim_ca:
raise ValueError(
"number of dimensions of continuous and categorical variables "
"must be equal in mc_proximity"
)

c_index = np.argmax(c, axis=1) / cat_num
return sum((x - c_index) ** 2) + sum(c_index)


if __name__ == "__main__":
cont_dim = 5
cat_dim = 5
cat_num = np.array([3, 4, 5, 5, 5])
cat_num = 3 * np.ones(cat_dim, dtype=np.int64)
optimizer = CatCMA(mean=3.0 * np.ones(cont_dim), sigma=1.0, cat_num=cat_num)

for generation in range(200):
solutions = []
for _ in range(optimizer.population_size):
x, c = optimizer.ask()
value = mc_proximity(x, c, cat_num)
if generation % 10 == 0:
print(f"{generation} {value}")
solutions.append(((x, c), value))
optimizer.tell(solutions)

if optimizer.should_stop():
break


What's Changed
* Add support for Python 3.12 by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/153
* Remove `setup.py` and use build module by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/154
* Fix CI failures by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/158
* get mean by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/159
* add question template by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/162
* fix sigma setting by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/160
* Add GitHub action setting for continuous benchmark by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/168
* fix typo by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/169
* fix BIPOP-CMA in visualization by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/170
* update readme by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/171
* update by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/172
* fix the old_sigma assertion when lr_adapt=True by Kreyparion in https://github.com/CyberAgentAILab/cmaes/pull/174
* remove kurobako dependency by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/175
* Support for numpy v2.0 by porink0424 in https://github.com/CyberAgentAILab/cmaes/pull/177
* catcma (GECCO2024) by ha-mano in https://github.com/CyberAgentAILab/cmaes/pull/178
* fix CatCMA by ha-mano in https://github.com/CyberAgentAILab/cmaes/pull/179
* Update README.md by ha-mano in https://github.com/CyberAgentAILab/cmaes/pull/181
* Bump the version up to `v0.11.0` by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/183

New Contributors
* Kreyparion made their first contribution in https://github.com/CyberAgentAILab/cmaes/pull/174
* porink0424 made their first contribution in https://github.com/CyberAgentAILab/cmaes/pull/177
* ha-mano made their first contribution in https://github.com/CyberAgentAILab/cmaes/pull/178

**Full Changelog**: https://github.com/CyberAgentAILab/cmaes/compare/v0.10.0...v0.11.0

2205.13482

> |CMA-ES|CMA-ESwM|
> |---|---|
> |![CMA-ES](https://raw.githubusercontent.com/EvoConJP/CMA-ES_with_Margin/main/fig/CMA-ES.gif)|![CMA-ESwM](https://raw.githubusercontent.com/EvoConJP/CMA-ES_with_Margin/main/fig/CMA-ESwM.gif)|
>
> The above figures are taken from [EvoConJP/CMA-ES_with_Margin](https://github.com/EvoConJP/CMA-ES_with_Margin).

Please check out the following examples for the usage.

* [cmaes_with_margin_binary.py](https://github.com/CyberAgentAILab/cmaes/blob/main/examples/cmaes_with_margin_binary.py)
* [cmaes_with_margin_integer.py](https://github.com/CyberAgentAILab/cmaes/blob/main/examples/cmaes_with_margin_integer.py)


What's Changed

* Running benchmark of Warm Starting CMA-ES on GitHub Actions. by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/99
* Validate bounds domain contains mean by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/100
* Fix overflow errors uncovered by Coverage-guided Fuzzing. by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/104
* Fuzzing for sep-CMA-ES by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/105
* Set license_file on setup.cfg by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/106
* fix sep-CMA description by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/107
* Temporarily disable a GitHub action for kurobako benchmarks by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/113
* Fix mutable by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/112
* Run tests with Python 3.10 by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/109
* Update author and maintainer package info. by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/116
* Introduce some related projects on README by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/118
* Migrate the project metadata to pyproject.toml by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/119
* Revert 119 to support Python 3.6. by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/122
* Support CMA-ES with Margin. by knshnb in https://github.com/CyberAgentAILab/cmaes/pull/121
* Add integer examples for CMA-ES with Margin by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/125
* Support Python 3.11 by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/123
* Add README of CMA-ES with margin by knshnb in https://github.com/CyberAgentAILab/cmaes/pull/124
* Follow-up 126: Remove Scipy dependency by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/127
* Remove SciPy dependency by amylase in https://github.com/CyberAgentAILab/cmaes/pull/126
* Use gh instead of ghr by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/128
* Bump the version up to v0.9.0 by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/129

New Contributors
* knshnb made their first contribution in https://github.com/CyberAgentAILab/cmaes/pull/121
* amylase made their first contribution in https://github.com/CyberAgentAILab/cmaes/pull/126

References



**Full Changelog**: https://github.com/CyberAgentAILab/cmaes/compare/v0.8.2...v0.9.0

0.11.1

0.11.0

Highlights

`CatCMA` [Hamano+, GECCO2024]

0.10.0

What's Changed
* add DX-NES-IC by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/149
* xNES implementation by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/150
* add LRA-CMA-ES by nomuramasahir0 in https://github.com/CyberAgentAILab/cmaes/pull/151
* Bump the version up to v0.10.0 by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/152

**Full Changelog**: https://github.com/CyberAgentAILab/cmaes/compare/v0.9.1...v0.10.0

* PyPI: https://github.com/CyberAgentAILab/cmaes/blob/main/.github/workflows/pypi-publish.yml

0.9.1

What's Changed
* Remove `tox.ini` by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/131
* Fix a broken link to Optuna's documentation by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/132
* Drop Python 3.6 support. by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/130
* Reuse `CMA` inside `CMAwM` by knshnb in https://github.com/CyberAgentAILab/cmaes/pull/133
* Add rng related methods by knshnb in https://github.com/CyberAgentAILab/cmaes/pull/135
* Fix correction of out-of-range continuous params of `CMAwM` by knshnb in https://github.com/CyberAgentAILab/cmaes/pull/134
* Fix correction of out-of-range discrete params of `CMAwM` by knshnb in https://github.com/CyberAgentAILab/cmaes/pull/136
* Avoid to use `typing.List`, `typing.Dict`, and `typing.Tuple`. by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/139
* Check feasibility of sampled discrete parameters in `CMAwM` by knshnb in https://github.com/CyberAgentAILab/cmaes/pull/140
* Refactor `CMAwM` by knshnb in https://github.com/CyberAgentAILab/cmaes/pull/141
* Add a test case for no discrete spaces. by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/143
* Allow no discrete spaces in `CMAwM` by knshnb in https://github.com/CyberAgentAILab/cmaes/pull/142
* Remove warnings in CMAwM class by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/144
* Revert handling of infeasible discrete parameters by knshnb in https://github.com/CyberAgentAILab/cmaes/pull/145
* Bump the version up to v0.9.1 by c-bata in https://github.com/CyberAgentAILab/cmaes/pull/138


**Full Changelog**: https://github.com/CyberAgentAILab/cmaes/compare/v0.9.0...v0.9.1

Page 1 of 4

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.