Global search over nonconvex functions
The objective is multimodal and derivative-free optimization is needed.
SciPy · Function
Finds a global minimum of a bounded objective with dual annealing, optionally followed by local refinement. It returns an OptimizeResult describing the best point and termination state.
dual_annealing explores a bounded objective with a temperature-controlled stochastic search, periodically reheating when the temperature falls to a specified fraction. It can optionally refine promising points with a local minimizer and accepts fixed extra arguments through args.
scipy.optimize.dual_annealing(func, bounds, args=(), maxiter=1000, minimizer_kwargs=None, initial_temp=5230.0, restart_temp_ratio=2e-5, visit=2.62, accept=-5.0, maxfun=10000000.0, rng=None, no_local_search=False, callback=None, x0=None, *, seed=None)| Name | Type | Description |
|---|---|---|
func | callable | Objective callable accepting x as a one-dimensional array and optional fixed arguments. |
bounds | sequence or Bounds | Finite variable bounds, supplied as Bounds or (min, max) pairs. |
args | tuple, optional | Extra fixed arguments passed to func. |
maxiter | int, optional | Maximum number of global-search iterations. |
minimizer_kwargs | dict, optional | Options forwarded to the local minimizer. |
initial_temp | float, optional | Starting temperature for the annealing schedule. |
restart_temp_ratio | float, optional | Temperature ratio that triggers reannealing. |
visit | float, optional | Visiting-distribution parameter. |
accept | float, optional | Acceptance-probability parameter. |
maxfun | int, optional | Maximum objective-function evaluations. |
rng | int, Generator, optional | Random-number generator or seed control. |
no_local_search | bool, optional | Disable local minimization when true. |
OptimizeResult containing the best solution, objective value, termination status, message, evaluation count, and iteration count.
import numpy as np
from scipy.optimize import dual_annealing
def objective(x):
return np.sum(x**2) + 0.2 * np.sin(5 * x[0])
result = dual_annealing(objective, [(-5, 5), (-5, 5)], seed=0)
print(result.x)
print(result.fun)Minimizes a bounded two-variable objective and prints the best point and objective value.
The objective is multimodal and derivative-free optimization is needed.
A good global candidate should be polished with a local method.
The model has bounded physical or design variables.
The function performs global minimization using dual annealing over finite bounds. It combines stochastic exploration with optional local minimization of promising points.
Follow-up: How would you increase exploration? Raise initial_temp or visit, while recognizing that higher exploration can require more evaluations.
func receives a one-dimensional array x and any fixed parameters supplied through args. bounds can be a Bounds object or a sequence of lower-upper pairs.
Follow-up: Why must bounds be finite? They define the constrained search region and the number of variables.
The temperature decreases during annealing, and reannealing starts when it reaches initial_temp multiplied by restart_temp_ratio. The visit parameter controls the visiting distribution, while accept controls acceptance probability.
Follow-up: How can local refinement be customized? Supply minimizer_kwargs for the local minimizer and leave no_local_search false.
scipy.optimize.minimizescipy.optimize.Boundsscipy.optimize.OptimizeResult