DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

How to Use SciPy’s Differential Evolution for Bounded Optimization

SciPy differential evolution is a stochastic population search for bounded objectives. Learn how to define bounds, budget evaluations, and choose practical settings.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

scipy.optimize.differential_evolution searches for a low value of a multivariable objective by evolving a population of candidate solutions within bounds you provide. It is a stochastic global-search method, not a guarantee of the true global minimum. You define the objective and bounds, choose a practical evaluation budget, then inspect the returned OptimizeResult.

What differential evolution does

SciPy describes the function as finding “the global minimum of a multivariate function.” More precisely, it is a stochastic, population-based search over bounded candidate points. It does not use gradient methods, and it may need more objective evaluations than a conventional gradient-based optimizer. Its name should not be read as a promise that every run finds the mathematical global optimum. See the SciPy differential_evolution API reference.

During a generation, the method mutates population members to create trial candidates, evaluates them, and keeps a trial when it improves on the corresponding existing candidate. The API offers built-in strategies; best1bin is identified as a good starting point for many systems. Advanced users can also provide a custom strategy callable.

Define the objective and bounds

Your objective receives a vector of variables, typically a one-dimensional NumPy array, and returns a scalar value to minimize. The function signature is f(x, *args); extra fixed inputs can be passed through args. Give every variable a lower and upper bound, either as pairs or with a Bounds object. Bounds are part of the problem definition: they constrain the search and should represent meaningful limits for your application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
import numpy as np
from scipy.optimize import differential_evolution

def objective(x):
    return (x[0] - 2.0) ** 2 + (x[1] + 1.0) ** 2

result = differential_evolution(
    objective,
    bounds=[(-5.0, 5.0), (-5.0, 5.0)],
)

print(result.x)      # candidate minimizer
print(result.fun)    # objective value at result.x
print(result.success)
print(result.message)

This small example illustrates the API shape, not a benchmark or a guarantee about accuracy on other objectives. SciPy returns an OptimizeResult; check its success status and message, and evaluate the solution in the context of your actual problem. The SciPy optimization tutorial includes examples with Rosenbrock and Ackley functions, constraints, vectorization, parallel workers, and polishing.

Choose a search budget and stopping criteria

The number of evaluations can grow quickly because each generation evaluates a population. The API documents this upper-bound formula when polishing is disabled:

(maxiter + 1) * popsize * (N - N_equal)

Here N is the number of variables and N_equal is the number whose lower and upper bounds are equal. This is a function-evaluation budget calculation, not a runtime prediction or a quality guarantee; the optional polish stage can add evaluations. Measure cost using your own objective and environment.

Relevant controls include maxiter (maximum generations), popsize (population-size multiplier), tol and atol (relative and absolute convergence tolerances), and init (population initialization). The default initialization is Latin hypercube; documented alternatives include Sobol, Halton, random, or a user-supplied population. Stopping is based on the standard deviation of population energies relative to the configured tolerances. Tightening a tolerance or increasing the population and generation limits can increase work, so tune against both solution quality and evaluation cost.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set constraints, integer variables, and polishing deliberately

The API supports constraints and an integrality option for variables that must take integer values. These features affect the feasible solutions the search can return. Polishing is enabled by default: SciPy uses L-BFGS-B for an unconstrained problem and trust-constr when constraints are present. If you provide a custom polish callable, you are responsible for ensuring that it respects bounds, constraints, and integrality.

Choose updating and execution mode

With updating='immediate', the best candidate can update during a generation; with updating='deferred', it updates at generation end. Parallel workers and vectorized evaluation are compatible with deferred updating and may override the updating behavior. Parallel workers can help when objective calls are expensive, but process overhead can make them slower for inexpensive objectives. Vectorization can reduce interpreter overhead when your objective can evaluate a population together. Neither approach is universally faster; compare them using the shape and cost of your workload.

Check your installed SciPy version

The current SciPy v1.18.0 API reference notes version-sensitive features: callable strategy customization and expanded callback support were added in SciPy 1.12.0; workers-related polishing behavior changed in 1.15.0; and a callable polishing function was added in 1.17.0. If you use these newer options, consult documentation matching the SciPy version installed in your environment rather than assuming the latest API is available.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

A practical tuning sequence

  1. Validate the problem definition. Confirm that the objective accepts the expected vector shape, returns a scalar, and behaves sensibly throughout the supplied bounds.
  2. Start with documented defaults. Use the default Latin-hypercube initialization and a conventional strategy such as best1bin unless your problem gives a reason to change them.
  3. Set a budget consciously. Estimate the no-polishing evaluation ceiling from the API formula, then account for any polish evaluations and the cost of each objective call.
  4. Match constraints and variable types. Encode feasibility requirements using the constraints and integrality options where appropriate; verify that polishing is suitable for those requirements.
  5. Test execution options against your objective. Compare serial evaluation, workers, or vectorization as applicable, bearing in mind deferred updating behavior.
  6. Interpret results cautiously. Review the returned status, objective value, and candidate; for a stochastic search, a successful termination criterion is not proof of global optimality.

Further reading

For the algorithm itself rather than a SciPy how-to, Springer lists Differential Evolution: A Practical Approach to Global Optimization by Kenneth V. Price, Rainer M. Storn, and Jouni A. Lampinen, covering differential-evolution strategies and practical global optimization: Springer book catalog entry.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.