-
Notifications
You must be signed in to change notification settings - Fork 16
Constraint Handling
The optimization constraints are handled through imposing a dynamic penalty value to the acquisition function when being optimized to propose new candidate solutions. It is straightforward to implement your own equality or inequality constraints:
For equality constraints, the function should only return 0 when the condition is satisfied and it is generally recommended to return a large value if the degree of constraint violations is higher, for instance, in the example below, we would like to restrict the search on a hyperplane x_1 + x_2 + ... + x_n = 1:
def h(x):
return np.abs(np.sum(x) - 1)If you have more than one constraint, please return a vector containing the value from each constraint from the constraint function.
For inequality constraints, the function should only return a non-positive value when the condition is satisfied and similarly, it is recommended to return a large value if the degree of constraint violations is higher, for instance, in the example below, we would like to restrict the search on one half of the search space, separated by x_1 + x_2 + ... + x_n >= 1:
def g(x):
return 1 - np.sum(x)The constraint functions
handgshould be passed to the constructor ofBOclass (and its subclasses) or to thefmininterface.