Ruben Martinez-Cantin avatar Ruben Martinez-Cantin committed 56977ed

Bug solved in some demos and Aopt. Added REEMBO demo in matlab.

Comments (0)

Files changed (17)

   par.noise = DEFAULT_NOISE;
   par.surr_name = "sStudentTProcessJef";
   par.kernel.name = "kSum(kSEISO,kConst)";
-  par.mean.name = "mSum(mConst,mConst)";
+  par.mean.name = "mSum(mLinear,mConst)";
   par.l_type = L_ML;
   par.n_iterations = 200;       // Number of iterations
   par.n_init_samples = 50;

app/bo_display.cpp

   size_t dim = 1;
   bopt_params parameters = initialize_parameters_to_default();
   parameters.n_init_samples = 10;
-  parameters.n_iter_relearn = 10;
+  parameters.n_iter_relearn = 0;
   parameters.n_iterations = 300;
   parameters.verbose_level = 2;
 
   // Surrogate models
-  //parameters.surr_name = "sStudentTProcessNIG";
+  //  parameters.surr_name = "sStudentTProcessNIG";
   parameters.surr_name = "sGaussianProcessNormal";
 
-  // Criterion models
-  // parameters.crit_name = "cEI";
-  // parameters.crit_params[0] = 1;
-  parameters.crit_name = "cLCB";
-  parameters.crit_params[0] = 5;
+  // Criterion model
+  parameters.crit_name = "cAopt";
+  parameters.n_crit_params = 0;
+
+  parameters.crit_name = "cEI";
+  parameters.crit_params[0] = 1;
   parameters.n_crit_params = 1;
 
+  // parameters.crit_name = "cLCB";
+  // parameters.crit_params[0] = 5;
+  // parameters.n_crit_params = 1;
+
   // Kernel models
-  parameters.kernel.name = "kSum(kPoly3,kRQISO)";
-  double mean[128] = {1, 1, 1, 1};
-  double std[128] = {5, 5, 5, 5};
-  size_t nhp = 4;
-  memcpy(parameters.kernel.hp_mean, mean, nhp * sizeof(double));
-  memcpy(parameters.kernel.hp_std,std, nhp * sizeof(double));
-  parameters.kernel.n_hp = nhp;
+  // parameters.kernel.name = "kSum(kPoly3,kRQISO)";
+  // double mean[128] = {1, 1, 1, 1};
+  // double std[128] = {10, 10, 10, 10};
+  // size_t nhp = 4;
+  // memcpy(parameters.kernel.hp_mean, mean, nhp * sizeof(double));
+  // memcpy(parameters.kernel.hp_std,std, nhp * sizeof(double));
+  // parameters.kernel.n_hp = nhp;
 
-  // parameters.kernel.name = "kSEISO";
-  // parameters.kernel.hp_mean[0] = 1;
-  // parameters.kernel.hp_std[0] = 5;
-  // parameters.kernel.n_hp = 1;
+  parameters.kernel.name = "kMaternISO3";
+  parameters.kernel.hp_mean[0] = 1;
+  parameters.kernel.hp_std[0] = 5;
+  parameters.kernel.n_hp = 1;
 
 
 

include/criteria_atomic.hpp

     int setParameters(const vectord &params) { return 0; };
     size_t nParameters() {return 0;};
     double operator()( const vectord &x)
-    { return mProc->prediction(x)->getStd(); };
+    { return -mProc->prediction(x)->getStd(); };
     std::string name() {return "cAopt";};
   };
 

include/parameters.h

   /*************************************************************/
   /* These functions are added to simplify wrapping code       */
   /*************************************************************/
-  surrogate_name str2surrogate (const char* name);
+  /* surrogate_name str2surrogate (const char* name); */
   learning_type  str2learn     (const char* name);
 
-  BAYESOPT_API const char* surrogate2str(surrogate_name name);
+  /* BAYESOPT_API const char* surrogate2str(surrogate_name name); */
   BAYESOPT_API const char* learn2str(learning_type name);
 
   BAYESOPT_API bopt_params initialize_parameters_to_default(void);

matlab/bayesoptextras.h

 static void struct_string(const mxArray *s, const char *name, char* result)
 {
   mxArray *val = mxGetField(s, 0, name);
+  char *valstr;
 
   if (val) {
     if( mxIsChar(val) ) {
-      result = mxArrayToString(val);
+      if ( mxGetString(val, result, 1+(mxGetM(val) * mxGetN(val)))) {
+	  mexErrMsgTxt("Error loading string.");
+	}
     } else {
       mexErrMsgTxt("Method name must be a string");
     }

matlab/demo_reembo.m

+% 
+% -------------------------------------------------------------------------
+%    This file is part of BayesOpt, an efficient C++ library for 
+%    Bayesian optimization.
+%
+%    Copyright (C) 2011-2013 Ruben Martinez-Cantin <rmcantin@unizar.es>
+%
+%    BayesOpt is free software: you can redistribute it and/or modify it 
+%    under the terms of the GNU General Public License as published by
+%    the Free Software Foundation, either version 3 of the License, or
+%    (at your option) any later version.
+%
+%    BayesOpt is distributed in the hope that it will be useful, but 
+%    WITHOUT ANY WARRANTY; without even the implied warranty of
+%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%    GNU General Public License for more details.
+%
+%    You should have received a copy of the GNU General Public License
+%    along with BayesOpt.  If not, see <http://www.gnu.org/licenses/>.
+% ------------------------------------------------------------------------
+%
+clear all, close all
+addpath('testfunctions')
+
+params.n_iterations = 300;
+params.n_init_iterations = 50;
+params.crit_name = 'cEI';
+params.surr_name = 'sGaussianProcessNormal';
+params.noise = 0.005;
+params.kernel_name = 'kMaternISO3';
+params.kernel_hp_mean = [0.5];
+params.kernel_hp_std = [10];
+params.verbose_level = 0;
+params.log_filename = 'matbopt.log';
+
+n = 2;          % number of low dims (effective)
+nh = 1000;      % number of actual dims
+nreembo = 10;    % number of reembo iterations
+
+
+global MATRIX_A
+
+lb = ones(n,1)*-sqrt(n);
+ub = ones(n,1)*sqrt(n);
+fun = 'braninhighdim';    % the function has an effective 2D
+values = zeros(nreembo,1);
+points = zeros(nreembo,n);
+
+for i=1:nreembo
+    disp('Continuous optimization');
+    MATRIX_A = randn(nh,n);
+    tic;
+    result = bayesopt(fun,n,params,lb,ub);
+    toc;
+
+    values(i) = braninhighdim(result);
+    hd_res = MATRIX_A*result';
+    points(i,:) = hd_res(1:2)';
+    disp(hd_res(1)); disp(hd_res(2)); disp(values(i));
+end;
+
+[foo,id] = min(values);
+disp(points(id,:));
 params.n_iterations = 100;
 params.n_init_iterations = 50;
 params.crit_name = 'cEI';
-params.surr_name = 'GAUSSIAN_PROCESS';
+params.surr_name = 'sGaussianProcessNormal';
 params.noise = 0.005;
 params.kernel_name = 'kMaternISO3';
 params.kernel_hp_mean = [0.5];
 params.kernel_hp_std = [10];
-params.verbose_level = 1;
+params.verbose_level = 0;
 params.log_filename = 'matbopt.log';
 
-n = 5;
+% n = 5;
+% lb = ones(n,1)*pi/2;
+% ub = ones(n,1)*pi;
+% fun = 'michalewicz';
 
-lb = ones(n,1)*pi/2;
-ub = ones(n,1)*pi;
-fun = 'michalewicz';
+n = 2;
+lb = zeros(n,1);
+ub = ones(n,1);
+fun = 'branin';
 
 disp('Continuous optimization');
 tic;

matlab/testfunctions/ackley.m

+% 
+% -------------------------------------------------------------------------
+%    This file is part of BayesOpt, an efficient C++ library for 
+%    Bayesian optimization.
+%
+%    Copyright (C) 2011-2013 Ruben Martinez-Cantin <rmcantin@unizar.es>
+%
+%    BayesOpt is free software: you can redistribute it and/or modify it 
+%    under the terms of the GNU General Public License as published by
+%    the Free Software Foundation, either version 3 of the License, or
+%    (at your option) any later version.
+%
+%    BayesOpt is distributed in the hope that it will be useful, but 
+%    WITHOUT ANY WARRANTY; without even the implied warranty of
+%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%    GNU General Public License for more details.
+%
+%    You should have received a copy of the GNU General Public License
+%    along with BayesOpt.  If not, see <http://www.gnu.org/licenses/>.
+% ------------------------------------------------------------------------
+%
+
 function y = ackley(x)
 % Bounds -32.768, 32.768
 % Min x = zeros, y = 0

matlab/testfunctions/branin.m

+% 
+% -------------------------------------------------------------------------
+%    This file is part of BayesOpt, an efficient C++ library for 
+%    Bayesian optimization.
+%
+%    Copyright (C) 2011-2013 Ruben Martinez-Cantin <rmcantin@unizar.es>
+%
+%    BayesOpt is free software: you can redistribute it and/or modify it 
+%    under the terms of the GNU General Public License as published by
+%    the Free Software Foundation, either version 3 of the License, or
+%    (at your option) any later version.
+%
+%    BayesOpt is distributed in the hope that it will be useful, but 
+%    WITHOUT ANY WARRANTY; without even the implied warranty of
+%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%    GNU General Public License for more details.
+%
+%    You should have received a copy of the GNU General Public License
+%    along with BayesOpt.  If not, see <http://www.gnu.org/licenses/>.
+% ------------------------------------------------------------------------
+%
+
+function y = branin(x)
+%Bounds [0,1]^2
+% Min = 0.1239 0.8183
+% Min = 0.5428 0.1517  => 0.3979
+% Min = 0.9617 0.1650
+    
+a = x(1) * 15 - 5;
+b = x(2) * 15;
+
+y = (b-(5.1/(4*pi^2))*a^2+5*a/pi-6)^2+10*(1-1/(8*pi))*cos(a)+10;

matlab/testfunctions/braninhighdim.m

+% 
+% -------------------------------------------------------------------------
+%    This file is part of BayesOpt, an efficient C++ library for 
+%    Bayesian optimization.
+%
+%    Copyright (C) 2011-2013 Ruben Martinez-Cantin <rmcantin@unizar.es>
+%
+%    BayesOpt is free software: you can redistribute it and/or modify it 
+%    under the terms of the GNU General Public License as published by
+%    the Free Software Foundation, either version 3 of the License, or
+%    (at your option) any later version.
+%
+%    BayesOpt is distributed in the hope that it will be useful, but 
+%    WITHOUT ANY WARRANTY; without even the implied warranty of
+%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%    GNU General Public License for more details.
+%
+%    You should have received a copy of the GNU General Public License
+%    along with BayesOpt.  If not, see <http://www.gnu.org/licenses/>.
+% ------------------------------------------------------------------------
+%
+
+function y = branin(x)
+%Bounds [0,1]^2
+% Min = 0.1239 0.8183
+% Min = 0.5428 0.1517  => 0.3979
+% Min = 0.9617 0.1650
+
+global MATRIX_A
+z = MATRIX_A*x';
+
+if (z(1) < 0) z(1) = 0; end;
+if (z(2) < 0) z(2) = 0; end;
+if (z(1) > 1) z(1) = 1; end;
+if (z(2) > 1) z(2) = 1; end;
+
+% Trick: We assume the function has 1000 dims, but in reality, it is just
+% the traditional 2D branin.
+
+a = z(1) * 15 - 5;
+b = z(2) * 15;
+
+y = (b-(5.1/(4*pi^2))*a^2+5*a/pi-6)^2+10*(1-1/(8*pi))*cos(a)+10;

matlab/testfunctions/langermann.m

+% 
+% -------------------------------------------------------------------------
+%    This file is part of BayesOpt, an efficient C++ library for 
+%    Bayesian optimization.
+%
+%    Copyright (C) 2011-2013 Ruben Martinez-Cantin <rmcantin@unizar.es>
+%
+%    BayesOpt is free software: you can redistribute it and/or modify it 
+%    under the terms of the GNU General Public License as published by
+%    the Free Software Foundation, either version 3 of the License, or
+%    (at your option) any later version.
+%
+%    BayesOpt is distributed in the hope that it will be useful, but 
+%    WITHOUT ANY WARRANTY; without even the implied warranty of
+%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%    GNU General Public License for more details.
+%
+%    You should have received a copy of the GNU General Public License
+%    along with BayesOpt.  If not, see <http://www.gnu.org/licenses/>.
+% ------------------------------------------------------------------------
+%
+
 function x_out = langermann(x_in)
 % Bounds [3,5]
     a = [3,5,2,1,7];

matlab/testfunctions/michalewicz.m

+% 
+% -------------------------------------------------------------------------
+%    This file is part of BayesOpt, an efficient C++ library for 
+%    Bayesian optimization.
+%
+%    Copyright (C) 2011-2013 Ruben Martinez-Cantin <rmcantin@unizar.es>
+%
+%    BayesOpt is free software: you can redistribute it and/or modify it 
+%    under the terms of the GNU General Public License as published by
+%    the Free Software Foundation, either version 3 of the License, or
+%    (at your option) any later version.
+%
+%    BayesOpt is distributed in the hope that it will be useful, but 
+%    WITHOUT ANY WARRANTY; without even the implied warranty of
+%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%    GNU General Public License for more details.
+%
+%    You should have received a copy of the GNU General Public License
+%    along with BayesOpt.  If not, see <http://www.gnu.org/licenses/>.
+% ------------------------------------------------------------------------
+%
+
 function y = michalewicz(x)
 %Bounds [0,pi]
 %Min = -4687 (n=5)

matlab/testfunctions/quadratic.m

+% 
+% -------------------------------------------------------------------------
+%    This file is part of BayesOpt, an efficient C++ library for 
+%    Bayesian optimization.
+%
+%    Copyright (C) 2011-2013 Ruben Martinez-Cantin <rmcantin@unizar.es>
+%
+%    BayesOpt is free software: you can redistribute it and/or modify it 
+%    under the terms of the GNU General Public License as published by
+%    the Free Software Foundation, either version 3 of the License, or
+%    (at your option) any later version.
+%
+%    BayesOpt is distributed in the hope that it will be useful, but 
+%    WITHOUT ANY WARRANTY; without even the implied warranty of
+%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%    GNU General Public License for more details.
+%
+%    You should have received a copy of the GNU General Public License
+%    along with BayesOpt.  If not, see <http://www.gnu.org/licenses/>.
+% ------------------------------------------------------------------------
+%
+
 function [value] = quadratic(xin)
 % Simple quadratic function [0,1]
     xin = xin - 0.53;

matlab/testfunctions/rosenbrock.m

+% 
+% -------------------------------------------------------------------------
+%    This file is part of BayesOpt, an efficient C++ library for 
+%    Bayesian optimization.
+%
+%    Copyright (C) 2011-2013 Ruben Martinez-Cantin <rmcantin@unizar.es>
+%
+%    BayesOpt is free software: you can redistribute it and/or modify it 
+%    under the terms of the GNU General Public License as published by
+%    the Free Software Foundation, either version 3 of the License, or
+%    (at your option) any later version.
+%
+%    BayesOpt is distributed in the hope that it will be useful, but 
+%    WITHOUT ANY WARRANTY; without even the implied warranty of
+%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%    GNU General Public License for more details.
+%
+%    You should have received a copy of the GNU General Public License
+%    along with BayesOpt.  If not, see <http://www.gnu.org/licenses/>.
+% ------------------------------------------------------------------------
+%
+
 function y = rosenbrock(x)
 % Bounds [-2.048,2.048]
 % Min y = 0

python/demo_dimscaling.py

 params['n_init_samples'] = 150
 #params['noise'] = 0.01
 #params['kernel_name'] = "kMaternISO3"
-params['surr_name'] = "STUDENT_T_PROCESS_NORMAL_INV_GAMMA"
+params['surr_name'] = "sStudentTProcessJef"
 
 dim = 20
 lb = np.ones((dim,))*0

python/demo_multiprocess.py

     bo = BayesOptProcess(pipe_child)
     bo.params['n_iterations'] = 50
     bo.params['n_init_samples'] = 20
-    bo.params['s_name'] = "GAUSSIAN_PROCESS_INV_GAMMA_NORMAL"
-    bo.params['c_name'] = "GP_HEDGE"
+    bo.params['s_name'] = "sGaussianProcessNormal"
+    bo.params['c_name'] = "cHedge(cEI,cLCB,cExpReturn,cOptimisticSampling)"
 
     p = Process(target=worker, args=(pipe_par,))
 

src/parameters.cpp

 
 
 
-surrogate_name str2surrogate(const char* name)
+/*surrogate_name str2surrogate(const char* name)
 {
   if      (!strcmp(name,  "GAUSSIAN_PROCESS"))
     return S_GAUSSIAN_PROCESS;
     case S_ERROR:
     default: return "ERROR!";
     }
-}
+    }*/
 
 
 learning_type str2learn(const char* name)
 
 
 char DEF_LOG_FILE[] = "bayesopt.log";
-char DEF_SUR_NAME[] = "GAUSSIAN_PROCESS";
+char DEF_SUR_NAME[] = "sGaussianProcess";
 char DEF_KERNEL_NAME[] = "kMaternISO3";
 char DEF_MEAN_NAME[] = "mOne";
 char DEF_CRITERIA_NAME[] = "cEI";
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.