bayes_opt.BayesianOptimization
¶
-
class bayes_opt.BayesianOptimization(f: collections.abc.Callable[..., float] | None, pbounds: Mapping[str, tuple[float, float]], acquisition_function: AcquisitionFunction | None =
None
, constraint: NonlinearConstraint | None =None
, random_state: int | RandomState | None =None
, verbose: int =2
, bounds_transformer: DomainTransformer | None =None
, allow_duplicate_points: bool =False
)¶ Handle optimization of a target function over a specific target space.
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:¶
- f : function or None.¶
Function to be maximized.
- pbounds : dict¶
Dictionary with parameters names as keys and a tuple with minimum and maximum values.
- constraint : NonlinearConstraint.¶
Note that the names of arguments of the constraint function and of f need to be the same.
- random_state : int or numpy.random.RandomState, optional(default=None)¶
If the value is an integer, it is used as the seed for creating a numpy.random.RandomState. Otherwise the random state provided is used. When set to None, an unseeded random state is generated.
- verbose : int, optional(default=2)¶
The level of verbosity.
- bounds_transformer : DomainTransformer, optional(default=None)¶
If provided, the transformation is applied to the bounds.
- allow_duplicate_points : bool, optional (default=False)¶
If True, the optimizer will allow duplicate points to be registered. This behavior may be desired in high noise situations where repeatedly probing the same point will give different answers. In other situations, the acquisition may occasionally generate a duplicate point.
- acquisition_function : AcquisitionFunction | None¶
- property acquisition_function : AcquisitionFunction¶
Return the acquisition function associated with the optimizer.
- property constraint : ConstraintModel | None¶
Return the constraint associated with the optimizer, if any.
- property max : dict[str, Any] | None¶
Get maximum target value found and corresponding parameters.
See TargetSpace.max for more information.
-
maximize(init_points: int =
5
, n_iter: int =25
) None ¶ Maximize the given function over the target space.
Warning
The maximize loop only fits the GP when suggesting a new point to probe based on the acquisition function. This means that the GP may not be fitted on all points registered to the target space when the method completes. If you intend to use the GP model after the optimization routine, make sure to fit it manually, e.g. by calling
optimizer._gp.fit(optimizer.space.params, optimizer.space.target)
.
-
probe(params: Mapping[str, float] | Sequence[float] | ndarray[Any, dtype[floating[Any]]], lazy: bool =
True
) None ¶ Evaluate the function at the given points.
Useful to guide the optimizer.
-
register(params: Mapping[str, float] | Sequence[float] | ndarray[Any, dtype[floating[Any]]], target: float, constraint_value: float | ndarray[Any, dtype[floating[Any]]] | None =
None
) None ¶ Register an observation with known target.
- property res : list[dict[str, Any]]¶
Get all target values and constraint fulfillment for all parameters.
See TargetSpace.res for more information.
- set_bounds(new_bounds: Mapping[str, ndarray[Any, dtype[floating[Any]]] | Sequence[float]]) None ¶
Modify the bounds of the search space.
- property space : TargetSpace¶
Return the target space associated with the optimizer.