23 #define _USE_MATH_DEFINES    26 #include <boost/numeric/ublas/assignment.hpp>    34     #define M_PI       3.14159265358979323846    43     TemplateWritter(std::string &template_filename, std::string &template_prefix)
    44     :input(), prefix(template_prefix)
    46         input.open(template_filename.c_str());
    54     void createFile(std::string &filename, 
const vectord& xin){
    57         input.seekg(0, std::ios::beg);
    58         std::ofstream output(filename.c_str());
    62         std::string currentLine;
    63         while (getline( input, currentLine)){
    64             if(currentLine.length() > 0){
    66                 size_t prefix_index = currentLine.find(prefix);
    67                 while(prefix_index != std::string::npos){
    68                     size_t number_index = prefix_index + prefix.length();
    71                     std::string number_string = 
"";
    72                     while(number_index < currentLine.size() && std::isdigit(currentLine.at(number_index))){
    73                         number_string = number_string + currentLine.at(number_index);
    78                     size_t x_index = fp.to_value<
size_t>(number_string);
    81                     if(x_index >= xin.size()){
    83                         std::cout << 
"ERROR: parameter " << x_index << 
" is out of bounds" << std::endl;
    84                         output << currentLine.substr(0, prefix_index) << 
"OUT_OF_BOUNDS";
    88                         double x = xin(x_index);
    89                         output << currentLine.substr(0, prefix_index) << fp.to_string(x);
    93                     currentLine = currentLine.substr(number_index);
    94                     prefix_index = currentLine.find(prefix);
    97                 output << currentLine << std::endl;    
   109     ContinuousModel(2,par) {}
   115     std::cout << 
"WARNING: This only works for 2D inputs." << std::endl
   116           << 
"WARNING: Using only first two components." << std::endl;
   124     std::string template_filename(
"../examples/standalone_calls/problem_template.xml");
   125     std::string template_prefix(
"XXXX_");
   127     std::string created_filename(
"../examples/standalone_calls/created_file.xml");
   128     tw.createFile(created_filename, xin);
   131     std::string results_filename(
"../examples/standalone_calls/results.txt");
   134     std::string call = 
"python ../examples/standalone_calls/eval_branin_xml.py " + created_filename + 
" " + results_filename;
   135     system(call.c_str());
   148   inline double sqr( 
double x ){ 
return x*x; };
   153     sv(0) = 0.1238938; sv(1) = 0.818333;
   154     std::cout << 
"Solutions: " << sv << 
"->"    155           << evaluateSample(sv) << std::endl;
   156     sv(0) = 0.5427728; sv(1) = 0.151667;
   157     std::cout << 
"Solutions: " << sv << 
"->"    158           << evaluateSample(sv) << std::endl;
   159     sv(0) = 0.961652; sv(1) = 0.1650;
   160     std::cout << 
"Solutions: " << sv << 
"->"    161           << evaluateSample(sv) << std::endl;
   166 int main(
int nargs, 
char *args[])
   170     if(!bayesopt::utils::ParamLoader::load(args[1], par)){
   171         std::cout << 
"ERROR: provided file \"" << args[1] << 
"\" does not exist" << std::endl;
   176     par = initialize_parameters_to_default();
   189   std::cout << 
"Result: " << result << 
"->"    191   branin.printOptimal();
   194   std::string filename(
"../examples/standalone_calls/created_file.xml");
   195   if( 
remove( filename.c_str() ) == 0 ){
   196     std::cout << 
"File \"" << filename << 
"\" successfully removed" << std::endl;
   199     std::cout << 
"Error: cannot remove \"" << filename << 
"\" file" << std::endl; 
   203   filename = 
"../examples/standalone_calls/results.txt";
   204   if( 
remove( filename.c_str() ) == 0 ){
   205     std::cout << 
"File \"" << filename << 
"\" successfully removed" << std::endl;
   208     std::cout << 
"Error: cannot remove \"" << filename << 
"\" file" << std::endl; 
 
Bayesian optimization for functions in continuous input spaces. 
BayesOpt main C++ interface. 
bool checkReachability(const vectord &query)
This function checks if the query is valid or not. 
size_t n_iterations
Maximum BayesOpt evaluations (budget) 
void optimize(vectord &bestPoint)
Execute the optimization process of the function defined in evaluateSample. 
double evaluateSample(const vectord &xin)
Function that defines the actual function to be optimized. 
int verbose_level
Neg-Error,0-Warning,1-Info,2-Debug -> stdout 3-Error,4-Warning,5-Info,>5-Debug -> logfile...
double noise
Variance of observation noise (and nugget) 
Functions to write and parse data files. 
Allows to load parameters from file. 
int random_seed
>=0 -> Fixed seed, <0 -> Time based (variable).