Gradient-based minimization of a non-expensive scalar function

Driver:

ScipyMinimizer

Download script: scipy_minimization.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 known derivatives. In this case a global optimization can be performed by a set of gradient-based local optimizations starting at different initial points. We start independent minimizations from six initial points (num_initial=6) and allow for two parallel evaluations of the objective function (num_parallel=2).

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]) ...
11};
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 'scipy_minimization'
24study = client.create_study( ...
25    'design_space', design_space, ...
26    'environment', environment, ...
27    'constraints', constraints,...
28    'driver','ScipyMinimizer',...
29    'name','Gradient-based minimization of a non-expensive scalar function',...
30    'study_id', 'scipy_minimization');
31
32study.configure('max_iter', 30, 'num_initial', 6, 'jac', true, 'method', 'SLSQP');
33
34% Evaluation of the black-box function for specified design parameters
35function observation = evaluate(study, sample)
36
37    observation = study.new_observation();
38    observation.add(10*2 ...
39                    + (sample.x1^2 - 10*cos(2*pi*sample.x1)) ...
40                    + (sample.x2^2 - 10*cos(2*pi*sample.x2)) ...
41                   );
42    observation.add(2*sample.x1 + 2*pi*sin(2*pi*sample.x1), ...
43                    'derivative', 'x1');
44    observation.add(2*sample.x2 + 2*pi*sin(2*pi*sample.x2), ...
45                    'derivative', 'x2');     
46    
47end  
48
49% Run the minimization
50study.set_evaluator(@evaluate);
51study.run(); 
52
53best = study.driver.best_sample;
54fprintf('Best sample at x1=%0.3e, x2=%0.3e\n', best.x1, best.x2)