API reference
- class scipybiteopt.OptimizeResult
Bases:
dictRepresents the optimization result.
- x
The solution of the optimization.
- Type
ndarray
- fun
Value of the objective function.
- Type
float
- nfev
Number of evaluations of the objective function.
- Type
int
- scipybiteopt.biteopt(fun, bounds, args=(), iters=1000, depth=1, attempts=10, tol='hard', callback=None)
Global optimization via the biteopt algorithm
Note
biteopt does not handle Python Exceptions and will not exit gracefully in case of errors. Take care that your objective function always returns a double.
- Parameters
fun (callable) – The objective function to be minimized. Must be in the form
fun(x, *args), wherexis the argument in the form of a 1-D numpy array and args is a tuple of any additional fixed parameters needed to completely specify the function.bounds (array-like) – Bounds for variables.
(min, max)pairs for each element inx, defining the finite lower and upper bounds for the optimizing argument offun. It is required to havelen(bounds) == len(x).args (tuple, optional, default ()) – Further arguments to describe the objective function
iters (int, optional, default 1000) – Maximal number of function evaluations allowed in one attempt
depth (int, optional, default 1) – Depth of evolutionary algorithm. Required to be
<37. Multiplies allowed number of function evaluations by \(\sqrt{depth}\). Setting depth to a higher value increases the chance for convergence for high-dimensional problems.attempts (int, optional, default 10) – Number of individual optimization attemps
tol (string, optional, default "strong") – Convergence criterion. Must be one of
hard,weak, orNone. Stops optimization if no significant decrease of the objective function was achieved within a certain number of iterations: 64*n_dim forhard, 128*n_dim forweak. IfNone, optimization will run for the maximal number of function evaluationsiterper attempt.callback (callable, optional, default None) – callback function which is also called before every objective function evaluation. Must be in the form
fun(x, *args), wherexis the argument in the form of a 1-D numpy array and args is a tuple of any additional fixed parameters needed to completely specify the function.
- Returns
result – The optimization result represented as a
OptimizeResultobject. Attributes are:xthe solution array,funthe value of the function at the solution, and the number of function evaluationsnfev.- Return type
Example
Let’s minimize a classical example in global optimization: the Ackley function.
>>> import numpy as np >>> from scipybiteopt import biteopt >>> bounds = [(-5, 5), (-5, 5)] >>> def ackley(x): ... arg1 = -0.2 * np.sqrt(0.5 * (x[0] ** 2 + x[1] ** 2)) ... arg2 = 0.5 * (np.cos(2. * np.pi * x[0]) + np.cos(2. * np.pi * x[1])) ... return -20. * np.exp(arg1) - np.exp(arg2) + 20. + np.e >>> result = biteopt(ackley, bounds) >>> result.x, result.fun array([0., 0.]), 0.0