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
Update Suggest API #510
Comments
Sorry for the late reply.
Note that the details of the API design is still under consideration (e.g., If you have any thought about the above new API design (draft), please let us know. |
Looks good to me! Maybe rather than giving log as a Boolean, you might use a keyword argument called “distribution” in case you’d ever like to use something more exotic |
Thank you for your suggestion. |
Would you like me to rename this issue, then? |
IMO, either is OK. Feel free to change the title if you want to do it. |
@sile |
Thank you for looking forward to this feature. But, unfortunately, there has been almost no progress since last year. Though Optuna dev team will be still busy for the coming months, we will keep in mind that this is a wanted feature and try to implement it if possible. |
@sile I wonder which solution is likely to be implemented. |
Hi @hayata-yamamoto, sorry for the delayed response. To clarify the design and approach, I created a contribution-welcome issue #902 for, so-called, |
@sile |
Great! |
Hi all, I think the new For example, suggest_int(1, 16, log=True) # or, equivalently: suggest_int(1, 16, distribution='log') would produce values between 1 and 4 equally likely as values between 4 and 16. Model parameters that benefit from discrete log-uniform distributions are e.g.:
My current workaround is to round/truncate log-uniform float values via |
@kasparthommen it would be nice to specify the log scale as well.
Such that As a question for all: would these 5 values be generated with equal probability? Or is it weighted? |
No, all values between 1 and 16 will be generated, but the probability decreases for larger values. |
It looks a good suggestion, but should it be implemented as another function? So, |
My suggestion to add the
I don't really care how it is implemented underneath as long as it provides the functionality I have suggested :-)
I don't agree - I think we should adopt @sile's proposal (2nd post) and extend the |
I'm sorry. This is my wrong :(
If adding |
When I wrote #510 (comment), I didn't plan to add a log-scale option to |
@sile Cool, appreciated! |
Hi, I'd like to work on this issue if it is possible. 😸 |
Sure. Please go for it! > @himkt |
This issue has not seen any recent activity. |
Is there something we have to work on in this PR? |
@himkt Thanks! |
@sile |
@himkt Cool! Thanks! |
@himkt Could I help you implement I guess a new
as a counterpart of
|
Hi @nzw0301, thank you for your interest!
I basically agree with you but I think
I think what we have to do is implementing @nzw0301 What do you think? @sile @cthoyt @hayata-yamamoto @kasparthommen |
Thank you @himkt for your kind reply.
You are right! My understanding was wrong.
It sounds fine. |
IMO, it's sufficient only to extend
Agree. |
Wonderful! |
I understand this comment and it's reasonable, I guess. To be honest, it's easy to understand if this function has a On the other hand, if you only use natural logarithm to generate samples, it may be hard to understand at least for me. I'm afraid that I cannot remember whether natural logarithm can generate an integer value or not. If other developers have the same feeling, adding base can help us to use this function. |
Add testsI haven't created tests. Thank you for your kind comment.
|
I've got. That's cool. |
@hayata-yamamoto Thank you for sharing your concerns. Let me put a small note about the option for the logarithm scale. A histogram may look like here. |
The implemention for a log-uniformly distributed integer is actually quite simple, it's import matplotlib.pyplot as plt
import numpy as np
# this function only implements the log-uniform case
def suggest_int_loguniform(low: int, high: int, step: int=1) -> int:
# input validation - please replace by optuna's standard assertion/checking mechanisms
assert low > 0
assert high >= low
assert step >= 0
# adjust 'high' if necessary
high -= (high - low) % step # e.g. if low = 1, high = 6, step = 2 then adjust to high = 5
# define corresponding continuous range and validate that as well
uniform_low = low - step/2
uniform_high = high + step/2
assert uniform_low > 0
# generate continuous log-uniform sample
log_low = np.log(uniform_low)
log_high = np.log(uniform_high)
sample_continuous = np.exp(np.random.uniform(log_low, log_high)) # <-- the actual value between log_low and log_high needs to come from the sampler, not np.random.uniform
# convert to int
sample_int = int(round(sample_continuous/step))*step
return sample_int
# histogram A: 1...16
np.random.seed(42)
values = []
for i in range(100000):
values.append(suggest_int_loguniform(1, 16))
plt.figure()
plt.hist(values, bins=50)
plt.show()
# histogram B: 2...16, step=2
values = []
for i in range(100000):
values.append(suggest_int_loguniform(2, 16, 2))
plt.figure()
plt.hist(values, bins=50)
plt.show() |
This issue has not seen any recent activity. |
This issue has not seen any recent activity. |
Through the following PRs, the update of the Suggest API has been completed. All of the features will be available by the next major release (v2.0.0) planned for July.
|
There is already a function in the
Trial
class for suggesting a discrete uniformly distributed float (Trial.suggest_discrete_uniform
). It would be nice to have the same option that returns integers instead of floats.My use case is for network representation learning - I want to suggest the embedding dimension in intervals of 50 between 50-350 (e.g. 50, 100, 150, ... , 300, 350).\
Currently, I can accomplish this by dividing out my interval then suggesting an integer and multiplying it like:
But this loses the power of tracking the value within
optuna
. Alternatively I could use the following, but the the data type is tracked incorrectly.The text was updated successfully, but these errors were encountered: