The Boulder Opal Toolkits are currently in beta phase of development. Breaking changes may be introduced.
- optimize(cost_function, initial_test_parameters, optimizer, bounds, cost_uncertainty=None, target_cost=None, max_iteration_count=100, callback=None, verbose=True)
Run a closed-loop optimization to find a minimum of the given cost function.
This is an iterative process, where the optimizer generates and tests a set of points. After several iterations the distribution of generated test points should converge to low values of the cost function. You can use this approach when your system is too complicated to model, or the computation of gradient is expensive or impossible.
cost_function (Callable) – A function that takes the parameters as an argument and returns an array of costs values. The function should take a NumPy array of input parameters with shape
(test point count, parameter count)and return the costs in a 1D array of length test point count.
initial_test_parameters (np.ndarray) – The initial values of the parameters to use in the optimization. A 2D NumPy array of shape
(test point count, parameter count).
optimizer (Optimizer) – The optimizer to be used in the minimization of the cost function.
bounds (np.ndarray) – The per-parameter bounds on the test points. The bounds must be a NumPy array of shape
(parameter count, 2)where the trailing axis are the bounds for each parameter (with the lower bound first, followed by the upper bound).
cost_uncertainty (float, optional) – The standard deviation in the value of the cost. Must be non-negative. Defaults to 0.
target_cost (float, optional) – The target cost. If passed, the optimization will halt if the best cost is below the given value.
max_iteration_count (int, optional) – The maximum number of iterations. Defaults to 100.
callback (Callable, optional) – A function that takes in the current set of parameters, a 2D NumPy array of shape
(test point count, parameter count), and returns a bool. The function is evaluated once during each iteration with the current parameters. If it returns True, the optimization is halted.
verbose (bool, optional) – Whether to print out information about the optimization cycle. Defaults to True.
A dictionary containing the results of the optimization, namely, the best parameters best_parameters, their associated cost best_cost, and the history of best cost values best_cost_history.
- Return type:
If the optimization loop is halted via a KeyboardInterrupt then the function returns the best results obtained in the optimization thus far.