Commits

Ruben Martinez-Cantin  committed 3249e95

Adding camelback demo

  • Participants
  • Parent commits 6f2739a

Comments (0)

Files changed (9)

File doxygen/demos.dox

-/*! \page demos Description of demos and examples
+/*! \page demos Demos and examples
 \tableofcontents
 
 We have include a descriptions of the different demos than can be
 
 with a search domain \f$-5 \leq x \leq 10\f$, \f$0 \leq y \leq 15\f$.
 
-\image html doxygen/branin.jpg
+\image html doxygen/branin.png
 
 For simplicity to display and use the function, the function used in
 the code has already been normalized in the [0,1] interval. Then, the
 
 with a search domain \f$-2 \leq x \leq 2\f$, \f$-1 \leq y \leq 1\f$.
 
-\image html doxygen/camel.png
+\image html doxygen/camelback.png
 
 There are two global minima:
 

File examples/CMakeLists.txt

 TARGET_LINK_LIBRARIES(bo_oned bayesopt)
 
 #Branin
-#ADD_EXECUTABLE(bo_branin ./bo_branin.cpp )
-#add_dependencies(bo_branin bayesopt)
-#TARGET_LINK_LIBRARIES(bo_branin bayesopt)
+ADD_EXECUTABLE(bo_branin ./bo_branin.cpp )
+add_dependencies(bo_branin bayesopt)
+TARGET_LINK_LIBRARIES(bo_branin bayesopt)
 
 ADD_EXECUTABLE(bo_branin_timed ./bo_branin_timed.cpp )
 add_dependencies(bo_branin_timed bayesopt)
 TARGET_LINK_LIBRARIES(bo_branin_mcmc bayesopt)
 
 #Hartmann
-ADD_EXECUTABLE(bo_hartmann_timed ./bo_hartmann_timed.cpp )
-add_dependencies(bo_hartmann_timed bayesopt)
-TARGET_LINK_LIBRARIES(bo_hartmann_timed bayesopt)
+ADD_EXECUTABLE(bo_hartmann ./bo_hartmann.cpp )
+add_dependencies(bo_hartmann bayesopt)
+TARGET_LINK_LIBRARIES(bo_hartmann bayesopt)
 
+#Camelback
+ADD_EXECUTABLE(bo_camelback ./bo_camelback.cpp )
+add_dependencies(bo_camelback bayesopt)
+TARGET_LINK_LIBRARIES(bo_camelback bayesopt)
 
 enable_language(C)  #For OpenGL and bo_display demo
 

File examples/bo_branin.cpp

   par.verbose_level = 1;
   par.noise = 1e-10;
   
-  BraninNormalized branin(2,par);
+  BraninNormalized branin(par);
   vectord result(2);
 
   branin.optimize(result);

File examples/bo_branin_display.cpp

   par.sc_type = SC_MAP;
   par.verbose_level = 1;
   
-  boost::scoped_ptr<BraninNormalized> branin(new BraninNormalized(2,par));
+  boost::scoped_ptr<BraninNormalized> branin(new BraninNormalized(par));
   GLOBAL_MATPLOT.init(branin.get(),2);
 
   vectord sv(2);  

File examples/bo_branin_mcmc.cpp

   par.sc_type = SC_MAP;
   par.verbose_level = 1;
   
-  BraninNormalized branin(2,par);
+  BraninNormalized branin(par);
   vectord result(2);
 
   branin.optimize(result);

File examples/bo_branin_timed.cpp

   //  par.n_iter_relearn = 0;
   par.random_seed = 0;
   par.verbose_level = 1;
-  
-  BraninNormalized branin(2,par);
+  par.noise = 1e-10;
+
+  BraninNormalized branin(par);
 
   std::ofstream timelog;
-  timelog.open("time.log");
+  timelog.open("time_branin.log");
   std::clock_t curr_t;
   std::clock_t prev_t = clock();
 

File examples/bo_hartmann.cpp

+/*
+-------------------------------------------------------------------------
+   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/>.
+------------------------------------------------------------------------
+*/
+
+#include <ctime>
+#include <fstream>
+#include "testfunctions.hpp"
+
+int main(int nargs, char *args[])
+{
+  bopt_params par = initialize_parameters_to_default();
+  par.n_iterations = 190;
+  par.noise = 1e-10;
+  par.random_seed = 0;
+  par.verbose_level = 1;
+
+  
+  ExampleHartmann6 hart6(par);
+
+  std::ofstream timelog;
+  timelog.open("time_hartmann.log");
+  std::clock_t curr_t;
+  std::clock_t prev_t = clock();
+
+  hart6.initializeOptimization();
+      
+  for (size_t ii = 0; ii < par.n_iterations; ++ii)
+    {      
+      hart6.stepOptimization();
+
+      curr_t = clock();
+      timelog << ii << ","
+	      << static_cast<double>(curr_t - prev_t) / CLOCKS_PER_SEC 
+	      << std::endl;
+      prev_t = curr_t;
+      }
+
+  timelog.close();
+
+  vectord result = hart6.getFinalResult();
+  std::cout << "Result: " << result << "->" 
+	    << hart6.evaluateSample(result) << std::endl;
+  hart6.printOptimal();
+
+  return 0;
+}

File examples/bo_hartmann_timed.cpp

-/*
--------------------------------------------------------------------------
-   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/>.
-------------------------------------------------------------------------
-*/
-
-#include <ctime>
-#include <fstream>
-#include "testfunctions.hpp"
-
-int main(int nargs, char *args[])
-{
-  bopt_params par = initialize_parameters_to_default();
-  par.n_iterations = 190;
-  par.noise = 1e-10;
-  par.random_seed = 0;
-  par.verbose_level = 1;
-
-  
-  ExampleHartmann6 branin(par);
-
-  std::ofstream timelog;
-  timelog.open("time_hartmann.log");
-  std::clock_t curr_t;
-  std::clock_t prev_t = clock();
-
-  branin.initializeOptimization();
-      
-  for (size_t ii = 0; ii < par.n_iterations; ++ii)
-    {      
-      branin.stepOptimization();
-
-      curr_t = clock();
-      timelog << ii << ","
-	      << static_cast<double>(curr_t - prev_t) / CLOCKS_PER_SEC 
-	      << std::endl;
-      prev_t = curr_t;
-      }
-
-  timelog.close();
-
-  vectord result = branin.getFinalResult();
-  std::cout << "Result: " << result << "->" 
-	    << branin.evaluateSample(result) << std::endl;
-  branin.printOptimal();
-
-  return 0;
-}

File examples/testfunctions.hpp

 class BraninNormalized: public bayesopt::ContinuousModel
 {
 public:
-  BraninNormalized(size_t dim,bopt_params par):
-    ContinuousModel(dim,par) {}
+  BraninNormalized(bopt_params par):
+    ContinuousModel(2,par) {}
 
   double evaluateSample( const vectord& xin)
   {
 
 };
 
+
+class ExampleCamelback: public bayesopt::ContinuousModel
+{
+public:
+  ExampleCamelback(bopt_params par):
+    ContinuousModel(2,par) {}
+
+  double evaluateSample( const vectord& x)
+  {
+     if (x.size() != 2)
+      {
+	std::cout << "WARNING: This only works for 2D inputs." << std::endl
+		  << "WARNING: Using only first two components." << std::endl;
+      }
+     double x1_2 = x(0)*x(0);
+     double x2_2 = x(1)*x(1);
+
+     double tmp1 = (4 - 2.1 * x1_2 + (x1_2*x1_2)/3) * x1_2;
+     double tmp2 = x(0)*x(1);
+     double tmp3 = (-4 + 4 * x2_2) * x2_2;
+     return tmp1 + tmp2 + tmp3;
+  }
+
+  bool checkReachability(const vectord &query)
+  {return true;};
+
+  inline double sqr( double x ){ return x*x; };
+
+  void printOptimal()
+  {
+    vectord sv(2);  
+    sv(0) = 0.0898; sv(1) = -0.7126;
+    std::cout << "Solutions: " << sv << "->" 
+	      << evaluateSample(sv) << std::endl;
+    sv(0) = 0.0898; sv(1) = 0.7126;
+    std::cout << "Solutions: " << sv << "->" 
+	      << evaluateSample(sv) << std::endl;
+  }
+
+};
+
+
+
 class ExampleHartmann6: public bayesopt::ContinuousModel
 {
 public:
   vectord mC;
   matrixd mP;
 };
+
+