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.

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