Commits

Ruben Martinez-Cantin committed b2e298a

Cleaning demo files

Comments (0)

Files changed (6)

-BayesOpt: A Bayesian optimization toolbox
+BayesOpt: A Bayesian optimization library
 =========================================
 
 BayesOpt is an efficient implementation of the Bayesian optimization
 - Mirror: <http://mloss.org/software/view/453/>
 
 The install guide and documentation for Windows, Linux and MacOS:
-- [Install guide](http://rmcantin.bitbucket.org/html/install.html) or [Install guide](@ref install)
+- [Online install guide](http://rmcantin.bitbucket.org/html/install.html) or [Local install guide](@ref install)
 
 
 Getting involved
 publication, we would appreciate it if you would kindly cite BayesOpt
 in your manuscript. Cite BayesOpt as:
 
-> Ruben Martinez-Cantin, **BayesOpt: a toolbox for
-> nonlinear-optimization, experimental design and stochastic bandits**,
+> Ruben Martinez-Cantin, **BayesOpt: A Bayesian Optimization Library for Nonlinear
+> Optimization, Experimental Design and Bandits**,
 > <http://bitbucket.org/rmcantin/bayesopt>
 
 - In addition, if you use a specific algorithm (REMBO, GP-Hedge,
 You should have received a copy of the GNU General Public License
 along with BayesOpt. If not, see <http:www.gnu.org/licenses/>.
 
-----------------------------------------------------------------------
+----------------------------------------------------------------------

doxygen/demos.dox

-/*! \page demos Description of demo files
+/*! \page demos Description of demos and examples
 \tableofcontents
 
 We have include a descriptions of the different demos than can be found in the
 library. Most of them are used to highlight the capabilities of the Bayesian optimization
 framework or the characteristics of the library.
 
-\b Important: note that some demos requires some extra dependencies to work (OpenGL, SimpleCV, etc.)
+\b Important: Some demos requires extra dependencies to work. They will be mention in each
+demo.
 
 \section cppdemos C/C++ demos
 
-These demos are automatically compiled and installed with the library. They can be found in the \c /bin subfolder. The source code of these demos is in \c /app
+These demos are automatically compiled and installed with the library. They can be found
+in the \c /bin subfolder. The source code of these demos is in \c /examples
 
-\subsection quadcpp Interface test (continuous and discrete)
+\subsection quadcpp Quadratic examples (continuous and discrete)
 
-\b bo_cont and \b bo_disc provides examples of the C (callback) and C++ (inheritance) interfaces for a simple quadratic function. They are the best starting point to start playing with the library.
+\b bo_cont and \b bo_disc provides examples of the C (callback) and C++ (inheritance)
+interfaces for a simple quadratic function. They are the best starting point to start
+playing with the library.
 
 \subsection onedcpp 1D test
 
 
 For details about REMBO, see \cite ZiyuWang2013.
 
-*/
+*/

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)

examples/bo_cont.cpp

   {
     double x[100];
     for (size_t i = 0; i < Xi.size(); ++i)
-	x[i] = Xi(i);
+      {
+	x[i] = Xi(i);	
+      }
     return testFunction(Xi.size(),x,NULL,NULL);
   };
 
 int main(int nargs, char *args[])
 {    
   int n = 10;                   // Number of dimensions
+  clock_t start, end;
+  double diff,diff2;
 
   // Common configuration
-  // See parameters.h for the available options
-  // If we initialize the struct with the DEFAUL_PARAMS,
-  // the we can optionally change only few of them 
+  // See parameters.h for the available options.
+  // Some parameters did not need to be changed for default, but we have done it for
+  // illustrative purpose.
   bopt_params par = initialize_parameters_to_default();
 
+  set_kernel(&par,"kSum(kSEISO,kConst)");
   par.kernel.hp_mean[0] = 1.0;
   par.kernel.hp_mean[1] = 1.0;
   par.kernel.hp_std[0] = 1.0;
   par.kernel.hp_std[1] = 1.0;
   par.kernel.n_hp = 2;
+
+  set_mean(&par,"mConst");
   par.mean.coef_mean[0] = 1.0;
   par.mean.coef_std[0] = 10.0;
   par.mean.n_coef = 1;
+
   set_surrogate(&par,"sStudentTProcessJef");
-  set_kernel(&par,"kSum(kSEISO,kConst)");
-  set_mean(&par,"mConst");
+  par.noise = 1e-10;
+
   par.sc_type = SC_MAP;
   par.l_type = L_EMPIRICAL;
-  par.n_iterations = 200;    // Number of iterations
-  par.init_method = 1;
-  par.n_init_samples = 50;
+
+  par.n_iterations = 100;    // Number of iterations
+  par.random_seed = 0;
+  par.n_init_samples = 15;
   par.n_iter_relearn = 0;
-  par.verbose_level = 1;
+
   /*******************************************/
-
-  clock_t start, end;
-  double diff,diff2;
-
   std::cout << "Running C++ interface" << std::endl;
-  // Configure C++ interface
 
   ExampleQuadratic opt(n,par);
   vectord result(n);
   opt.optimize(result);
   end = clock();
   diff = (double)(end-start) / (double)CLOCKS_PER_SEC;
+
   /*******************************************/
-
-
   std::cout << "Running C inferface" << std::endl;
   
-  // Configure C interface
-  double u[128], x[128], l[128], fmin[128];
+  // Prepare C interface
+  double low[128], up[128], xmin[128], fmin[128];
 
-  for (int i = 0; i < n; ++i) {
-    l[i] = 0.;    u[i] = 1.;
-  }
+  // Lower and upper bounds
+  for (int i = 0; i < n; ++i) 
+    {
+      low[i] = 0.;    
+      up[i] = 1.;
+    }
 
   // Run C interface
   start = clock();
-  bayes_optimization(n,&testFunction,NULL,l,u,x,fmin,par);
+  bayes_optimization(n,&testFunction,NULL,low,up,xmin,fmin,par);
   end = clock();
   diff2 = (double)(end-start) / (double)CLOCKS_PER_SEC;
   /*******************************************/
   std::cout << "Final result C++: " << result << std::endl;
   std::cout << "Elapsed time in C++: " << diff << " seconds" << std::endl;
 
-  std::cout << "Final result C: [" << n <<"](" << x[0];
+  std::cout << "Final result C: [" << n <<"](" << xmin[0];
   for (int i = 1; i < n; ++i )
-    std::cout << "," << x[i];
-  
+    {
+      std::cout << "," << xmin[i];      
+    }
   std::cout << ")" << std::endl;
   std::cout << "Elapsed time in C: " << diff2 << " seconds" << std::endl;
 

examples/bo_disc.cpp

   {
     double x[100];
     for (size_t i = 0; i < Xi.size(); ++i)
-	x[i] = Xi(i);
+      {
+	x[i] = Xi(i);	
+      }
     return testFunction(Xi.size(),x,NULL,NULL);
   };
 
 {    
   // Common configuration
   // See parameters.h for the available options
-  // If we initialize the struct with the DEFAUL_PARAMS,
-  // the we can optionally change only few of them 
+  // This is just an example of what can be done.
   bopt_params par = initialize_parameters_to_default();
 
-  par.kernel.hp_mean[0] = 1.0;
-  par.kernel.hp_std[0] = 1.0;
-  par.kernel.n_hp = 1;
-  par.mean.coef_mean[0] = 0.0;
-  par.mean.coef_std[0] = 10.0;
-  par.mean.n_coef = 1;
   set_surrogate(&par,"sStudentTProcessJef");
-  par.n_iterations = 20;       // Number of iterations
+  par.noise = 1e-10;
+  par.n_iterations = 70;       // Number of iterations
   par.n_init_samples = 20;
   /*******************************************/
   
-  const size_t nPoints = 1000;
+  const size_t nPoints = 1000;          // Number of discrete points
   const size_t n = 6;                   // Number of dimensions
 
+  // Let's generate a discrete grid by latin hypercube sampling in the n-dimensional
+  // space.
   randEngine mtRandom;
   matrixd xPoints(nPoints,n);
-  vecOfvec xP;
 
-  //Thanks to the quirks of Visual Studio, the following expression is invalid,
-  //so we have to replace it by a literal.
-  //WARNING: Make sure to update the size of the array if the number of points
-  //or dimensions change.
+  bayesopt::utils::lhs(xPoints,mtRandom);
+
+
+  // Set of discrete points using C arrays.  
+  // Thanks to the quirks of Visual Studio, the following expression is invalid, so we
+  // have to replace it by a literal.  WARNING: Make sure to update the size of the array
+  // if the number of points or dimensions change.
 #ifdef _MSC_VER
   double xPointsArray[6000];
 #else
   double xPointsArray[nPinArr];
 #endif
   
-  bayesopt::utils::lhs(xPoints,mtRandom);
+  // Set of discrete points using ublas vectors. For the C++ interface.
+  vecOfvec xP;   
 
+
+  // Lets copy the generated points to the specific structure for each interface.
   for(size_t i = 0; i<nPoints; ++i)
     {
       vectord point = row(xPoints,i);  
     }
     
 
-  
+  /*******************************************/
   // Run C++ interface
   std::cout << "Running C++ interface" << std::endl;
   ExampleDisc opt(xP,par);
   bayes_optimization_disc(n, &testFunction, NULL, xPointsArray, nPoints,
 			  x, fmin, par);
 
-  // Find the optimal value
+
+  // Find the optimal value by brute force
   size_t min = 0;
   double minvalue = opt.evaluateSample(row(xPoints,min));
   for(size_t i = 1; i<nPoints; ++i)
 	}
     }
 
-  std::cout << "Final result C++: " << result << std::endl;
-  std::cout << "Final result C: (";
+  std::cout << "Final result C++: " << result << " | Value:" << opt.evaluateSample(result) << std::endl;
+  std::cout << "Final result C: ["<< n << "](";
   for (int i = 0; i < n; i++ )
     std::cout << x[i] << ", ";
-  std::cout << ")" << std::endl;
-  std::cout << "Optimal: " << row(xPoints,min) << std::endl;
+  std::cout << ")" << " | Value:" << fmin[0] << std::endl;
+  std::cout << "Optimal: " << row(xPoints,min) << " | Value:" << minvalue << std::endl;
 }

src/kernel_functors.cpp

 	size_t n = mKernel->nHyperParameters();
 
 	FILE_LOG(logINFO) << "Expected " << n << " hyperparameters."
-			  << " Replicating given prior.";
+			  << " Replicating parameters and prior.";
 
 	vectord newthetav = svectord(n,thetav(0));
 	vectord newstheta = svectord(n,stheta(0));