API reference

class scipybiteopt.OptimizeResult

Bases: dict

Represents 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), where x is 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 in x, defining the finite lower and upper bounds for the optimizing argument of fun. It is required to have len(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, or None. Stops optimization if no significant decrease of the objective function was achieved within a certain number of iterations: 64*n_dim for hard, 128*n_dim for weak. If None, optimization will run for the maximal number of function evaluations iter per 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), where x is 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 OptimizeResult object. Attributes are: x the solution array, fun the value of the function at the solution, and the number of function evaluations nfev.

Return type

OptimizeResult

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