Skip to content
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

Problem about allow_duplicate_points #468

Closed
Forestsene opened this issue Mar 21, 2024 · 4 comments
Closed

Problem about allow_duplicate_points #468

Forestsene opened this issue Mar 21, 2024 · 4 comments

Comments

@Forestsene
Copy link

When I have to use some same points to optimize a black_box_function, I notice a strange phenomenon: When I use 5 or 4 of the same points, I obtain different next new point.

image

Here is my script:

optimizer = BayesianOptimization(
    f=None,
    pbounds={"r0":(0.500, 0.700)},
    verbose=0,
    random_state=1,
    allow_duplicate_points=True
)
utility = UtilityFunction(kind="ei", kappa=10, xi=0)
#ini
#--------------------1-------------------------------
optimizer.register(params={'r0': 0.500}, target=-77.54000 )
#--------------------2-------------------------------
optimizer.register(params={'r0': 0.540}, target=-40.86500 )
#--------------------3-------------------------------
optimizer.register(params={'r0': 0.580}, target=-12.81900 )
#--------------------4-------------------------------
optimizer.register(params={'r0': 0.620}, target=-7.23000 )
#--------------------5-------------------------------
optimizer.register(params={'r0': 0.660}, target=-23.60100 )
#--------------------6-------------------------------
optimizer.register(params={'r0': 0.700}, target=-35.62100 )
                                                        
#--------------------iter-------------------------------
                                                        
#-------------------7-----------------------------------
optimizer.register(params={'r0': 0.606}, target=-0.84700 )
#-------------------10-----------------------------------
optimizer.register(params={'r0': 0.602}, target=-1.65000 )
#-------------------11-----------------------------------
optimizer.register(params={'r0': 0.608}, target=-1.99000 )
#-------------------12-----------------------------------
optimizer.register(params={'r0': 0.605}, target=-0.52800 )
#-------------------14-----------------------------------
optimizer.register(params={'r0': 0.603}, target=-0.62300 )
##-------------------15-----------------------------------
optimizer.register(params={'r0': 0.603}, target=-0.62300 )
##-------------------16-----------------------------------
optimizer.register(params={'r0': 0.603}, target=-0.62300 )
##-------------------17-----------------------------------
optimizer.register(params={'r0': 0.603}, target=-0.62300 )
##-------------------18-----------------------------------
#optimizer.register(params={'r0': 0.603}, target=-0.62300 )
##-------------------19-----------------------------------
optimizer.register(params={'r0': 0.603}, target=-0.62300 )
next_point = optimizer.suggest(utility)
print(next_point.get('r0'))

Besides, I have changed the kernel in bayesian_optimization.py Line 127

        # Internal GP regressor
        kernel=1.0 * RBF(length_scale=1e-1, length_scale_bounds=(1e-2, 1e3)) + WhiteKernel(noise_level=1e-2, noise_level_bounds=(1e-10, 1e1))
        self._gp = GaussianProcessRegressor(
            kernel=kernel,
            alpha=0.0,
            normalize_y=True,
            n_restarts_optimizer=5,
            random_state=self._random_state,
        )

This did not occur when I ran the script in the tutorial(https://bayesian-optimization.github.io/BayesianOptimization/constraints.html)

I am not sure whether this is due to the complexity of the prediction function or the script. Could you give me some advice? Thank you very much!

@till-m
Copy link
Member

till-m commented Mar 21, 2024

Hey @Forestsene,

If you don't mind the question, what are you trying to do? Specifically, I'm wondering why you're registering the same point multiple times, especially if you expect it to not affect the GP.

Most likely the fitting process of the GP produces different results. If I read correctly, your working with a 1-dimensional problem. You could maybe plot the acq function (see the script here as an example on how to do that) -- if you compare the acq function in both cases, you should see a difference.

Another reason is that the acq maximization is non-deterministic, so the next probed point is not always the same, even when using the exact same underlying GP/acq.

Let us know if this helps.

@Forestsene
Copy link
Author

Thanks for your advice! I ploted the acq function and the fitting process of the GP produces different results.​

51

4

If the next_new_point given by BO is a point that has already been collected, I don't want to repeat the sampling because it takes a lot of time and will give almost the same result.

At this point, I was not sure whether to manually modify the next sampling point or transfer this point again to the Gaussian process regression, so I did this test.

My intuition tells me that if I fit the repeated points to a Gaussian process, I should get the same result, just like a linear regression, so I'll get the same next_new_point. But according to the test results, that's not the case. Is this a property of Gaussian process fitting? Expect your reply!

@till-m
Copy link
Member

till-m commented Mar 22, 2024

Hi @Forestsene,

From looking at the plot, I'm guessing the fitting process produces very different length scales. You could check this by inspecting the return object of gp.kernel.get_params().
I'm honestly not super experienced with this, maybe you could check out Rational Quadratic Kernel which is a mixture over a number of different lengthscales, see here and here.

Otherwise, I'm hoping someone else has better advice, I'm a bit out of my depth here admittedly.

@till-m
Copy link
Member

till-m commented May 27, 2024

Hi @Forestsene,

I assume the problem is solved. I will close this issue for now.

@till-m till-m closed this as completed May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants