bundles / scipy 1.17.1 / scipy / optimize / _dual_annealing / dual_annealing
function
scipy.optimize._dual_annealing:dual_annealing
Signature
def dual_annealing ( func , bounds , args = () , maxiter = 1000 , minimizer_kwargs = None , initial_temp = 5230.0 , restart_temp_ratio = 2e-05 , visit = 2.62 , accept = -5.0 , maxfun = 10000000.0 , rng = None , no_local_search = False , callback = None , x0 = None , * , seed = None ) Summary
Find the global minimum of a function using Dual Annealing.
Parameters
func: callableThe objective function to be minimized. Must be in the form
f(x, *args), wherexis the argument in the form of a 1-D array andargsis a tuple of any additional fixed parameters needed to completely specify the function.bounds: sequence or `Bounds`Bounds for variables. There are two ways to specify the bounds:
Instance of Bounds class.
Sequence of
(min, max)pairs for each element inx.
args: tuple, optionalAny additional fixed parameters needed to completely specify the objective function.
maxiter: int, optionalThe maximum number of global search iterations. Default value is 1000.
minimizer_kwargs: dict, optionalKeyword arguments to be passed to the local minimizer (
minimize). An important option could bemethodfor the minimizer method to use. If no keyword arguments are provided, the local minimizer defaults to 'L-BFGS-B' and uses the already supplied bounds. Ifminimizer_kwargsis specified, then the dict must contain all parameters required to control the local minimization.argsis ignored in this dict, as it is passed automatically.boundsis not automatically passed on to the local minimizer as the method may not support them.initial_temp: float, optionalThe initial temperature, use higher values to facilitates a wider search of the energy landscape, allowing dual_annealing to escape local minima that it is trapped in. Default value is 5230. Range is (0.01, 5.e4].
restart_temp_ratio: float, optionalDuring the annealing process, temperature is decreasing, when it reaches
initial_temp * restart_temp_ratio, the reannealing process is triggered. Default value of the ratio is 2e-5. Range is (0, 1).visit: float, optionalParameter for visiting distribution. Default value is 2.62. Higher values give the visiting distribution a heavier tail, this makes the algorithm jump to a more distant region. The value range is (1, 3].
accept: float, optionalParameter for acceptance distribution. It is used to control the probability of acceptance. The lower the acceptance parameter, the smaller the probability of acceptance. Default value is -5.0 with a range (-1e4, -5].
maxfun: int, optionalSoft limit for the number of objective function calls. If the algorithm is in the middle of a local search, this number will be exceeded, the algorithm will stop just after the local search is done. Default value is 1e7.
rng: {None, int, `numpy.random.Generator`}, optionalIf
rngis passed by keyword, types other than numpy.random.Generator are passed to numpy.random.default_rng to instantiate aGenerator. Ifrngis already aGeneratorinstance, then the provided instance is used. Specifyrngfor repeatable function behavior.If this argument is passed by position or
seedis passed by keyword, legacy behavior for the argumentseedapplies:If
seedis None (or numpy.random), the numpy.random.RandomState singleton is used.If
seedis an int, a newRandomStateinstance is used, seeded withseed.If
seedis already aGeneratororRandomStateinstance then that instance is used.
Specify
rngfor repeatable minimizations. The random numbers generated only affect the visiting distribution function and new coordinates generation.no_local_search: bool, optionalIf
no_local_searchis set to True, a traditional Generalized Simulated Annealing will be performed with no local search strategy applied.callback: callable, optionalA callback function with signature
callback(x, f, context), which will be called for all minima found.xandfare the coordinates and function value of the latest minimum found, andcontexthas one of the following values:0: minimum detected in the annealing process.1: detection occurred in the local search process.2: detection done in the dual annealing process.
If the callback implementation returns True, the algorithm will stop.
x0: ndarray, shape(n,), optionalCoordinates of a single N-D starting point.
Returns
res: OptimizeResultThe optimization result represented as a OptimizeResult object. Important attributes are:
xthe solution array,funthe value of the function at the solution, andmessagewhich describes the cause of the termination. See OptimizeResult for a description of other attributes.
Notes
This function implements the Dual Annealing optimization. This stochastic approach derived from [3] combines the generalization of CSA (Classical Simulated Annealing) and FSA (Fast Simulated Annealing) [1] [2] coupled to a strategy for applying a local search on accepted locations [4]. An alternative implementation of this same algorithm is described in [5] and benchmarks are presented in [6]. This approach introduces an advanced method to refine the solution found by the generalized annealing process. This algorithm uses a distorted Cauchy-Lorentz visiting distribution, with its shape controlled by the parameter
Where is the artificial time. This visiting distribution is used to generate a trial jump distance of variable under artificial temperature .
From the starting point, after calling the visiting distribution function, the acceptance probability is computed as follows:
Where is a acceptance parameter. For , zero acceptance probability is assigned to the cases where
The artificial temperature is decreased according to
Where is the visiting parameter.
Examples
The following example is a 10-D problem, with many local minima. The function involved is called Rastrigin (https://en.wikipedia.org/wiki/Rastrigin_function)import numpy as np from scipy.optimize import dual_annealing func = lambda x: np.sum(x*x - 10*np.cos(2*np.pi*x)) + 10*np.size(x) lw = [-5.12] * 10 up = [5.12] * 10 ret = dual_annealing(func, bounds=list(zip(lw, up)))✓
ret.x ret.fun✗
Aliases
-
scipy.optimize.dual_annealing