BayesOpt
demo_test.m
1 %
2 % -------------------------------------------------------------------------
3 % This file is part of BayesOpt, an efficient C++ library for
4 % Bayesian optimization.
5 %
6 % Copyright (C) 2011-2015 Ruben Martinez-Cantin <rmcantin@unizar.es>
7 %
8 % BayesOpt is free software: you can redistribute it and/or modify it
9 % under the terms of the GNU Affero General Public License as published by
10 % the Free Software Foundation, either version 3 of the License, or
11 % (at your option) any later version.
12 %
13 % BayesOpt is distributed in the hope that it will be useful, but
14 % WITHOUT ANY WARRANTY; without even the implied warranty of
15 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 % GNU Affero General Public License for more details.
17 %
18 % You should have received a copy of the GNU Affero General Public License
19 % along with BayesOpt. If not, see <http://www.gnu.org/licenses/>.
20 % ------------------------------------------------------------------------
21 %
22 clear all, close all
23 addpath('testfunctions')
24 
25 params.n_iterations = 190;
26 params.n_init_samples = 10;
27 params.crit_name = 'cEI';
28 params.surr_name = 'sStudentTProcessNIG';
29 params.noise = 1e-6;
30 params.kernel_name = 'kMaternARD5';
31 params.kernel_hp_mean = [1];
32 params.kernel_hp_std = [10];
33 params.verbose_level = 1;
34 params.log_filename = 'matbopt.log';
35 
36 
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 disp('Continuous optimization');
39 fun = 'branin'; n = 2;
40 lb = zeros(n,1);
41 ub = ones(n,1);
42 
43 tic;
44 bayesoptcont(fun,n,params,lb,ub)
45 toc;
46 disp('Press INTRO');
47 pause;
48 
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 disp('Discrete optimization');
51 % We still use branin
52 % The set of points must be numDimension x numPoints.
53 np = 100;
54 xset = repmat((ub-lb),1,np) .* rand(n,np) - repmat(lb,1,np);
55 
56 tic;
57 bayesoptdisc(fun, xset, params)
58 toc;
59 yset = zeros(np,1);
60 for i=1:np
61  yset(i) = feval(fun,xset(:,i));
62 end;
63 [y_min,id] = min(yset);
64 disp('Actual optimal');
65 disp(xset(:,id));
66 disp(y_min);
67 disp('Press INTRO');
68 pause;
69 
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 disp('Continuous optimization');
72 fun = 'hartmann'; n = 6;
73 lb = zeros(n,1);
74 ub = ones(n,1);
75 
76 tic;
77 bayesoptcont(fun,n,params,lb,ub)
78 toc;