-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Description
Hi, I am a beginner of Bayesian Optimization. I am learning advanced-tour.ipynb and want to add constraint to Suggest-Evaluate-Register Paradigm, the following is a simple example
def black_box_function(x, y):
return -x ** 2 - (y - 1) ** 2 + 1
def constraint_function(x, y):
return 1 - x - y
constraint = NonlinearConstraint(constraint_function, np.array([0.0]), np.array([1.0]))
optimizer = BayesianOptimization(
f=None,
constraint=constraint,
pbounds={'x': (0, 1), 'y': (0, 1)},
verbose=2
)
utility = UtilityFunction(kind="ucb", kappa=2.5, xi=0.0)
next_point_to_probe = optimizer.suggest(utility)
for _ in range(5):
next_point = optimizer.suggest(utility)
target = black_box_function(**next_point)
optimizer.register(params=next_point, target=target, constraint_value = constraint_function(next_point['x'], next_point['y']))
print(target, next_point)
print(optimizer.max)
When I applied this constrain, I got the error
TypeError Traceback (most recent call last)
/tmp/ipykernel_11843/3829336133.py in <module>
18 next_point = optimizer.suggest(utility)
19 target = black_box_function(**next_point)
---> 20 optimizer.register(params=next_point, target=target, constraint_value = constraint_function(next_point['x'], next_point['y']))
21
22 print(target, next_point)
TypeError: register() got an unexpected keyword argument 'constrain_value'
If I don't give a value to constraint_value optimizer.register(params=next_point, target=target), I got
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/tmp/ipykernel_11843/2609747791.py in <module>
18 next_point = optimizer.suggest(utility)
19 target = black_box_function(**next_point)
---> 20 optimizer.register(params=next_point, target=target)
21
22 print(target, next_point)
~/anaconda3/envs/pinns-tf/lib/python3.7/site-packages/bayes_opt/bayesian_optimization.py in register(self, params, target)
178 def register(self, params, target):
179 """Expect observation with known target"""
--> 180 self._space.register(params, target)
181 self.dispatch(Events.OPTIMIZATION_STEP)
182
TypeError: register() missing 1 required positional argument: 'constraint_value'
I am confused that how I can assign the constraint_value.
Thank you so much!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels