-
Notifications
You must be signed in to change notification settings - Fork 3
/
bfoss.m
4359 lines (3644 loc) · 173 KB
/
bfoss.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ xsearch, fsearch, nevalss, exc, x_hist, f_hist, el_hist ] = ...
bfoss( level, f, xbest, max_or_min, xincr, x_hist, f_hist, xtype, ...
xlower, xupper, lattice_basis, varargin )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%% %%%%%%%%%%%%
%%%%%%%%%%%% BFOSS %%%%%%%%%%%%
%%%%%%%%%%%% %%%%%%%%%%%%
%%%%%%%%%%%% A BFO-compatible library of Search-Step functions %%%%%%%%%%%%
%%%%%%%%%%%% %%%%%%%%%%%%
%%%%%%%%%%%% M. Porcelli and Ph. L. Toint %%%%%%%%%%%%
%%%%%%%%%%%% %%%%%%%%%%%%
%%%%%%%%%%%% Version 1.0 (c) 2020 %%%%%%%%%%%%
%%%%%%%%%%%% %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 1. BFOSS, a BFO compatible library of search-step functions
%
% This file provides a library of search-step functions to be used with the BFO
% derivative-free optimization package. The current version of BFOSS includes
% - unstructured multivariate polynomial interpolation model of degree at most
% linear (for C^1 functions) or quadratic (for C^2 functions)
% - partially separable multivariate polynomial interpolation model of degree at
% most linear (for C^1 functions) or quadratic (for C^2 functions),
% from which a search step is then computed using a standard trust-region mechanism.
%
% The computation of the trial point xsearch and associated function value fsearch uses
% information on past function values and associated points (as computed by BFO or by
% previous calls to the library). This information is contained in the vectors f_hist
% (the past f-values) and x_hist (the associated points). Further information on the
% problem is also provided in that input arguments specify the variables' types and
% their bounds (if any). For discrete variables, the basis of the considered lattice
% is also supplied on input. Finally, element-wise structure, function values and
% points are supplied in the case where the function is partially separable, allowing
% the library to exploit this commonly occuring structure.
%
% NOTE: If the objective function is in elemental form, it ust use the (default) sum
% composition function for BFOSS to be applicable.
%
% A description of BFOSS and preliminary numerical results are available in Porcelli
% and Toint (2017b). BFO itself is described in Porcelli and Toint (2017a).
%
%% 2. Multivariate interpolation models
%
% When interpolation models are used, BFOSS uses the past function values and points
% to create an "interpolation set", which is used in turn to compute associated
% Lagrange polynomials. A linear combination of these polynomials is constructed
% to provide an interpolating polynomial IN THE CONTINUOUS VARIABLES, which can
% then to be minimized to find a trial point. (Note that discrete variables are
% considered fixed).
%
% This mechanism requires that Lagrange polynomials can be computed on the tentative
% interpolation set. This in turn imposes that the geometry of the points in this set
% is "poised" enough (meaning that each point brings additional information on the
% function). This is measured by computing the maximum absolute value of the Lagrange
% polynomials is the neighbourhood. If this value is small enough, the improvement
% in "poisedness" which would be obtained by exchanging a current interpolation point
% by the best possible candidate is relatively modest, and the set is the declared
% poised. However, for this value to be meaningfull, the Lagrange polynomials themselves
% must be reasonably accurate. As they are computed by solving a linear system
% (possibly in the generalized sense), this requires the system matrix to be not
% too ill-conditioned. The construction of the interpolating polynomial thus proceeds
% in four phases:
% 1) a tentative interpolation set is defined using past points/values as much as
% possible (in the limits of availability and for an at most quadratic model),
% 2) this set is corrected to ensure that the matrix defining the Lagrange polynomials
% is not too ill-conditioned,
% 3) it is possibly further improved by performing exchanges until the improvement
% in poisedness becomes moderate enough,
% 4) the same (reasonably conditioned) matrix is then used to define the linear
% combination of the Lagrange polynomials which interpolates function values at the
% interpolation points.
% Once available, the polynomial interpolant may be used as a model of the objective
% function and its value minimized to provide the trial step.
% Note that the degree of the interpolating polynomials (and associated Lagrange
% polynomials) may vary depending on how data points are chosen and how many elements
% in the monomial basis of the polynomials are considered. This later number may vary
% between 2 (the minimal non-constant mode) to ((n+1)*(n+2))/2 (the full quadratic).
%
% The use of multivariate interpolation models was pioneered by Winfield and, most
% proeminently, by Powell in the 1970's. The user is refered to Conn, Scheinberg
% and Vicente (2009) for a good introduction to this topic and its use in derivative-free
% methods. This book also contains an excellent bibliography.
%
% Importantly, the commonly occuring structure of partially separable functions
% (see Griewank and Toint (1982)) can be exploited to great advantage in model-based
% derivative-free methods. The idea (see Colson and Toint (2005)) is simply to
% construct a model whose structure mimics that of the original function, thereby
% supplying considerable additional information for its construction. A separate model
% is typically constructed for each "element function" of the considered partially
% separable decomposition, and these models are then assembled to form a global
% structured model. This is what BFOSS does, applying the techniques to compute an
% interpolation model to each element of the objective by restricting the analysis to
% its associated "element domain" (very often a small dimensional subspace).
%
%% 3. The trust_region mechanism
%
% When a model of the objective function is available (an interpolating polynomial),
% this model can the be minimized in a region around the current iterate where it
% is believed to be valid. This "trust-region" is a ball centered at the current
% best point and whose radius is updated from one call of BFOSS to the next (some
% information is saved by BFOSS in a few persistent variables). The trust-region
% mechanism used here is classical (see Conn, Gould and Toint (2000) for an extensive
% coverage of these methods.
%
% 4. References
%
% A. R. Conn, N. I. M. Gould and Ph. L. Toint, "Trust Region Methods", MPS-SIAM Series
% on Optimization, vol.1, SIAM, Philadelphia, 2000.
%
% A. R. Conn, K. Scheinberg and L. N. Vicente, "Introduction to Derivative-free
% Optimization", MPS-SIAM Series on Optimization, SIAM, Philadelphia, 2009.
%
% B. Colson and Ph. L. Toint, "Optimizing Partially Separable Functions Without
% Derivatives", Optimization Methods and Software, vol. 20(4-5), pp. 493-508, 2005.
%
% A. Griewank and Ph. L. Toint, "On the unconstrained optimization of partially
% separable functions", in "Nonlinear Optimization 1981" (M. J. D. Powell, ed.)
% Academic Press, London, pp. 301--312, 1982.
% M. Porcelli and Ph. L. Toint, "BFO, a trainable derivative-free Brute Force
% Optimizer for nonlinear bound-constrained optimization and equilibrium computations
% with continuous and discrete variables", Transactions of the AMS on Mathematical
% Software, vol. 44(1), 2017a.
%
% M. Porcelli and Ph. L. Toint, "Global and local information in structured derivative free
% optimization with BFO", in preparation, 2020.
%
%% 5. Arguments
%
% INPUT:
%
% level : the level from which BFO call the search-step function. If negative
% this signals that return from BFO to the user is imminent and that
% cleanup internal to BFOSS must be performed (no output value is
% expected in this case).
% f : the handle to the objective function.
% xbest : the current best point
% max_or_min : 'min' or 'max' depending on whether minimization or maximization
% xincr : the current mesh size needed to compute the current TR radius
% x_hist : an (n x min(nfcalls,l_hist)) array whose columns
% contain the min(nfcalls,l_hist)) points at which f(x) has been
% evaluated last.
% f_hist : an array of length nfcalls containing the function values
% associated with the columns of x_hist.
% xlower : the vector of lower bounds.
% xupper : the vector of upper bounds.
% indfree : a vector of current idices of free variables.
% nevalss : a scalar for the number of function evaluations in the search step
% function, computed so far.
% Delta : a scalar for the current trust-region radius
% verbosity : a string for the level of verbosity
% varargin : a (possibly empty) list of arguments.
% For the interpolation models, the first argument in varargin
% must be the element-wise history (el_hist), a cell of structs
% produced by BFO, when the problem is patially separable. All
% following arguments are specified by a (keyword, value) pair.
% The keyword is a string and the associated value immediately
% follows the keyword in varargin. Possible keywords and associated
% values are as follows.
% model-type : the type of model to use (for now, only 'interpolation')
% model-mode : the technique used to define the relation between the number
% of data points and the number of monomial basis elements for
% constructing the model:
% 'subbasis': the number of elements of the monomial basis is equal
% the number of interpolation points (monomials are
% ordered as follows: constant term, linear terms,
% diagonal quadratic terms, and finally off-diagonal
% quadratic terms by increasing subdiagonals.
% 'minell2' : the number of elements of the monomail basis is
% always equal to the number needed for a full quadratic,
% the (possibly underdetermined) linear system being then
% solved in the least-squares sense.
% Default: 'subbasis'
% minimum-model-degree: the minimum degree of the polynomial model:
% 'minimal' : at least two basis monomials are used,
% 'linear' : the constant and the n linear monomials are used,
% 'diagonal' : idem + the diagonal quadratic terms,
% 'quadratic': idem + the off-diagonal quadratic terms.
% Default: 'minimal'.
% maximum-model-degree: the maximal model degree at any iteration:
% 'linear' : the constant and the n linear monomials are used,
% 'diagonal' : idem + the diagonal quadratic terms,
% 'quadratic': idem + the off-diagonal quadratic terms.
% Default: 'quadratic'.
% conditioning-limit: a real number >= 1 specifying the maximum admissible
% conditioning for the interpolation matrix
% Default: 1e14.
% poisedness-limit : a positive real number specifying an upper bound on the Lagrange
% polynomial in the trust region for declaring the interpolation poised
% Default: 100.
% neighbourhood-limit: a real number >= 1 specifying the multiple of the trust
% region radius beyond which points aare considered too far to be
% relevant for the current interpolation model.
% Default: 10.
% far-point-acceptability: a real (>1) specifyin the minimum improvement in poisedness
% required for including points in the history in the interpolation set,
% Default: 100.
% TR-init-radius: a positive real specifying the initial trust-region radius,
% or a negative number for an automatic choice (not always optimal),
% Default: -1 (automatic)
% TR-min-radius: a positive real specifying the trust-region radius under which no
% search step is computed,
% Default: 1e-8
% TR-max-radius: a positive real specifying the maximal trust-region radius,
% Default: 100.
% TR-accuracy : a positive real specifying the accuracy at which the trust-region
% constraint must be satisfied,
% Default: 1e-3.
% TR-eta1 : the threshold on rho for successful iterations
% Default: 0.05.
% TR-eta2 : the threshold on rho for very successful iterations
% Default: 0.9.
% TR-alpha1 : the TR expansion factor at very successful iterations
% Default: 2.5.
% TR-alpha2 : the TR contraction factor at unsuccessful iterations
% Default: 0.25.
% TR-solver-step: the solver for the trust-region subproblem defining the
% search step. Possible choices are
% 'more-sorensen' : a bound-constrained variant of the Moré-Sorensen
% TR algorithm
% 'ptcg' : a projected truncated conjugate gradient method
% Default: 'more-sorensen'
% TR-solver-Lagrange: the solver for the trust-region subproblems involving the
% Lagrange polynomials. Possible choices are
% 'more-sorensen' : a bound-constrained variant of the Moré-Sorensen
% TR algorithm
% 'ptcg' : a projected truncated conjugate gradient method
% Default: 'more-sorensen'
% TR_PTCG_rel_acc: the relative accuracy on the projected gradient to terminate
% the projected truncated CG
% 'Default: 1e-5.
% TR_PTCG_abs_acc: the absolute accuracy on the projected gradient to terminate
% the projected truncated CG
% 'Default: 1e-10.
% TR_PTCG_maxcgits : the maximum number of CG iterations allowed in the TR problem
% solution, relative to dimension.
% Default: 3.
% termination-order: the order of the critical point requested on the model
% for the search-step function to indicate termination to BFO:
% '1rst' : checks that the model's gradient norm is below epsilon
% '2nd' : additionnaly checks that
% for minimization: the smallest eigenvalue of the models'
% Hessian is above -sqrt( epsilon )
% for maximization: the largest eigenvalue of the models'
% Hessian is below sqrt( epsilon );
% Using '1rst' results in (usually marginally) faster termination, at
% the expense of accuracy.
% Default: '2nd'.
% epsilon : the accuracy used for model-based termination
% Default: 1e-5.
% min-step-length: the minimum length of the step for computing the trial
% function value,
% Default: 1e-10.
% verbosity : a string specifying the verbosity of the search-step finding process
% Possible values are 'silent', 'low', 'medium' and 'debug' .
% Default: 'low'.
%
% OUTPUT:
%
% xsearch : an array of length n containing the point returned by the
% user as a tentative improved iterate,
% fsearch : the associated objective function value f(xsearch)
% nevalss : the number of function evaluations performed internally by the
% search-step function.
% exc : the search-step exit code.
% exc = 3: seemingly at optimum: the search-step function has determined
% that the base point appears to be optimal (xsearch and fsearch
% are to be ignored in this case);
% exc = 2: normal successful return: a search-step xsearch and associated
% function value fsearch has been found, which produces significant
% objective function improvement;
% exc = 1: normal unusuccessful return: a search-step xsearch and associated
% fsearch have been calculated, but do not produce significant
% objective function improvement;
% exc = 0: the search step function has found a point xsearch and a value
% fsearch, but leaves to BFO the decision to use it or not;
% exc = -1: the search-step function could not reliably compute a search step,
% and the returned xsearch and fsearch should be ignored;
% exc = -2: the objective function returned a NaN or infinite value: the
% returned xsearch and fsearch should be ignored;
% exc = -3: the user has requested termination: the returned xsearch and
% fsearch should be ignored.
% x_hist : is the updated array or cell array to which is now appended the set of
% vectors at which the objective function has been evaluated
% (xsearch = x_hist( 1:n,end)).
% f_hist : the updated array of function values (f_search = f_hist(end)).
% el_hist : the cell array containing the updated structs (for all element function
% evaluations during the search-step computation).
%
% 6. Software issues
%
% DEPENDENCIES : bfoss_search_step_interp_model, bfoss_search_step_interp_model_ps
%
% PROGRAMMING : M. Porcelli and Ph. Toint, March 2017 to 2020
% (this version 13 I 2020).
%
%% RESTRICTIONS
%
% In the present version, BFOSS does not support
% - categorical variables
% - functions defined with a 'with-bound' interface.
% Note that discrete variables are considered as fixed for the computation
% of the search step.
%
%% CONDITIONS OF USE
% *** Use at your own risk! No guarantee of any kind given or implied. ***
% Copyright (c) 2020, Ph. Toint and M. Porcelli. All rights reserved.
%
% Redistribution and use of the BFO package and the BFOSS library in source and
% binary forms, with or without modification, are permitted provided that the
% following conditions are met:
%
% * Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% +-------------------------------------------------------------------------+
% | |
% | DISCLAIMER |
% | |
% | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
% | "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
% | LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
% | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
% | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
% | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
% | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
% | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
% | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
% | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
% | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
% | DAMAGE. |
% | |
% +-------------------------------------------------------------------------+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set default values for output arguments.
xsearch = [];
fsearch = [];
nevalss = -1;
exc = -1;
% Set default basic values.
model_type = 'interpolation'; % for now the only model type avaialble
verbosity = 'low'; % the verbosity of the search-step finding process
% Now verify if the problem is in elemental form. Also define varg1, the position
% (in varargin) of the keyword of the first ( keyword, value ) pair.
varg1 = 1;
if ( iscell( f ) && ~isempty( varargin ) )
el_hist = varargin{ 1 };
elemental_form = 1;
varg1 = 2;
end
if ( varg1 == 1 )
elemental_form = 0;
el_hist = [];
end
% Set the default algorithmic parameters depending on model type and elemental-form.
switch ( model_type )
case 'interpolation'
[ model_mode, minimum_model_degree, maximum_model_degree, kappa_ill, poisedupper, ...
toofarlimit, farthr, term_order, epsilon, TR_init_radius, TR_min_radius, ...
TR_max_radius, TR_accuracy, TR_eta1, TR_eta2, TR_alpha1, TR_alpha2, TR_solver_step, ...
TR_solver_Lagr, TR_PTCG_rel_acc, TR_PTCG_abs_acc, TR_PTCG_maxcgits,min_step_length ] =...
bfoss_interpolation_default_parameters( elemental_form );
end
% See if this is the termination call, in which case all input arguments except level
% are meaningless.
if ( level >= 0 )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Interpret the optional arguments %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Extract verbosity first, if specified.
nargs = size( varargin, 2 );
for i = varg1:nargs
if ( ischar( varargin{i} ) && strcmp( varargin{i}, 'verbosity' ) )
if ( i < nargs && ischar( varargin{i+1} ) )
switch ( varargin{i+1} )
case 'silent'
verbosity = 'silent';
case 'low'
verbosity = 'low';
case 'medium'
verbosity = 'medium';
case 'debug'
verbosity = 'debug';
otherwise
disp( ' BFOSS error: Unknow verbosity. Using default.' )
end
else
disp( ' BFOSS error: the argument list is ill-constructed. Terminating.' )
nevalss = -1;
return
end
break
end
end
% Process the rest of the variable argument list.
for i = varg1:2:nargs
wrongkey = '';
if ( ischar( varargin{ i } ) && nargs > i )
switch ( varargin{ i } )
% The type of the model used
case 'model-type'
if ( ischar( varargin{ i+1 } ) )
switch( varargin{ i+1 } )
case 'interpolation'
otherwise
wrongkey = 'model-type';
end
else
wrongkey = 'model-type';
end
% The model mode, if any.
case 'model-mode'
if ( ischar( varargin{ i+1 } ) )
switch( varargin{ i+1 } )
case 'subbasis'
model_mode = 'subbasis';
case 'minell2'
model_mode = 'minell2';
otherwise
wrongkey = 'model-mode';
end
else
wrongkey = 'model-mode';
end
% The minimum model degree (for interpolation)
case 'minimum-model-degree'
if ( ischar( varargin{ i+1 } ) )
switch( varargin{ i+1 } )
case 'minimal'
minimum_model_degree = 'minimal';
case 'linear'
minimum_model_degree = 'linear';
case 'diagonal'
minimum_model_degree = 'diagonal';
case 'quadratic'
minimum_model_degree = 'quadratic';
otherwise
wrongkey = 'minimum-model-degree';
end
else
wrongkey = 'minimum-model-degree';
end
% The maximum model degree (for interpolation)
case 'maximum-model-degree'
if ( ischar( varargin{ i+1 } ) )
switch( varargin{ i+1 } )
case 'linear'
maximum_model_degree = 'linear';
case 'diagonal'
maximum_model_degree = 'diagonal';
case 'quadratic'
maximum_model_degree = 'quadratic';
otherwise
wrongkey = 'max-model-degree';
end
else
wrongkey = 'max-model-degree';
end
% The upper bound on the interpolation matrix conditioning
case 'conditioning-limit'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num) ) == 1 && num >= 1 )
kappa_ill = num;
else
wrongkey = 'conditioning-limit';
end
else
wrongkey = 'conditioning-limit';
end
% The upper bound on the Lagrange polynomial in the
% trust region for declaring interpolation poised
case 'poisedness-limit'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num) ) == 1 && num >= 0 )
poisedupper = num;
else
wrongkey = 'poisedness-limit';
end
else
wrongkey = 'poisedness-limit';
end
% The multiple of the TR radius beyond which points are considered too far
% to be included in the interpolation set
case 'neighbourhood-limit'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num) ) == 1 && num >= 1 )
toofarlimit = num;
else
wrongkey = 'neighbourhood-limit';
end
else
wrongkey = 'neighbourhood-limit';
end
% The minimum improvement in poisedness required for
% including points in the history in the interpolation set
case 'far-point-acceptability'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num ) ) == 1 && num >= 0 )
farthr = num;
else
wrongkey = 'far-point-acceptability';
end
else
wrongkey = 'far-point-acceptability';
end
% The order of the critical point for model-based termination
case 'termination-order'
if ( ischar( varargin{ i+1 } ) )
switch( varargin{ i+1 } )
case '1rst'
term_order = '1rst';
case '2nd'
term_order = '2nd';
otherwise
wrongkey = 'termination-order';
end
else
wrongkey = 'termination-order';
end
% The initial trust-region radius
case 'TR-init-radius'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num ) ) == 1 && num > 0 )
TR_init_radius = num;
else
wrongkey = 'TR-init-radius';
end
else
wrongkey = 'TR-init-radius';
end
% The minimal trust-region radius for modelling to take place.
case 'TR-min-radius'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num ) ) == 1 && num > 0 )
TR_min_radius = num;
else
wrongkey = 'TR-min-radius';
end
else
wrongkey = 'TR-min-radius';
end
% The maximum allowed radius for the trust region
case 'TR-max-radius'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num ) ) == 1 && num > 0 )
TR_max_radius = num;
else
wrongkey = 'TR-max-radius';
end
else
wrongkey = 'TR-max-radius';
end
% The required accuracy on the trsut-region constraint
case 'TR-accuracy'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num ) ) == 1 && num > 0 )
TR_accuracy = num;
else
wrongkey = 'TR-accuracy';
end
else
wrongkey = 'TR-accuracy';
end
% The TR threshold for successful iterations
case 'TR-eta1'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num ) ) == 1 && num > 0 )
TR_eta1 = num;
else
wrongkey = 'TR-eta1';
end
else
wrongkey = 'TR-eta1';
end
% The TR threshold for very successful iterations
case 'TR-eta2'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num ) ) == 1 && num > 0 )
TR_eta2 = num;
else
wrongkey = 'TR-eta2';
end
else
wrongkey = 'TR-eta2';
end
% The TR expansion factor at very successful iterations
case 'TR-alpha1'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num ) ) == 1 && num > 0 )
TR_alpha1 = num;
else
wrongkey = 'TR-alpha1';
end
else
wrongkey = 'TR-alpha1';
end
% The TR contraction factor at unsuccessful iterations
case 'TR-alpha2'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num ) ) == 1 && num > 0 )
TR_alpha2 = num;
else
wrongkey = 'TR-alpha2';
end
else
wrongkey = 'TR-alpha2';
end
% The solver for the step TR subproblem
case 'TR-solver-step'
if ( ischar( varargin{ i+1 } ) )
switch ( varargin{ i+1 } )
case 'more-sorensen'
TR_solver_step = 'more-sorensen';
case 'ptcg'
TR_solver_step = 'ptcg';
otherwise
wrongkey = 'TR-solver-step';
end
else
wrongkey = 'TR-solver-step';
end
% The solver for the Lagrange TR subproblems
case 'TR-solver-Lagrange'
if ( ischar( varargin{ i+1 } ) )
switch ( varargin{ i+1 } )
case 'more-sorensen'
TR_solver_Lagr = 'more-sorensen';
case 'ptcg'
TR_solver_Lagr = 'ptcg';
otherwise
wrongkey = 'TR-solver-Lagrange';
end
else
wrongkey = 'TR-solver-Lagrange';
end
% The relative accuracy on the projected gradient for terminating the PTCG
case 'TR-PTCG-relative-acuracy'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num ) ) == 1 && num > 0 && num < 1 )
TR_PTCG_rel_acc = num;
else
wrongkey = 'TR-PTCG-relative-accuracy';
end
else
wrongkey = 'TR-PTCG-relative-accuracy';
end
% The absolute accuracy on the projected gradient for terminating the PTCG
case 'TR-PTCG-absolute-acuracy'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num ) ) == 1 && num > 0 && num < 1 )
TR_PTCG_abs_acc = num;
else
wrongkey = 'TR-PTCG-absolute-accuracy';
end
else
wrongkey = 'TR-PTCG-absolute-accuracy';
end
% The maximum number of CG iterations in PTCG, relative to problem size
case 'TR-PTCG-maxcgits'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num ) ) == 1 && num > 0 )
TR_PTCG_maxcgits = ceil( num );
else
wrongkey = 'TR-PTCG-maxcgits';
end
else
wrongkey = 'TR-PTCG-maxcgits';
end
% The minimum steplength for computing f at the trial point
case 'min-step-length'
if ( isnumeric( varargin{ i+1 } ) )
num = varargin{ i+1 };
if ( max( size( num ) ) == 1 && num > 0 )
min_step_length = num;
else
wrongkey = 'min-step-length';
end
else
wrongkey = 'min-step-length';
end
% The process verbosity (already handled above)
case 'verbosity'
% Wrong keyword
otherwise
if ( ~strcmp( verbosity, 'silent' ) )
disp( [ ' BFOSS warning: Unknown ', int2str( i ) ,'-th keyword. Ignoring.' ] )
end
end
if ( ~isempty( wrongkey ) )
if ( ~strcmp( verbosity, 'silent' ) )
disp( [ ' BFOSS warning: Incorrect value for keyword ', wrongkey, ...
'. Default used.' ] )
end
end
else
if ( ~strcmp( verbosity, 'silent' ) )
disp( ' BFOSS error: the argument list is ill-constructed. Terminating.' )
end
nevalss = -1;
return
end
end
end
% Verify that the minimal trust-region radius is large enough for the quadratic terms
% in the interpolation matrix to be above underflow.
TR_min_radius = 10 * max( sqrt( eps ), TR_min_radius );
% Consider the different model types (to be completed in the future)
switch( model_type )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Interpolation models %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'interpolation'
% Verify the coherence of the interpolation degrees.
if ( strcmp( maximum_model_degree, 'linear' ) )
if ( ismember( minimum_model_degree, { 'diagonal', 'quadratic' } ) )
minimum_model_degree = 'linear';
end
elseif ( strcmp( maximum_model_degree, 'diagonal' ) )
if ( strcmp( minimum_model_degree, 'quadratic' ) )
minimum_model_degree = 'diagonal';
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The elemental-form case
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ( elemental_form )
[ xsearch, fsearch, nevalss, exc, x_hist, f_hist, el_hist ] = ...
bfoss_search_step_interp_model_sf( level, f, xbest, max_or_min, xincr, x_hist, ...
f_hist, xtype, xlower, xupper, el_hist, model_mode, ...
minimum_model_degree, maximum_model_degree, ...
kappa_ill, toofarlimit, poisedupper, farthr, ...
TR_init_radius, TR_min_radius, TR_max_radius, ...
TR_accuracy, TR_eta1, TR_eta2, TR_alpha1,TR_alpha2, ...
TR_solver_step, TR_solver_Lagr, TR_PTCG_rel_acc, ...
TR_PTCG_abs_acc, TR_PTCG_maxcgits, term_order, epsilon,...
min_step_length, verbosity );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The non-partially-separable case
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
else
[ xsearch, fsearch, nevalss, exc, x_hist, f_hist ] = ...
bfoss_search_step_interp_model( level, f, xbest, max_or_min, xincr, x_hist, ...
f_hist, xtype, xlower, xupper, model_mode, ...
minimum_model_degree, maximum_model_degree, ...
kappa_ill, toofarlimit, poisedupper, farthr, ...
TR_init_radius, TR_min_radius, TR_max_radius, ...
TR_accuracy, TR_eta1, TR_eta2, TR_alpha1, ...
TR_alpha2, TR_solver_step, TR_solver_Lagr, ...
TR_PTCG_rel_acc, TR_PTCG_abs_acc, ...
TR_PTCG_maxcgits, term_order, epsilon, ...
min_step_length, verbosity );
end
end
return
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ xsearch, fsearch, nevalss, exc, x_hist, f_hist ] = ...
bfoss_search_step_interp_model( level, f, xbest, max_or_min, xincr, x_hist, ...
f_hist, xtype, xlower, xupper, model_mode, ...
minimum_model_degree, maximum_model_degree, ...
kappa_ill, toofarlimit, poisedupper, farthr, ...
TR_init_radius, TR_min_radius, TR_max_radius, ...
TR_accuracy, TR_eta1, TR_eta2, TR_alpha1, ...
TR_alpha2, TR_solver_step, TR_solver_Lagr, ...
TR_PTCG_rel_acc, TR_PTCG_abs_acc, ...
TR_PTCG_maxcgits, term_order, epsilon, ...
min_step_length, verbosity )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Compute a tentative improved point from an interpolation model using available points,
% by minimizing this model in a trust region whose radius is remembered from one call to
% the next and updated.
%
% INPUT:
%
% level : the level of the current optimization (in BFO),
% f : is the handle to the objective function,
% xbest : is the vector of the current best point,
% max_or_min : 'min' or 'max' depending on whether minimization or maximization
% xincr : the current mesh size needed to compute the current trust-region radius
% x_hist : x_hist is an (n x min(nfcalls,l_hist)) array whose columns contain the
% min(nfcalls,l_hist)) points at which f(x) has been evaluated last
% f_hist : is an array of length nfcalls containing the function values associated
% with the columns of x_hist,
% xtype : a string of length n, defining the type of the variables,
% xlower : is the vector of lower bounds,
% xupper : is the vector of upper bounds,
% model_mode : the technique used to define the relation between the number
% of data points and the number of monomial basis elements for
% constructing the model:
% 'subbasis': the number of elements of the monomial basis is equal
% the number of interpolation points (monomials are
% ordered as follows: constant term, linear terms,
% diagonal quadratic terms, and finally off-diagonal
% quadratic terms by increasing subdiagonals.
% 'minell2' : the number of elements of the monomail basis is
% always equal to the number needed for a full quadratic,
% the (possibly underdetermined) linear system being then
% solved in the least-squares sense.
% minimum_model_degree: the minimum degree of the model
% 'minimal' : at least two basis monomials are used,
% 'linear' : the constant and the n linear monomials are used
% 'diagonal' : + the diagonal quadratic terms
% 'quadratic': + the off-diagonal quadratic terms
% maximum_model_degree : the maximum degree of the model:
% 'linear' : the constant and the n linear monomials are used
% 'diagonal' : + the diagonal quadratic terms
% 'quadratic': + the off-diagonal quadratic terms
% kappa_ill : a positive real number specifying the maximum consitioning allowed
% for the interpolation matrix
% toofarlimit : a real number larger than 1 specifying the multiple of the TR radius
% beyond which points are considered irrelevant for interpolation
% poisedupper : a positive real number specifying an upper bound on the Lagrange
% polynomial in the trust region for declaring the interpolation poised
% farthr : a real (>1) specifyin the minimum improvement in poisedness
% required for including points in the history in the interpolation set
% TR_init_radius : the initial trust-region-radius, or a negative number if it should
% be chosen as norm( xincr, 'inf')
% TR_min_radius : a positive real specifying the trust-region radius under which no
% search step is computed
% TR_max_radius : a positive real specifying the maximal trust-region radius
% TR_accuracy : a positive real specifying the accuracy at which the trust-region
% constraint must be satisfied
% TR_eta1 : the threshold on rho for successful iterations
% TR_eta2 : the threshold on rho for very successful iterations
% TR_alpha1 : the TR expansion factor at very successful iterations
% TR_alpha2 : the TR contraction factor at unsuccessful iterations
% TR_solver_step : the TR solver for computing the search step ('more-sorensen' or 'ptcg')
% TR_solver_Lagr : the TR solver for optimizing the Lagrange polynomials
% ('more-sorensen' or 'ptcg')
% TR_PTCG_rel_acc: the relative projected gradient accuracy for PTCG termination
% TR_PTCG_abs_acc: the absolute projected gradient accuracy for PTCG termination
% TR_PTCG_maxcgits: the maximum number of CG iterations in PTCG relative to problem size
% term_order : the order of the critical point requested on the model
% for the search-step function to indicate termination to BFO:
% '1rst' : checks that the model's gradient norm is below epsilon
% '2nd' : additionnaly checks that the smallest eigenvalue of
% the models' Hessian is above -sqrt( epsilon );
% epsilon : the accuracy used for maodel-based termination
% min_step_length: the minimum length of the step for computing the trial
% function value,
% verbosity : a string for the level of verbosity. Possible values are
% 'silent', 'low', 'medium', 'debug'.
%
% OUTPUT:
%
% xsearch : is an array of length n containing the point returned by the
% user as a tentative improved iterate,
% fsearch : the associated objective function value f(xsearch)
% nevalss : the number of function evaluations performed internally by the
% search-step function.
% exc : the search-step exit code.
% exc = 3: seemingly at optimum: the search-step function has determined
% that the base point appears to be optimal (xsearch and fsearch
% are to be ignored in this case);
% exc = 2: normal successful return: a search-step xsearch and associated
% function value fsearch has been found, which produces significant
% objective function improvement;
% exc = 1: normal unusuccessful return: a search-step xsearch and associated
% fsearch have been calculated, but do not produce significant
% objective function improvement;
% exc = 0: the search step function has found a point xsearch and a value
% fsearch, but leaves to BFO the decision to use it or not;
% exc = -1: the search-step function could not reliably compute a search step,
% and the returned xsearch and fsearch should be ignored;
% exc = -2: the objective function returned a NaN or infinite value: the
% returned xsearch and fsearch should be ignored;
% exc = -3: the user has requested termination: the returned xsearch and
% fsearch should be ignored.
% x_hist : is the updated array or cell array to which is now appended the set of
% vectors at which the objective function has been evaluated
% (xsearch = x_hist( 1:n,end)).
% f_hist : is the updated array of function values (f_search = f_hist(end)).
%