Global minimization of a non-expensive scalar function

Driver:

DifferentialEvolution

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} \]
 1jcm_optimizer_path = '<JCM_OPTIMIZER_PATH>';
 2addpath(fullfile(jcm_optimizer_path, 'interface', 'matlab'));
 3 
 4server = jcmoptimizer.Server();
 5client = jcmoptimizer.Client(server.port); 
 6
 7% Definition of the search domain
 8design_space = { ...
 9    struct('name', 'x1', 'type', 'continuous', 'domain', [-1.5,1.5]), ...
10    struct('name', 'x2', 'type', 'continuous', 'domain', [-1.5,1.5]) ...
11x};
12
13% Definition of fixed environment parameter
14environment = {...     
15   struct('name', 'radius', 'type', 'fixed', 'domain', 1.5) ...
16};
17
18% Definition of a constraint on the search domain
19constraints = {...
20   struct('name', 'circle', 'expression', 'sqrt(x1^2 + x2^2) <= radius')...
21};
22
23 % Creation of the study object with study_id 'differential_evolution'
24study = client.create_study( ...
25    'design_space', design_space, ...
26    'environment', environment, ...
27    'constraints', constraints,...
28    'driver','DifferentialEvolution',...
29    'name','Global minimization of a non-expensive scalar function',...
30    'study_id', 'differential_evolution');
31
32% Configure study parameters
33study.configure('max_iter', 80);
34
35% Evaluation of the black-box function for specified design parameters
36function observation = evaluate(study, sample)
37
38    observation = study.new_observation();
39    observation.add(10*2 ...
40                    + (sample.x1^2 - 10*cos(2*pi*sample.x1)) ...
41                    + (sample.x2^2 - 10*cos(2*pi*sample.x2)) ...
42                   );
43    
44end  
45
46% Run the minimization
47study.set_evaluator(@evaluate);
48study.run(); 
49
50best = study.driver.best_sample;
51fprintf('Best sample at x1=%0.3e, x2=%0.3e\n', best.x1, best.x2)