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
Implement log
argument for suggest_int
of pycma integration.
#1302
Implement log
argument for suggest_int
of pycma integration.
#1302
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1302 +/- ##
==========================================
+ Coverage 86.50% 87.78% +1.27%
==========================================
Files 94 96 +2
Lines 7375 7317 -58
==========================================
+ Hits 6380 6423 +43
+ Misses 995 894 -101
Continue to review full report at Codecov.
|
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 PR! I have some comments.
For the first your concern, I totally agree with you. I think we should fix optuna.samplers.CmaEsSampler
as done in this PR.
optuna/integration/cma.py
Outdated
# TODO(toshihikoyanase): Shiting 0.5 is not sufficient if step > 1. | ||
lows.append(self._to_cma_params(search_space, param_name, dist.low - 0.5)) | ||
highs.append(self._to_cma_params(search_space, param_name, dist.high + 0.5)) |
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.
Your second concern is reasonable: instead of expanding 0.5, we should expand 0.5*step. As you say, I think that IntLogUniformDistrbituion
uses 0.5 to ensure low
positive, but if we just want to ensure it, how about doing the following? I think the optuna.samplers.CmaEsSampler
can be fixed as well.
# TODO(toshihikoyanase): Shiting 0.5 is not sufficient if step > 1. | |
lows.append(self._to_cma_params(search_space, param_name, dist.low - 0.5)) | |
highs.append(self._to_cma_params(search_space, param_name, dist.high + 0.5)) | |
# TODO(toshihikoyanase): Shiting 0.5 is not sufficient if step > 1. | |
lows.append(self._to_cma_params(search_space, param_name, max(0, dist.low - 0.5 * dist.step))) | |
highs.append(self._to_cma_params(search_space, param_name, dist.high + 0.5 * dist.step)) |
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 change still has the problem of bias in discretization when low - 0.5 * step
is negative. A possible solution is to move [low-0.5*step, high+0.5*step]
parallel to [1, high - low + step + 1]
for sampling when low - 0.5 * step
is negative, and then undo it later. However, this is a change that has to be made to other samplers at the same time, and I think it's outside the scope of 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.
I'm sorry for the delayed response.
Your new PR (#1329) will prohibit the simultaneous use of step
and log
, and we can keep the master
's implementation. I'll remove the TODO comment about it.
Hi @toshihikoyanase! Is this PR ready for the review? |
946cbe3
to
9f19cb6
Compare
@HideakiImamura I'm sorry for the delayed response. Regarding the |
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! Basically, LGTM! I have some minor comments.
e6969bd
to
709a677
Compare
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. LGTM!
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, basically LGTM.
optuna/integration/cma.py
Outdated
if isinstance(dist, IntLogUniformDistribution): | ||
exp_value = math.exp(cma_param_value) | ||
r = numpy.round((exp_value - dist.low) / dist.step) | ||
v = r * dist.step + dist.low |
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.
step
has been removed (c.f. #1438) so I think we can safely assume it being 1.
optuna/integration/cma.py
Outdated
elif isinstance(distribution, LogUniformDistribution): | ||
elif isinstance(distribution, LogUniformDistribution) or isinstance( | ||
distribution, IntLogUniformDistribution | ||
): |
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.
Ditto.
I'm sorry but I pushed the wrong branch. I'm reverting the change. |
Co-authored-by: Hideaki Imamura <38826298+HideakiImamura@users.noreply.github.com>
Remove redundant logic. Co-authored-by: Hideaki Imamura <38826298+HideakiImamura@users.noreply.github.com>
Co-authored-by: Hiroyuki Vincent Yamazaki <hiroyuki.vincent.yamazaki@gmail.com>
423efb2
to
24dd979
Compare
optuna/integration/cma.py
Outdated
lows.append(dist.low - 0.5) | ||
highs.append(dist.high + 0.5) | ||
lows.append(dist.low - 0.5 * dist.step) | ||
highs.append(dist.high + 0.5 * dist.step) |
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.
Just wondering but is this change somewhat orthogonal to the other?
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.
You're right. It's the change for IntUniformDistribution
. I reverted the change in 682e8f4. Thank you for your careful review.
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.
Should we create a separate PR for that?
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 your suggestion.
I created #1456. Please review it after 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.
Thanks, I'll have a look at it.
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 having it dragged out, LGTM!
Let me merge this PR after CI.
Motivation
This one of the follow-up PRs of #1201.
Description of the changes
This PR adds support for
IntLogUniformDistribution
tooptuna.integration.CmaEsSampler
.I have two concerns about this implementation:
optuna.samplers.CmaEsSampler
quantizes the suggested values bystep
in the log domain, this implementation quantizes them in the linear domain similarly to theoptuna.samplers.RandomSampler
. If this change is acceptable, I think I also update theoptuna.samplers.CmaEsSampler
.optuna.samplers.RandomSampler
suggests values fromDiscreteUniformDistribution
, it expandslow
andhigh
by0.5 * q
to make the bins of quantization equivalent to others. On the other hand, it expands0.5
when it usesIntLogUniformDistribution
. I think this is because thelow
can be negative depending onstep
. In the most cases, users will usestep=1
and the calculation will be correct. So, I follow this definition inoptuna.integration.CmaEsSampler
, but I'm a bit concerned about performance degradation when users specifystep>1
.