question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

trial.suggest_int uses RandomSampler instead of CmaEsSampler

See original GitHub issue

All my parameters are using trial.suggest_int. Tried optuna.samplers.CmaEsSampler but performance really bad. Many parameters used RandomSampler and objective score, R2 was very low and seemed static, R2 = 0.30 Tried optuna.integration.CmaEsSampler and performance was slightly better, R2 = 0.58 - 0.60 but also many parameters was sampled using RandomSampler. The same study using TPESampler gives R2 = 0.749, no problems.

Some representative codes:

def objective (trial): params_list =[] n_params = trial.suggest_int(‘n_params’, 3, 5) param1 = trial.suggest_int(‘param1’, 0, 1200) param2 = trial.suggest_int(‘param2’, 0, 1199) params_list.append(param1) params_list.append(param2) if n_params >=3: param3 = trial.suggest_int(‘param3’, 0, 1198) params_list.append(param3) if n_params >=4: param4 = trial.suggest_int(‘param4’, 0, 1197) params_list.append(param4) if n_params >=5: param5 = trial.suggest_int(‘param5’, 0, 1196) params_list.append(param5) model = model(params_list) score = model.evaluate(x_test, y_test) # R2 score return score

study = optuna.create_study(direction=‘maximize’, sampler=optuna.samplers.CmaEsSampler) study.optimize(objective, n_trials=10000, n_jobs=-1)

I have noticed that RandomSampler is always used on params 3, 4, 5 i.e. those that were in the conditional if statements.

I expect performance to be comparable to TPESampler and sampling is done using the CmaEsSampler.

Environment

  • Optuna version: 2.0
  • Python version: 3.7
  • OS: win10 64-bit
  • (Optional) Other libraries and their versions:

Error messages, stack traces, or logs

# error messages, stack traces, or logs
Example error messages:
[W 2020-07-29 20:58:44,714] The parameter 'param3' in trial#9993 is sampled independently by using `RandomSampler` instead of `CmaEsSampler` (optimization performance may be degraded). You can suppress this warning by setting `warn_independent_sampling` to `False` in the constructor of `CmaEsSampler`, if this independent sampling is intended behavior.
[W 2020-07-29 20:58:44,714] The parameter 'param4' in trial#9994 is sampled independently by using `RandomSampler` instead of `CmaEsSampler` (optimization performance may be degraded). You can suppress this warning by setting `warn_independent_sampling` to `False` in the constructor of `CmaEsSampler`, if this independent sampling is intended behavior.
[W 2020-07-29 20:58:44,714] The parameter 'param5' in trial#9996 is sampled independently by using `RandomSampler` instead of `CmaEsSampler` (optimization performance may be degraded). You can suppress this warning by setting `warn_independent_sampling` to `False` in the constructor of `CmaEsSampler`, if this independent sampling is intended behavior.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:24 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
koh-joshuacommented, Aug 1, 2020

Thank you. I am trying PyCmaSampler…it is slow…very slow…but seems to be working…will update later. I wanted to compare a Bayesian based sampler (TPE) to evolution based sampler (CMA-ES, PSO or GA). I think your cma-es implementation is the best, because it is fast. Fingers crossed the bug will be flushed out. Thanks!

2reactions
koh-joshuacommented, Jul 30, 2020

Thank you for your super quick response and explanation. You guys are totally amazing! Perhaps I can shout the Optuna team some beer and sake in the future when I drop by Tokyo. Thank!

Read more comments on GitHub >

github_iconTop Results From Across the Web

optuna.samplers.CmaEsSampler - Read the Docs
n_startup_trials – The independent sampling is used instead of the CMA-ES algorithm until the given number of trials finish in the same study....
Read more >
optuna/optuna - Gitter
The CmaEsSampler and the TPESampler both internally use the RandomSampler for the first “startup” trials. You could maybe take a look at these ......
Read more >
Goptuna - Go Packages
func (s *RandomSampler) Sample(study *Study, trial FrozenTrial, ... of optimize Deprecated: please use StudyOptionDirection instead.
Read more >
Optuna Suggests the Same Parameter Values in a lot of Trials ...
Like I described in the beginning of OP, RandomSampler also more or less has the same amount of duplicates. I want to use...
Read more >
Optuna: Simple Guide to Hyperparameters Tuning / Optimization
We'll be using methods of Trial instance for suggesting values of ... CmaEsSampler - This sampler uses cmaes library for selecting ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found