-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Internal sorting of parameter keys leads to unexpected behaviour when registering an array #530
Comments
Hello, I believe this bug is affecting my usage of the package. I have the following instance of the Optimisation class and after the first iteration is seems to swap the second and third bounds, so the parameter 'thick' is meant to have bound of
|
Hey @Nkehoe-QUB, if you give me a full example that reproduces the error I can have a look and see if this is really what happens. |
Hi, I'm sorry it turns out it's an issue how I'm handing the output of
But I didn't realise that the keys of the |
I'm glad this has been noted. I agree that this is a wrinkle worth smoothing out. If nothing else, better compatibility with pandas seems worthwhile. I'll take a look and report back. |
I do remember running into this and being tripped up by it. (example below 😝) I agree it would be better if this didn't happen, but note that this would be a breaking change for many users of this library, who will be assuming that this library is sorting the parameters. so fixing this should be deferred until the next major release is planned in my opinion. |
This should only affect people that register arrays, which hopefully is a small part of the userbase. One thing we could do is publish a minor version that raises a warning when someone registers an array, telling them that this operation will work differently in a future release. |
This change added confusing warnings even when executing the example code given on the web page, e.g. on https://bayesian-optimization.github.io/BayesianOptimization/2.0.1/visualization.html. Would it be possible to add a short hint about that also there, as it might be confusing for future users who want to follow the tutorial, but receive the warning? |
Hey @anates, Thanks for reporting. The warning should definitely not show up in this context, this is due to an error on my part. Let me think about the best way to handle the issue. For the record: This happens because Apologies for the confusion & hi from Basel :) |
@till-m For my understanding: Is there currently any way to avoid rotations/exchanges of the keys in |
Hey @anates, how are you using the library currently?
The plan is to fix the erroneously displayed warnings. The fact that the order is manipulated by the optimizer is something we will change in an upcoming release. What is the problem?Consider the case where you're trying to optimize a function def foobar(baz, qux, quux):
return something(baz, qux, quux) and you have evaluated the function at optimizer.register({'baz': 0., 'qux': 1., 'quux': 2.}, target=42) # register a dict
optimizer.register(np.array([0., 1., 2.]), target=42) # register an array The optimizer assumes that if you register an array, the entries correspond to the alphabetically ordered parameters, i.e. it would consider the second option to be equivalent to I hope this helps. Let me know if there are any other questions. |
Hei @till-m, currently I'm just using |
@anates if you install from PyPI, an updated version of the package should be available that doesn't produce the warnings. On conda it might take some time for the release to show up. |
@till-m Perfect, thank you very much for the quick reply and fix! |
Describe the bug
Internally, the target space sorts the keys of the
pbounds
dict before creating the target space bounds. This is presumably because python dicts were unordered before python 3.7 and ensured that there was a canonical order to the parameters. However, after python 3.7 dict keys are now ordered, making this sorting unnecessary. Moreover, the fact that the internal representation is changed can lead to unexpected behaviour when registering a numpy array (see example below). This seems very likely to happen when using a DataFrame representation of data.To Reproduce
Ex:
Output:
Expected behavior
The optimizer should not change the order of the keys provided by the user. Registering a numpy array instead of a dict should assume the same order as given by the pbounds.
The text was updated successfully, but these errors were encountered: