Skip to content

Differential Evolution (DE)

A simple and reliable method for continuous problems, and a good first try.

DE

DE(strategy=None, *, base_vector='rand', diff_vectors_count=1, crossover_method='bin', crossover_prob=0.9, beta_min=0.5, beta_max=0.5, **kwargs)

Differential Evolution (Storn and Price, 1995 and 1997).

Each trial vector mixes a mutant (a base vector plus F times the difference of random vectors) with its target, and replaces the target when it is at least as good. All trial vectors of an iteration are built from the same population.

Parameters

  • strategy (str, optional): Short form like "DE/best/2/bin". Sets base_vector, diff_vectors_count and crossover_method.
  • base_vector: "rand", "best", "current-to-best" or "rand-to-best". "target-to-best" is another name for "current-to-best". The pull toward the best vector uses the scale factor F.
  • diff_vectors_count: number of difference vectors
  • crossover_method: "bin" or "exp"
  • crossover_prob: crossover rate CR (default 0.9). Price, Storn and Lampinen (2005, p. 166) advise 0.2 for separable functions and 0.9 or 0.95 when the variables depend on each other. 0.9 was chosen on benchmark tests.
  • beta_min, beta_max: the scale factor is drawn uniformly from [beta_min, beta_max] for every component (jitter). The default is the fixed F = 0.5 of Storn and Price. For example, beta_min=0.2, beta_max=0.9 draws F per component from [0.2, 0.9]. The same book suggests F of 0.8 or more with CR 0.9, but that converges too slowly for short budgets, so raise F only for long runs.

In exponential crossover, the number of copied components L is 1 to d with P(L >= v) = CR^(v - 1).

References: R. Storn and K. Price, "Differential evolution: a simple and efficient heuristic for global optimization over continuous spaces", Journal of Global Optimization 11, 1997. K. V. Price, R. M. Storn and J. A. Lampinen, "Differential Evolution: A Practical Approach to Global Optimization", Springer, 2005.

Example

import ypea

problem = ypea.Problem(
    ypea.Real("x", shape=20, lb=-10, ub=10),
    lambda sol: ypea.benchmarks.sphere(sol.x),
    vectorized=True,
    name="sphere",
)

alg = ypea.DE(max_nfe=20_000)
result = alg.solve(problem, seed=1)
print(result.summary())
DE on sphere
  best objective value: 0.130197
  feasible: True (violation 0)
  evaluations: 20000, iterations: 199, time: 0.0429 s, stopped by: max_nfe

Differs from Python: MATLAB draws its own random numbers, so the best value differs from Python's.

problem = ypea.Problem( ...
    vars=ypea.Real("x", shape=20, lb=-10, ub=10), ...
    objective=@(sol) ypea.benchmarks.sphere(sol.x), ...
    vectorized=true, ...
    name="sphere");

alg = ypea.DE(max_nfe=20000);
result = alg.solve(problem, seed=1);
disp(result.summary())
DE on sphere
  best objective value: 0.0741037
  feasible: true (violation 0)
  evaluations: 20000, iterations: 199, time: 0.171 s, stopped by: max_nfe

Search on Rastrigin

DE solutions on Rastrigin at four iterations, and its convergence
DE with default settings, 50 iterations on Rastrigin in two dimensions (seed 1). The red points are the current population. The open diamond is the best solution so far, and the plus sign the global minimum.