🧬 Differential Evolution Optimizer

Differential Evolution (DE/rand/1/bin): mutant v = x_r1 + F(x_r2 - x_r3), crossover at rate CR. Self-adaptive variant adjusts F and CR. Benchmark on Rosenbrock, Rastrigin, Ackley.

AlgorithmsInteractive
Population on contour plot · ▶ Play · Step · P=pause · R=restart

How it Works

DE maintains a population of NP candidate vectors. Each generation, for each target vector x_i, three random vectors x_r1, x_r2, x_r3 are chosen. The mutant v = x_r1 + F·(x_r2 - x_r3). Binomial crossover creates trial u: each dimension taken from v with probability CR or from x_i otherwise. If f(u) <= f(x_i), u replaces x_i (greedy selection).

Mutation: v_i = x_r1 + F · (x_r2 − x_r3) Crossover: u_ij = v_ij if rand() < CR or j==j_rand x_ij otherwise Selection: x_i(t+1) = u_i if f(u_i) <= f(x_i) x_i otherwise Rosenbrock: f = (1−x)²+100(y−x²)² min=0 @ (1,1) Rastrigin: f = 20 + x²−10cos(2πx) + y²−10cos(2πy) Ackley: f = −20e^(−0.2√(x²+y²)/2) − e^(cos(2πx)+cos(2πy))/2 + 20+e

The contour plot shows the fitness landscape (darker=lower). Blue dots are the population; the red star marks the best solution. The convergence plot (bottom) shows best fitness per generation on a log scale.

Frequently Asked Questions

What is Differential Evolution (DE)?

Differential Evolution is a population-based stochastic optimization algorithm by Storn and Price (1997). It evolves candidate solutions using mutation (vector differences), crossover, and selection without requiring gradient information.

How does DE/rand/1/bin mutation work?

Three random vectors x_r1, x_r2, x_r3 are selected from the population. The mutant vector is v = x_r1 + F·(x_r2 - x_r3), where F ∈ [0,2] is the mutation scale factor controlling search step size.

What is the crossover operation in DE?

In binomial (bin) crossover, each dimension of the trial vector u is taken from the mutant v with probability CR, or from the target x otherwise. At least one dimension always comes from the mutant.

What are the F and CR parameters in DE?

F (mutation factor) controls mutation step size, typically F ∈ [0.4, 1.0]. CR (crossover rate) controls the fraction of parameters from the mutant, typically CR ∈ [0.1, 0.9]. Higher CR = more exploration.

What is the Rosenbrock function?

f(x,y) = (1-x)² + 100(y-x²)² has a narrow curved valley. Its global minimum is at (1,1) with f=0. The valley is easy to find but the minimum is hard to locate precisely.

What is the Rastrigin function?

The Rastrigin function is highly multimodal: f(x,y) = 20 + x²-10cos(2πx) + y²-10cos(2πy). Global minimum is at (0,0) with f=0. Tests global optimization ability.

What is the Ackley function?

The Ackley function has a nearly flat outer region with a deep global minimum at the origin. It challenges algorithms to avoid premature convergence to local optima in the flat region.

How does DE compare to other evolutionary algorithms?

DE typically outperforms genetic algorithms and particle swarm on continuous benchmarks. It is simpler than CMA-ES and scales well to ~100 dimensions. CMA-ES is often better for very high-dimensional smooth problems.

What is self-adaptive DE (SaDE)?

SaDE automatically adjusts F and CR during optimization based on their success rates, eliminating the need for manual tuning. Successful parameter values are recorded and used to generate new parameter values.

When should I use Differential Evolution?

Use DE for black-box, non-differentiable, multimodal, or noisy optimization with continuous variables, typically 5–50 dimensions. Good for parameter fitting and engineering design. Gradient methods are better when derivatives are available.

About this simulation

This simulator runs a DE/rand/1/bin evolutionary loop live in the browser: each generation, every population member spawns a mutant from three other randomly chosen vectors, blends it with the target through binomial crossover, and survives only if its fitness beats the original. Watch the population of dots crawl across the contour map of Rosenbrock, Rastrigin, or Ackley toward the red star while the right-hand panel plots best fitness on a log scale.

🔬 What it shows

A live population of candidate (x, y) points converging on the global minimum of a chosen benchmark function, with the fitness landscape rendered as a dark-to-light contour and convergence tracked on a log-scale chart.

🎮 How to use

Pick a Function (Rosenbrock, Rastrigin, Ackley), tune Population NP, Mutation F, and Crossover CR sliders, then hit ▶ Play or Step → to advance generations one at a time. Press R to restart or P to pause.

💡 Did you know?

DE needs no gradients at all — it infers useful search directions purely from the spread of vector differences inside its own population, which is why it handles noisy, discontinuous, black-box objectives that defeat calculus-based optimizers.

Frequently asked questions

Why does the algorithm need three random vectors per update?

Two of them (x_r2, x_r3) form a difference vector that encodes a plausible search direction and step size drawn from the population's current spread; the third (x_r1) anchors the mutant. This self-referential sampling is what lets DE adapt its step size automatically as the population converges.

What happens if I set CR close to 1.0?

Almost every dimension of the trial vector comes from the mutant rather than the target, so the search explores more aggressively — useful for separable, multimodal functions like Rastrigin but often slower to fine-tune the final minimum.

Why does Rosenbrock look easy on the contour but converge slowly?

Its curved valley is wide and clearly visible, so the population finds it in a handful of generations, but the valley floor near (1,1) is nearly flat in the direction of travel, so fitness improvements become tiny and the log-scale convergence line flattens out.

Why does population size (NP) matter?

A larger NP samples more difference vectors per generation, giving a richer set of mutation directions and reducing the risk of premature convergence on multimodal landscapes like Rastrigin, at the cost of more function evaluations per generation.

Can DE get stuck, and how would I see that here?

Yes — if diversity collapses too early the population std (shown in the Stats panel) drops near zero while best fitness stalls above the true minimum; raising F or CR, or restarting with a larger NP, usually restores progress.