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