-
-
Notifications
You must be signed in to change notification settings - Fork 985
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
Add BIPOP-CMA-ES support in CmaEsSampler
#4464
Conversation
@c-bata Could you review this PR? |
This pull request has not seen any recent activity. |
@Alnusjaponica Could you review this PR? |
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.
Sorry for my delayed reply. I made some small suggestions mainly for code comments. If you don't agree with them, please disregard them.
@Alnusjaponica Thanks you for comments. I fixed all points. |
Co-authored-by: Shinichi Hemmi <50256998+Alnusjaponica@users.noreply.github.com>
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## master #4464 +/- ##
=======================================
Coverage 90.89% 90.89%
=======================================
Files 184 184
Lines 13953 14009 +56
=======================================
+ Hits 12682 12733 +51
- Misses 1271 1276 +5
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Co-authored-by: Shinichi Hemmi <50256998+Alnusjaponica@users.noreply.github.com>
This pull request has not seen any recent activity. |
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.
Sorry for the delay in my review. It works fine, but there seems to be room for improvement on how to restore the optimizer. I left one suggestion.
This pull request has not seen any recent activity. |
This pull request has not seen any recent activity. |
CmaEsSampler
.CmaEsSampler
I checked the performance with Rastrigin-2D function, which is the similar settings as c-bata/goptuna#136, and confirmed that BIPOP-CMA-ES works as expected. https://gist.github.com/c-bata/0e739d661e21a5bc4c2ddf2141bf6a9e |
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 update! The update looks great to me.
Just for the record, I confirmed that BIPOP-CMA-ES does not take over the optimization history of IPOP-CMA-ES with the following Python script.
import optuna
from optuna_dashboard import run_server
seed = 1
storage = optuna.storages.InMemoryStorage()
def objective(trial: optuna.Trial) -> float:
x = trial.suggest_float('x', -10, 10)
y = trial.suggest_float('y', -10, 10)
system_attrs = trial.storage.get_trial_system_attrs(trial._trial_id)
for key, value in system_attrs.items():
if "optimizer" in key:
trial.set_user_attr(key, f"{value[:5]}...")
else:
trial.set_user_attr(key, value)
return x ** 2 + y ** 2
if __name__ == '__main__':
study1 = optuna.create_study(sampler=optuna.samplers.RandomSampler(seed=seed), storage=storage, study_name="random-to-bipop")
study1.optimize(objective, n_trials=100)
study1 = optuna.load_study(sampler=optuna.samplers.CmaEsSampler(restart_strategy="bipop", seed=seed), storage=storage, study_name="random-to-bipop")
study1.optimize(objective, n_trials=100)
study2 = optuna.create_study(sampler=optuna.samplers.CmaEsSampler(restart_strategy="ipop", seed=seed), storage=storage, study_name="ipop-to-bipop")
study2.optimize(objective, n_trials=100)
study2 = optuna.load_study(sampler=optuna.samplers.CmaEsSampler(restart_strategy="bipop", seed=seed), storage=storage, study_name="ipop-to-bipop")
study2.optimize(objective, n_trials=100)
for t1, t2 in zip(study1.trials[100:], study2.trials[100:]):
assert t1.params == t2.params and t1.value == t2.value
run_server(storage, port=8080)
Motivation
Current
CmaEsSampler
has IPOP-CMA-ES as the restart strategy.BIPOP-CMA-ES is a kind of extension of IPOP-CMA-ES to improve performance in some problems by adding device about the increment of population size.
I want to consider adding BIPOP-CMA-ES as new option.
Description of the changes
optuna/samplers/_cmaes.py
. Users can use this new feature byoptuna.samplers.CmaEsSampler(restart_strategy="bipop")
sampler_relative
method ofCmaEsSampler
_restore_optimizer
method ofCmaEsSampler
and add code to load counter variable liken_restarts
other place_popsize
to_initial_popsize
because its more adequatetests/sampler_tests/test_cmaes.py