BayesOpt
bo_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 
26 
27 
28 // Unfortunately OpenGL functions require no parameters, so the object 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 int menu()
53 {
54  std::string input;
55  int option = 0;
56  while ((option < 1) || (option > 5))
57  {
58  std::cout << "Please select an option for the parameters:\n\n"
59  << " 1- Default parameters.\n"
60  << " 2- Student t process model.\n"
61  << " 3- Combined kernel.\n"
62  << " 4- Lower Confidence Bound.\n"
63  << " 5- A-optimality criteria.\n\n"
64  << "Select [1-5]>";
65 
66  std::cin >> input;
67  std::istringstream is(input);
68  is >> option;
69  }
70  return option;
71 }
72 
73 int main(int nargs, char *args[])
74 {
75  bopt_params parameters = initialize_parameters_to_default();
76  parameters.n_init_samples = 7;
77  parameters.n_iterations = 100;
78  parameters.verbose_level = 2;
79 
80  switch( menu() )
81  {
82  case 1: break;
83  case 2:
84  {
85  set_surrogate(&parameters,"sStudentTProcessNIG");
86  parameters.n_iter_relearn = 5;
87  break;
88  }
89  case 3:
90  {
91  set_kernel(&parameters,"kSum(kPoly3,kRQISO)");
92  double mean[128] = {1, 1, 1, 1};
93  double std[128] = {5, 5, 5, 5};
94  size_t nhp = 4;
95  memcpy(parameters.kernel.hp_mean, mean, nhp * sizeof(double));
96  memcpy(parameters.kernel.hp_std,std, nhp * sizeof(double));
97  parameters.kernel.n_hp = nhp;
98  break;
99  }
100  case 4:
101  set_criteria(&parameters,"cLCB");
102  parameters.crit_params[0] = 5;
103  parameters.n_crit_params = 1;
104  break;
105  case 5:
106  set_criteria(&parameters,"cAopt");
107  parameters.n_crit_params = 0;
108  break;
109  default:
110  break;
111  };
112 
113  bayesopt::Parameters parameters_class(parameters);
114  boost::scoped_ptr<ExampleOneD> opt(new ExampleOneD(parameters_class));
115  GLOBAL_MATPLOT.init(opt.get(),1);
116 
117  glutInit(&nargs, args);
118  glutCreateWindow(50,50,800,650);
119  glutDisplayFunc( display );
120  glutReshapeFunc( reshape );
121  glutIdleFunc( idle );
122  glutMotionFunc( motion );
123  glutMouseFunc( mouse );
124  glutPassiveMotionFunc(passive);
125  glutKeyboardFunc( keyboard );
126  glutMainLoop();
127 
128  return 0;
129 }
size_t n_iterations
Maximum BayesOpt evaluations (budget)
Definition: parameters.h:84
size_t n_hp
Number of kernel hyperparameters.
Definition: parameters.h:70
int verbose_level
Neg-Error,0-Warning,1-Info,2-Debug -> stdout 3-Error,4-Warning,5-Info,>5-Debug -> logfile...
Definition: parameters.h:94
STL namespace.
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.h:86
double hp_mean[128]
Kernel hyperparameters prior (mean, log space)
Definition: parameters.h:68
kernel_parameters kernel
Kernel parameters.
Definition: parameters.h:125
Configuration parameters.
Definition: parameters.h:83
size_t n_crit_params
Number of criterion hyperparameters.
Definition: parameters.h:130
double hp_std[128]
Kernel hyperparameters prior (st dev, log space)
Definition: parameters.h:69
size_t n_iter_relearn
Number of samples before relearn kernel.
Definition: parameters.h:87
double crit_params[128]
Criterion hyperparameters (if needed)
Definition: parameters.h:129