BayesOpt
bo_branin_display.cpp
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 
23 #include "testfunctions.hpp"
24 #include "displaygp.hpp"
25 #include "param_loader.hpp"
26 
27 // Unfortunately OpenGL functions require no parameters, so the object
28 // has to be global.
30 
31 void display( void ){ GLOBAL_MATPLOT.display(); }
32 void reshape( int w,int h ){ GLOBAL_MATPLOT.reshape(w,h); }
33 void idle( void ) { glutPostRedisplay(); }
34 
35 void mouse(int button, int state, int x, int y ){ GLOBAL_MATPLOT.mouse(button,state,x,y); }
36 void motion(int x, int y ){ GLOBAL_MATPLOT.motion(x,y); }
37 void passive(int x, int y ){ GLOBAL_MATPLOT.passivemotion(x,y); }
38 
39 void keyboard(unsigned char key, int x, int y)
40 {
41  GLOBAL_MATPLOT.keyboard(key, x, y);
42  if(key=='r') //Toogle run/stop
43  {
44  GLOBAL_MATPLOT.toogleRUN();
45  }
46  if(key=='s') //Activate one step
47  {
48  GLOBAL_MATPLOT.setSTEP();
49  }
50 }
51 
52 
53 int main(int nargs, char *args[])
54 {
56  if(nargs > 1){
57  if(!bayesopt::utils::ParamLoader::load(args[1], par)){
58  std::cout << "ERROR: provided file \"" << args[1] << "\" does not exist" << std::endl;
59  return -1;
60  }
61  }
62  else{
63  par = initialize_parameters_to_default();
64  par.n_iterations = 100;
65  par.n_init_samples = 2;
66  par.n_iter_relearn = 1;
67  par.random_seed = 10;
68  //set_surrogate(&par,"sStudentTProcessNIG");
69 
70  par.l_type = L_MCMC;
71  par.sc_type = SC_MAP;
72  par.verbose_level = 1;
73  //bayesopt::utils::ParamLoader::save("bo_branin_display.txt", par);
74  }
75 
76  boost::scoped_ptr<BraninNormalized> branin(new BraninNormalized(par));
77  GLOBAL_MATPLOT.init(branin.get(),2);
78 
79  vectord sv(2);
80  sv(0) = 0.1239; sv(1) = 0.8183;
81  GLOBAL_MATPLOT.setSolution(sv);
82 
83  sv(0) = 0.5428; sv(1) = 0.1517;
84  GLOBAL_MATPLOT.setSolution(sv);
85 
86  sv(0) = 0.9617; sv(1) = 0.1650;
87  GLOBAL_MATPLOT.setSolution(sv);
88 
89  glutInit(&nargs, args);
90  glutCreateWindow(50,50,800,650);
91  glutDisplayFunc( display );
92  glutReshapeFunc( reshape );
93  glutIdleFunc( idle );
94  glutMotionFunc( motion );
95  glutMouseFunc( mouse );
96  glutPassiveMotionFunc(passive);
97  glutKeyboardFunc( keyboard );
98  glutMainLoop();
99 
100  return 0;
101 }
learning_type l_type
Type of learning for the kernel params.
Definition: parameters.hpp:96
Plots the evolution (nonparametric process, criteria or contour plots) of 1D and 2D problems...
size_t n_init_samples
Number of samples before optimization.
Definition: parameters.hpp:68
size_t n_iterations
Maximum BayesOpt evaluations (budget)
Definition: parameters.hpp:66
int verbose_level
Neg-Error,0-Warning,1-Info,2-Debug -> stdout 3-Error,4-Warning,5-Info,>5-Debug -> logfile...
Definition: parameters.hpp:76
score_type sc_type
Score type for kernel hyperparameters (ML,MAP,etc)
Definition: parameters.hpp:95
Allows to load parameters from file.
int random_seed
>=0 -> Fixed seed, <0 -> Time based (variable).
Definition: parameters.hpp:74
size_t n_iter_relearn
Number of samples before relearn kernel.
Definition: parameters.hpp:69