You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As has been noted in #158, the code will crash if it is asked to probe a point it has already probed.
This condition occurs not infrequently when using the utility functions. In addition, when working with very noisy data, it is completely valid to probe the same point more than once.
Describe the solution you'd like
I suggest simply replacing the error with a warning, and maybe a parameter called '_n_repeated_points_probed' - that would allow users to handle the issue on their end. Thoughts?
Are you able and willing to implement this feature yourself and open a pull request?
In addition, when working with very noisy data, it is completely valid to probe the same point more than once.
How do the GPR's handle receiving different target values for the same parameters? Does it just take the mean? Are the covariances adjusted at that point (or for all the points)?
a parameter called '_n_repeated_points_probed'
I assume -- based on the name -- that this is an integer counter storing how often points that were already probed have been re-probed?
"I assume -- based on the name -- that this is an integer counter storing how often points that were already probed have been re-probed?"
correct!
"How do the GPR's handle receiving different target values for the same parameters? Does it just take the mean? Are the covariances adjusted at that point (or for all the points)?"
This is actually something I am currently trying to figure out. I've been playing around with 10 runs of the same simulation, with varying levels of noise and seeing how best to model it. The distribution of the different data sets is below (n here means n particles, but that's not really important for the purpose of this discussion).
If we run the bayesian_optimization code with the default parameters, repeatedly pass it the same point with different (noisy) values, and simply replace the raise repeated_points error with a pass statement, it runs without issue but doesn't do a good job handling the noise:
However, we can construct a custom kernel like this:
frombayes_optimportBayesianOptimizationfromsklearn.gaussian_process.kernelsimportMatern, WhiteKerneloptimizer=BayesianOptimization(f=None,pbounds=pbounds, verbose=2, random_state=1)
k1=Matern(length_scale=[3, 0.2, 0.2]) # Matern is the defaul kernelk2=WhiteKernel()
kernel=k1+k2optimizer.set_gp_params(kernel=kernel)
then we can model noise very effectively:
Note that when noise_level_bounds is not set, the hyper parameters will be fit to the data at each iteration.
We can also set them to be fixed:
in which case the noise level will remain fixed. I think this is what I would want to do in my case, where I have an independent estimate of the noise that I am reasonably confident of. However, I am currently unclear as to the exact relation between the noise_level parameter and the modeled noise; it seems like even with the same value I can get different noise estimates depending on the input data.
I am currently trying to put together a noisy optimization example for my own code which uses this code as one of its backends. If I get that working I could also work up a similar example for this repo.
thanks for this, I didn't expect such a detailed explanation. I agree that it would be good if this were part of the documentation so if you find the time, a notebook would be a great addition. I assume that you need to write your own optimization loop to get around the caching that happens internally?
In any case, I agree with your proposed handling of the initial problem of repeatedly sampling the same point.
The test failure in #368 seems to occur by design: There is a test to ensure that no duplicate points are registered, i.e. loading from logs is idempotent. I'm guessing this was in fact the primary reason for disallowing duplicate points. Maybe adding a keyword allow_duplicate=False to register is the right way to go here?
Additionally, maybe we should replace KeyError with a more specific (custom?) error type, so that we can intentionally catch that at appropriate places without worrying about catching unrelated KeyErrors.
Hey @Till-M, I don't think I understand the problem (also I had to google what idempotent meant 😆).
The custom error does sound more appropriate albeit relatively low priority?
Sorry, I guess I explained the problem badly. The KeyError that was raised when registering a duplicate point was caught in the load_logs function to skip over points that had already been registered. That means that loading the same log twice didn't register any new points (and there is specifically a test to test for this). I'm not entirely sure whether we want to keep this behaviour or not, but if we do, then (dis)allowing duplicates should be an optional thing in the register function. Hope that makes sense.
@Till-M - I have been having another look at this.
I noticed that this error never occurred when using the maximize approach, only when using the suggest, probe, register approach.
After some digging, I found that within target_space.probe there is this line:
try:
returnself._cache[_hashable(x)]
exceptKeyError:
# this is the normal behavior that occurs when # the point has not been seen before
...
This means if the point x has ever been seen before, the code simply returns the previous value. It doesn't attempt to register the point again.
This seems like odd behaviour to me. I think we should remove this, so that the behaviour is either:
if allow_duplicate_points=False an error is thrown (the error that is already in the code)
else the duplicate points are registered in the normal way
Activity
t-muser commentedon Sep 12, 2022
Two (naive) questions that I have:
How do the GPR's handle receiving different target values for the same parameters? Does it just take the mean? Are the covariances adjusted at that point (or for all the points)?
I assume -- based on the name -- that this is an integer counter storing how often points that were already probed have been re-probed?
bwheelz36 commentedon Sep 12, 2022
Hey @Till-M
correct!
This is actually something I am currently trying to figure out. I've been playing around with 10 runs of the same simulation, with varying levels of noise and seeing how best to model it. The distribution of the different data sets is below (n here means n particles, but that's not really important for the purpose of this discussion).

If we run the bayesian_optimization code with the default parameters, repeatedly pass it the same point with different (noisy) values, and simply replace the
raise repeated_pointserror with a pass statement, it runs without issue but doesn't do a good job handling the noise:However, we can construct a custom kernel like this:
then we can model noise very effectively:
Note that when noise_level_bounds is not set, the hyper parameters will be fit to the data at each iteration.
We can also set them to be fixed:
in which case the noise level will remain fixed. I think this is what I would want to do in my case, where I have an independent estimate of the noise that I am reasonably confident of. However, I am currently unclear as to the exact relation between the noise_level parameter and the modeled noise; it seems like even with the same value I can get different noise estimates depending on the input data.
I am currently trying to put together a noisy optimization example for my own code which uses this code as one of its backends. If I get that working I could also work up a similar example for this repo.
bwheelz36 commentedon Sep 12, 2022
Note - we could also increase the alpha parameter to model noise without using a white kernel:
However then I'm even more unclear on the relationship between the value of alpha and the known noise...
t-muser commentedon Sep 13, 2022
Hi @bwheelz36,
thanks for this, I didn't expect such a detailed explanation. I agree that it would be good if this were part of the documentation so if you find the time, a notebook would be a great addition. I assume that you need to write your own optimization loop to get around the caching that happens internally?
In any case, I agree with your proposed handling of the initial problem of repeatedly sampling the same point.
bwheelz36 commentedon Sep 14, 2022
I hadn't actually thought of that, I always run in the 'advanced' mode of suggest/ probe/ register.
bwheelz36 commentedon Sep 14, 2022
I will update with a notebook and make the change suggested above once I'm more confident in what I'm doing!
t-muser commentedon Oct 13, 2022
The test failure in #368 seems to occur by design: There is a test to ensure that no duplicate points are registered, i.e. loading from logs is idempotent. I'm guessing this was in fact the primary reason for disallowing duplicate points. Maybe adding a keyword
allow_duplicate=Falseto register is the right way to go here?Additionally, maybe we should replace
KeyErrorwith a more specific (custom?) error type, so that we can intentionally catch that at appropriate places without worrying about catching unrelatedKeyErrors.bwheelz36 commentedon Oct 18, 2022
Hey @Till-M, I don't think I understand the problem (also I had to google what idempotent meant 😆).
The custom error does sound more appropriate albeit relatively low priority?
t-muser commentedon Oct 19, 2022
Sorry, I guess I explained the problem badly. The
KeyErrorthat was raised when registering a duplicate point was caught in theload_logsfunction to skip over points that had already been registered. That means that loading the same log twice didn't register any new points (and there is specifically a test to test for this). I'm not entirely sure whether we want to keep this behaviour or not, but if we do, then (dis)allowing duplicates should be an optional thing in theregisterfunction. Hope that makes sense.should fix bayesian-optimization#353
bwheelz36 commentedon Oct 27, 2022
ok @Till-M, this should be fixed in #372.
allow_duplicate_points. The default is False so the existing behavior of the code shouldnt changeallow_duplicate_points=TrueI haven't done anything to the log read in, because this should be handled already by the change in TargetSpace.
bwheelz36 commentedon Nov 25, 2022
@Till-M - I have been having another look at this.
I noticed that this error never occurred when using the
maximizeapproach, only when using the suggest, probe, register approach.After some digging, I found that within
target_space.probethere is this line:This means if the point x has ever been seen before, the code simply returns the previous value. It doesn't attempt to register the point again.
This seems like odd behaviour to me. I think we should remove this, so that the behaviour is either:
allow_duplicate_points=Falsean error is thrown (the error that is already in the code)