Derivative-free parameter fitting
Optimize a simulation, calibration loss, or engineering objective without reliable derivatives.
SciPy · Function
Finds a global minimum of a bounded multivariate function using stochastic, derivative-free differential evolution. It evolves a population of candidates and can optionally polish the best candidate.
The function maintains a population of candidate points, creates trial points by combining population members, and retains improvements across generations. It is stochastic and derivative-free, so it can explore broad bounded domains but may use more objective evaluations than gradient-based local methods.
scipy.optimize.differential_evolution(func, bounds, args=(), strategy='best1bin', maxiter=1000, popsize=15, tol=0.01, mutation=(0.5, 1), recombination=0.7, rng=None, callback=None, disp=False, polish=True, init='latinhypercube', atol=0, updating='immediate', workers=1, constraints=(), x0=None, *, integrality=None, vectorized=False, seed=None)| Name | Type | Description |
|---|---|---|
func | callable | Objective callable to minimize; it receives a candidate vector and may use extra positional arguments from args. |
bounds | sequence or Bounds | Bounds for every optimization variable, supplied as (min, max) pairs or a Bounds object. |
args | tuple, optional | Additional positional arguments passed to func. |
strategy | str, optional | Evolution strategy used to generate trial vectors. |
maxiter | int, optional | Maximum number of generations. |
popsize | int, optional | Population-size multiplier. |
tol | float, optional | Relative convergence tolerance. |
mutation | float or tuple, optional | Mutation constant, or a range from which it is sampled. |
recombination | float, optional | Crossover probability. |
rng | Generator or seed-like, optional | Random-number generator or compatible seed specification. |
callback | callable, optional | Callback invoked during optimization. |
disp | bool, optional | Whether to print progress. |
OptimizeResult containing the best solution, objective value, convergence information, and evaluation/status fields described on the documentation page.
import numpy as np
from scipy.optimize import differential_evolution
def objective(x):
return (x[0] - 1.5)**2 + (x[1] + 2.0)**2
result = differential_evolution(objective, [(-5, 5), (-5, 5)], rng=np.random.default_rng(7))
print(result.x)
print(result.fun)Minimizes a two-variable quadratic over the supplied box bounds.
Optimize a simulation, calibration loss, or engineering objective without reliable derivatives.
Search a bounded, multimodal objective where a local starting point may be misleading.
Optimize objectives with nonlinear or linear constraints.
Evaluate expensive objectives concurrently across candidate points.
It is a stochastic, population-based global optimizer that does not require gradients. Each generation mutates candidates by mixing them with other population members, then evaluates trial candidates and retains improvements.
Follow-up: How would you make parallel evaluation possible? Use workers greater than one, which requires deferred updating; vectorized evaluation is another supported route when the objective accepts a population of points.
Bounds define the candidate domain, and the objective callable receives a candidate vector. The result is an OptimizeResult containing the best solution and its objective value, along with solver status information.
Follow-up: What should be supplied for constrained problems? Pass constraint objects through constraints; integer-valued variables can additionally be specified with integrality.
The stopping test compares population energy spread with a tolerance-based threshold involving the mean energy and atol. Increasing maxiter or population size generally permits more search, while polish can refine the final candidate with a local method.
Follow-up: When might polishing be undesirable? Disable it when the extra local optimization cost is not wanted or when the final candidate should remain the raw evolutionary result.
scipy.optimize.Boundsscipy.optimize.LinearConstraintscipy.optimize.NonlinearConstraintscipy.optimize.OptimizeResultscipy.optimize.minimize