bayes_opt.BayesianOptimization

class bayes_opt.BayesianOptimization(f, pbounds, acquisition_function=None, constraint=None, random_state=None, verbose=2, bounds_transformer=None, allow_duplicate_points=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

Function to be maximized.

pbounds : dict

Dictionary with parameters names as keys and a tuple with minimum and maximum values.

constraint : ConstraintModel.

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.

property acquisition_function

Return the acquisition function associated with the optimizer.

property constraint

Return the constraint associated with the optimizer, if any.

property max

Get maximum target value found and corresponding parameters.

See TargetSpace.max for more information.

maximize(init_points=5, n_iter=25)

Maximize the given function over the target space.

Parameters:
init_points : int, optional(default=5)

Number of random points to probe before starting the optimization.

n_iter : int, optional(default=25)

Number of iterations where the method attempts to find the maximum value.

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, lazy=True)

Evaluate the function at the given points.

Useful to guide the optimizer.

Parameters:
params : dict or list

The parameters where the optimizer will evaluate the function.

lazy : bool, optional(default=True)

If True, the optimizer will evaluate the points when calling maximize(). Otherwise it will evaluate it at the moment.

register(params, target, constraint_value=None)

Register an observation with known target.

Parameters:
params : dict or list

The parameters associated with the observation.

target : float

Value of the target function at the observation.

constraint_value : float or None

Value of the constraint function at the observation, if any.

property res

Get all target values and constraint fulfillment for all parameters.

See TargetSpace.res for more information.

set_bounds(new_bounds)

Modify the bounds of the search space.

Parameters:
new_bounds : dict

A dictionary with the parameter name and its new bounds

set_gp_params(**params)

Set parameters of the internal Gaussian Process Regressor.

property space

Return the target space associated with the optimizer.

suggest()

Suggest a promising point to probe next.