bayes_opt.ConstraintModel
¶
See the Constrained Optimization notebook for a complete example.
-
class bayes_opt.constraint.ConstraintModel(fun, lb, ub, random_state=
None
)¶ Model constraints using GP regressors.
This class takes the function to optimize as well as the parameters bounds in order to find which values for the parameters yield the maximum value using bayesian optimization.
- Parameters:¶
- fun : None or Callable -> float or np.ndarray¶
The constraint function. Should be float-valued or array-valued (if multiple constraints are present). Needs to take the same parameters as the optimization target with the same argument names.
- lb : float or np.ndarray¶
The lower bound on the constraints. Should have the same dimensionality as the return value of the constraint function.
- ub : float or np.ndarray¶
The upper bound on the constraints. Should have the same dimensionality as the return value of the constraint function.
- random_state : np.random.RandomState or int or None, default=None¶
Random state to use.
Notes
In case of multiple constraints, this model assumes conditional independence. This means that for each constraint, the probability of fulfillment is the cdf of a univariate Gaussian. The overall probability is a simply the product of the individual probabilities.
- allowed(constraint_values)¶
Check whether constraint_values fulfills the specified limits.
- property lb¶
Return lower bounds.
- property model¶
Return GP regressors of the constraint function.
- predict(X)¶
Calculate the probability that the constraint is fulfilled at X.
Note that this does not try to approximate the values of the constraint function (for this, see ConstraintModel.approx().), but probability that the constraint function is fulfilled. That is, this function calculates
\[p = \text{Pr}\left\{c^{\text{low}} \leq \tilde{c}(x) \leq c^{\text{up}} \right\} = \int_{c^{\text{low}}}^{c^{\text{up}}} \mathcal{N}(c, \mu(x), \sigma^2(x)) \, dc.\]with \(\mu(x)\), \(\sigma^2(x)\) the mean and variance at \(x\) as given by the GP and \(c^{\text{low}}\), \(c^{\text{up}}\) the lower and upper bounds of the constraint respectively.
In case of multiple constraints, we assume conditional independence. This means we calculate the probability of constraint fulfilment individually, with the joint probability given as their product.
- property ub¶
Return upper bounds.