bayesian-optimization / BayesianOptimization

A Python implementation of global optimization with gaussian processes.
https://bayesian-optimization.github.io/BayesianOptimization/index.html
MIT License
7.81k stars 1.53k forks source link

```constraint``` and ```allow_duplicate_points``` can't be used at the same time. #471

Closed Forestsene closed 5 months ago

Forestsene commented 5 months ago

constraint and allow_duplicate_points can't be used at the same time.

I want to optimize a 4-D function f(x,y,z,k) with constraint z<k and I will get some duplicate points during BO process. So I need to use constraint and allow_duplicate_points at the same time. But it seems that these two functions can't work together although the script runs smoothly when they are used separately.

Here is my code

def constraint_function(x,y,z,k):
    return z-k

constraint_lower = -np.inf
constraint_upper = 0

constraint = NonlinearConstraint(constraint_function, constraint_lower, constraint_upper)

optimizer = BayesianOptimization(
    f=None,
    constraint=constraint,
    pbounds={"x": (2, 2.5),"y":(0.5, 1.0), "z":(11,11.5) , "k":(11,11.5)},
    verbose=0,
    random_state=1,
    allow_duplicate_points=True,
)

utility = UtilityFunction(kind="ei", kappa=10, xi=0)

#iter
optimizer.register(params={'x': 2.500, 'y': 0.600, 'z': 11.000, 'k': 11.500}, target=-2.78000, constraint_value=constraint_function(2.500,0.600,11.000,11.500))
#------------------------------------------------------
optimizer.register(params={'x': 2.216, 'y': 0.653, 'z': 11.178, 'k': 11.192}, target=-26.57100, constraint_value=constraint_function(2.216,0.653,11.178,11.192))
#------------------------------------------------------
optimizer.register(params={'x': 2.411, 'y': 0.916, 'z': 11.138, 'k': 11.437}, target=-100.00000, constraint_value=constraint_function(2.411,0.916,11.138,11.437))
optimizer.register(params={'x': 2.411, 'y': 0.916, 'z': 11.138, 'k': 11.437}, target=-90.00000, constraint_value=constraint_function(2.411,0.916,11.138,11.437))
#------------------------------------------------------

ERROR 316246465-b5b85505-1657-4843-a44a-7750892cdb58

I have used allow_duplicate_points=True, But I sill got this error.

Environment

Forestsene commented 5 months ago

I have found the solution in page(https://github.com/bayesian-optimization/BayesianOptimization/pull/437/files) Thanks to all contributors