BayesOpt
bo_hartmann.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 <ctime>
25 #include <fstream>
26 #include "param_loader.hpp"
27 
28 int main(int nargs, char *args[])
29 {
31  if(nargs > 1){
32  if(!bayesopt::utils::ParamLoader::load(args[1], par)){
33  std::cout << "ERROR: provided file \"" << args[1] << "\" does not exist" << std::endl;
34  return -1;
35  }
36  }
37  else{
38  par = initialize_parameters_to_default();
39  par.n_iterations = 190;
40  par.noise = 1e-10;
41  par.random_seed = 0;
42  par.verbose_level = 1;
43  //bayesopt::utils::ParamLoader::save("bo_hartmann.txt", par);
44  }
45 
46 
47  ExampleHartmann6 hart6(par);
48 
49  std::ofstream timelog;
50  timelog.open("time_hartmann.log");
51  std::clock_t curr_t;
52  std::clock_t prev_t = clock();
53 
54  hart6.initializeOptimization();
55 
56  for (size_t ii = 0; ii < par.n_iterations; ++ii)
57  {
58  hart6.stepOptimization();
59 
60  curr_t = clock();
61  timelog << ii << ","
62  << static_cast<double>(curr_t - prev_t) / CLOCKS_PER_SEC
63  << std::endl;
64  prev_t = curr_t;
65  }
66 
67  timelog.close();
68 
69  vectord result = hart6.getFinalResult();
70  std::cout << "Result: " << result << "->"
71  << hart6.evaluateSample(result) << std::endl;
72  hart6.printOptimal();
73 
74  return 0;
75 }
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
double noise
Variance of observation noise (and nugget)
Definition: parameters.hpp:88
Allows to load parameters from file.
int random_seed
>=0 -> Fixed seed, <0 -> Time based (variable).
Definition: parameters.hpp:74