bayes_opt.ConstraintModel
¶
See the Constrained Optimization notebook for a complete example.
-
class bayes_opt.constraint.ConstraintModel(fun: collections.abc.Callable[..., float] | collections.abc.Callable[..., NDArray[Float]] | None, lb: float | NDArray[Float], ub: float | NDArray[Float], random_state: int | RandomState | None =
None
) 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.
Note
In case of multiple constraints, this model assumes conditional independence. This means that the overall probability of fulfillment is a simply the product of the individual probabilities.
- allowed(constraint_values: ndarray[Any, dtype[floating[Any]]]) ndarray[Any, dtype[bool]] ¶
Check whether constraint_values fulfills the specified limits.
- approx(X: ndarray[Any, dtype[floating[Any]]]) ndarray[Any, dtype[floating[Any]]] ¶
Approximate the constraint function using the internal GPR model.
- fit(X: ndarray[Any, dtype[floating[Any]]], Y: ndarray[Any, dtype[floating[Any]]]) None ¶
Fit internal GPRs to the data.
- property model : list[GaussianProcessRegressor]¶
Return GP regressors of the constraint function.
- predict(X: ndarray[Any, dtype[floating[Any]]]) ndarray[Any, dtype[floating[Any]]] ¶
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.
Note
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.