-
Notifications
You must be signed in to change notification settings - Fork 74
Safe CMA-ES (GECCO 2024) #187
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
Conversation
|
@c-bata |
| and Noisy Problems?, GECCO, 2023.](https://arxiv.org/abs/2304.03473) | ||
| * [Nomura and Shibata 2024] [M. Nomura, M. Shibata, cmaes : A Simple yet Practical Python Library for CMA-ES, arXiv:2402.01373, 2024.](https://arxiv.org/abs/2402.01373) | ||
| * [Ros and Hansen 2008] [R. Ros, N. Hansen, A Simple Modification in CMA-ES Achieving Linear Time and Space Complexity, PPSN, 2008.](https://hal.inria.fr/inria-00287367/document) | ||
| * [Uchida et al. 2024] [K. Uchida, R. Hamano, M. Nomura, S. Saito, S. Shirakawa, CMA-ES for Safe Optimization, GECCO, 2024.](https://arxiv.org/abs/2405.10534) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you provide a brief description and usage for SafeCMA (like LRA-CMA-ES)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be clearer to explicitly state that the current implementation assumes no noise.
| cov: | ||
| A covariance matrix (optional). | ||
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the paper link like this.
cmaes/_safe_cma.py
Outdated
| assert c1 <= 1 - cmu, "invalid learning rate for the rank-one update" | ||
| assert cmu <= 1 - c1, "invalid learning rate for the rank-μ update" | ||
|
|
||
| cm = 1 # (eq. 54) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest removing comments like eq. ~ (for Hansen's Tutorial paper) in this PR, as they could be confusing when compared with the equations in the SafeCMA paper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, adding equation numbers for SafeCMA-specific operations would improve clarity.
| likelihood = gpytorch.likelihoods.GaussianLikelihood( | ||
| noise_constraint=gpytorch.constraints.GreaterThan(0) | ||
| ) | ||
| likelihood.noise = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about the validity of this setting because, as mentioned in this thread:
Some small value, but don't make it too small or numerical performance will suffer. I recommend 1e-4.
cornellius-gp/gpytorch#1196 (comment)
This implies there's room for improvement in this setting, but I'm not sure for now, so let's see how it goes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This setting was used in some previous studies, including the followings.
https://link.springer.com/chapter/10.1007/978-3-030-58112-1_13
https://dl.acm.org/doi/10.1007/978-3-031-30229-9_51
In addition, I run the safe CMA-ES with likelihood.noise = 1e-4 on some benchmark functions. As a result, it occurred a few constraint violations that was not observed with likelihood.noise = 0. Therefore, I did not change it.
| if out_scalar: | ||
| grad_norm = grad_norm.mean().to(torch.float64) | ||
|
|
||
| return -grad_norm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
df is defined as # function that returns the norm of gradient, but it currently returns a negative value, which seems odd.
I understand this is intended for scipy.optimize.minimize, but it would be better to align it with the description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the explanation of the function as # function that returns the negative norm of gradient.
cmaes/_safe_cma.py
Outdated
| safe_seeds = (np.random.rand(safe_seeds_num, dim) * 2 - 1) * 5 | ||
| safe_seeds[:, 0] = - np.abs(safe_seeds[:, 0]) | ||
| # evaluation of safe seeds (with multiple safety functions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with multiple safety functions
with a single safety function?
examples/safecma.py
Outdated
| safe_seeds = (np.random.rand(safe_seeds_num, dim) * 2 - 1) * 5 | ||
| safe_seeds[:, 0] = -np.abs(safe_seeds[:, 0]) | ||
|
|
||
| # evaluation of safe seeds (with multiple safety functions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with multiple safety functions
with a single safety function?
|
@kento031 |
cmaes/__init__.py
Outdated
| try: | ||
| from ._safe_cma import SafeCMA # NOQA | ||
| except ImportError: | ||
| pass # Implementation of Safe CMA-ES requires scipy, gpytorch, and torch | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the current approach is somewhat tricky, as users may be confused if cmaes.SafeCMA doesn’t exist in certain Python environments.
How about simply removing SafeCMA from __init__.py and renaming cmaes/_safe_cma.py to cmaes/safe_cma.py?
| try: | |
| from ._safe_cma import SafeCMA # NOQA | |
| except ImportError: | |
| pass # Implementation of Safe CMA-ES requires scipy, gpytorch, and torch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the great suggestion! It looks good to me.
@kento031
Could you make this modification if it’s okay?
|
@nomuramasahir0 @c-bata |
bea9914 to
f5e178a
Compare
|
Sorry for being so late in addressing your comments. I checked the code using @nomuramasahir0 We previously discussed about whether |
|
@kento031 |
|
@ha-mano |
c-bata
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the update. LGTM with a nit.
Co-authored-by: c-bata <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after CI passes. Thank you for your contribution 💯
|
Thank you for all your comments! In the CI check, the Should I modify these codes to resolve the errors? |
|
@kento031 No, you don't need to fix that errors in this PR 👍 |
This is the implementation of Safe CMA-ES [Uchida+, GECCO 2024].
https://arxiv.org/abs/2405.10534