BayesOpt
demo_rembo.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 % BayesOpt parameters
26 params.n_iterations = 200;
27 params.n_init_samples = 10;
28 params.crit_name = 'cEI';
29 params.surr_name = 'sStudentTProcessNIG';
30 params.noise = 1e-6;
31 params.kernel_name = 'kMaternARD5';
32 params.kernel_hp_mean = [1 1];
33 params.kernel_hp_std = [10 10];
34 params.verbose_level = 5;
35 params.log_filename = 'matbopt.log';
36 
37 fun = 'braninhighdim'; % the function has an effective 2D
38 n = 2; % number of low dims (effective)
39 nh = 1000; % number of actual dims
40 
41 global MATRIX_A % random proyection matrix
42 global TRUE_I % indexes of relevant components
43 
44 TRUE_I = [150,237];
45 
46 % Bounds of proyected (low-dim) space
47 lb = ones(n,1)*-sqrt(n);
48 ub = ones(n,1)*sqrt(n);
49 
50 % rembo iterations results
51 nrembo = 10; % number of rembo iterations
52 values = zeros(nrembo,1);
53 points = zeros(nrembo,n);
54 
55 for i=1:nrembo
56  disp('Running optimization');
57  MATRIX_A = randn(nh,n);
58 
59  tic;
60  [result, val, error] = bayesoptcont(fun,n,params,lb,ub);
61  toc;
62 
63  % We project the result back to the real low-dim space
64  hd_res = MATRIX_A*result';
65  points(i,:) = hd_res(TRUE_I)';
66  values(i) = val;
67 
68  fprintf('Opt point: %f, %f ||', hd_res(TRUE_I));
69  fprintf('Opt value: %f || Error: %d\n',val, error);
70 end;
71 
72 [foo,id] = min(values);
73 fprintf('Final point: %f, %f ||', points(id,:));
74 fprintf('Final value: %f\n',values(id));