Global minimization of a non-expensive scalar function
- Driver:
Download script: differential_evolution.m
The target of the study is to minimize a scalar function. The scalar function is assumed to be inexpensive to evaluate (i.e. evaluation time shorter than a second) and to have no known derivatives. In this case a heuristic global optimization is advisable. Differential evolution (DE) is an evolutionary optimization algorithm inspired by the mutation, crossover and selection processes occurring in nature.
As an example, the 2D Rastrigin function on a circular domain is minimized,
\[ \begin{align}\begin{aligned}&\text{min.}\,& f(x_1,x_2) = 2\cdot10 + \sum_{i=1,2} \left(x_i^2 - 10\cos(2\pi x_i)\right)\\&\text{s.t.}\,& \sqrt{x_1^2 + x_2^2} \leq 1.5.\end{aligned}\end{align} \]
1client = jcmoptimizer.Client();
2
3% Definition of the search domain
4design_space = { ...
5 struct('name', 'x1', 'type', 'continuous', 'domain', [-1.5,1.5]), ...
6 struct('name', 'x2', 'type', 'continuous', 'domain', [-1.5,1.5]) ...
7};
8
9% Definition of fixed environment parameter
10environment = {...
11 struct('name', 'radius', 'type', 'fixed', 'domain', 1.5) ...
12};
13
14% Definition of a constraint on the search domain
15constraints = {...
16 struct('name', 'circle', 'expression', 'sqrt(x1^2 + x2^2) <= radius')...
17};
18
19 % Creation of the study object with study_id 'differential_evolution'
20study = client.create_study( ...
21 'design_space', design_space, ...
22 'environment', environment, ...
23 'constraints', constraints,...
24 'driver','DifferentialEvolution',...
25 'study_name','Global minimization of a non-expensive scalar function',...
26 'study_id', 'differential_evolution');
27
28% Configure study parameters
29study.configure('max_iter', 80);
30
31% Evaluation of the black-box function for specified design parameters
32function observation = evaluate(study, sample)
33
34 observation = study.new_observation();
35 observation.add(10*2 ...
36 + (sample.x1^2 - 10*cos(2*pi*sample.x1)) ...
37 + (sample.x2^2 - 10*cos(2*pi*sample.x2)) ...
38 );
39
40end
41
42% Run the minimization
43study.set_evaluator(@evaluate);
44study.run();
45
46best = study.driver.best_sample;
47fprintf('Best sample at x1=%0.3e, x2=%0.3e\n', best.x1, best.x2)
48
49client.shutdown_server();