Commits

Ruben Martinez-Cantin  committed f085519

Adding conditional compiling for test display

  • Participants
  • Parent commits 55e2db7

Comments (0)

Files changed (7)

File CMakeLists.txt

 #Display test
 find_package(GLUT)
 find_package(OpenGL)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/matplotpp)
-enable_language(C)
-ADD_EXECUTABLE(bo_display 
-  ./app/bo_display.cpp 
-  ./matplotpp/matplotpp.cc 
-  ./matplotpp/gl2ps.c)
-add_dependencies(bo_display bayesopt)
-TARGET_LINK_LIBRARIES(bo_display bayesopt ${GLUT_LIBRARY} ${OPENGL_LIBRARY})
+if(OPENGL_FOUND AND GLUT_FOUND)
+  INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/matplotpp)
+  enable_language(C)
+  ADD_EXECUTABLE(bo_display 
+    ./app/bo_display.cpp 
+    ./matplotpp/matplotpp.cc 
+    ./matplotpp/gl2ps.c)
+  add_dependencies(bo_display bayesopt)
+  TARGET_LINK_LIBRARIES(bo_display bayesopt ${GLUT_LIBRARY} ${OPENGL_LIBRARY})
+endif()
 
 #Branin
 ADD_EXECUTABLE(bo_branin ./app/bo_branin.cpp )

File app/bo_display.cpp

       }
 
     double x = xin(0);
-    return sqr(x-0.5) + sin(20*x)*0.2;
+    return sqr(x-0.3) + sin(20*x)*0.2;
   };
 
   bool checkReachability(const vectord &query)
 
 class MP :public MatPlot{ 
 void DISPLAY(){
-    // Create test data 
-    int n=400;
+    int n=100;
     vector<double> x,y,z,su,sl,c;
     x=linspace(0,1,n);
     y = x; z = x; su = x; sl = x; c= x;
 	q(0) = x[i];
 	ProbabilityDistribution* pd = GLOBAL_MODEL->getSurrogateModel()->prediction(q);
 	y[i] = pd->getMean();
-	su[i] = y[i] + 3*pd->getStd();
-	sl[i] = y[i] - 3*pd->getStd();
+	su[i] = y[i] + 2*pd->getStd();
+	sl[i] = y[i] - 2*pd->getStd();
 	c[i] = -GLOBAL_MODEL->evaluateCriteria(q);
 	z[i] = GLOBAL_MODEL->evaluateSample(q);
       }
     //plot
     subplot(2,1,1);
     title("press r to run and stop");
-    plot(x,y);
+    plot(x,y); set(3);
     plot(lx,ly);set("k");set("*");
-    plot(x,su);set("g");
-    plot(x,sl);set("g");
-    plot(x,z);set("r");
+    plot(x,su);set("g"); set(2);
+    plot(x,sl);set("g"); set(2);
+    plot(x,z);set("r"); set(3);
    
     subplot(2,1,2);
-    plot(x,c);
-
+    plot(x,c); set(3);
 }
 }mp;
 
 void reshape(int w,int h){ mp.reshape(w,h); }
 void idle( void )
 {
-  if(is_run)
+  if ((is_run) && (state_ii < 150))
     {
-      if (state_ii < 300)
-	++state_ii;
+      ++state_ii;
       GLOBAL_MODEL->stepOptimization(state_ii); 
       vectord last(1);
       double res = GLOBAL_MODEL->getSurrogateModel()->getLastSample(last);
       ly.push_back(res);
       lx.push_back(last(0));
-    
     }
   glutPostRedisplay();
 }
 {
   size_t dim = 1;
   bopt_params parameters = initialize_parameters_to_default();
-  parameters.n_init_samples = 10;
-  parameters.n_iterations = 100;
-  parameters.surr_name = S_GAUSSIAN_PROCESS;
-  // parameters.kernel.hp_mean[0] = 0.5;
-  // parameters.kernel.hp_std[0] = 100.0;
-  // parameters.kernel.n_hp = 1;
+  parameters.n_init_samples = 7;
+  parameters.n_iter_relearn = 0;
+  parameters.n_iterations = 150;
+  parameters.surr_name = S_STUDENT_T_PROCESS_JEFFREYS;
+  parameters.kernel.hp_mean[0] = 1;
+  parameters.kernel.hp_std[0] = 0.1;
+  parameters.kernel.n_hp = 1;
   // parameters.mean.name = "mZero";
   //  parameters.crit_name = "cHedge(cEI,cLCB,cExpReturn,cOptimisticSampling)";
   // parameters.epsilon = 0.0;
+  //  parameters.verbose_level = 2;
 
   state_ii = 0;
 
   vectord result(dim);
   GLOBAL_MODEL = opt;
   opt->initializeOptimization();
+  vectord last(1);
+  size_t n_points = GLOBAL_MODEL->getSurrogateModel()->getNSamples();
+  for (size_t i = 0; i<n_points;++i)
+    {
+      double res = GLOBAL_MODEL->getSurrogateModel()->getSample(i,last);
+      ly.push_back(res);
+      lx.push_back(last(0));
+    }
   
   glutInit(&nargs, args);
-  glutCreateWindow(100,100,500,400);
+  glutCreateWindow(100,100,900,700);
   glutDisplayFunc( display );
   glutReshapeFunc( reshape );
   glutIdleFunc( idle );

File include/nonparametricprocess.hpp

     double getLastSample(vectord &x);
     inline vectord getPointAtMinimum() { return mGPXX[mMinIndex]; };
     inline double getValueAtMinimum() { return mGPY(mMinIndex); };
+    inline size_t getNSamples() { return mGPY.size(); };
   
     // Kernel function
     /** 

File src/bayesoptcont.cpp

 		if(yPoints(i)<ymin) 
 		  ymin = yPoints(i);
 	      
-		FILE_LOG(logDEBUG) << ymin << "|" << yPoints(i) << "|" 
-				   << mBB->unnormalizeVector(sample) ;
+		FILE_LOG(logDEBUG) << "X:" << mBB->unnormalizeVector(sample) 
+				   << "|Y:" << yPoints(i) << "|Min:" << ymin ;
 	      }
 	  }  
       }

File src/gaussian_process.cpp

    along with BayesOpt.  If not, see <http://www.gnu.org/licenses/>.
 ------------------------------------------------------------------------
 */
-#include "gaussian_process.hpp"
+
 #include "cholesky.hpp"
 #include "trace_ublas.hpp"
+#include "gaussian_process.hpp"
 
 namespace bayesopt
 {

File src/gaussian_process_ml.cpp

 /*
------------------------------------------------------------------------------
-   Copyright (C) 2011 Ruben Martinez-Cantin <rmcantin@unizar.es>
+-------------------------------------------------------------------------
+   This file is part of BayesOpt, an efficient C++ library for 
+   Bayesian optimization.
+
+   Copyright (C) 2011-2013 Ruben Martinez-Cantin <rmcantin@unizar.es>
  
-   This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
+   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.
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   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 this program.  If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------------
+   along with BayesOpt.  If not, see <http://www.gnu.org/licenses/>.
+------------------------------------------------------------------------
 */
 
-
 #include "cholesky.hpp"
 #include "trace_ublas.hpp"
 #include "gaussian_process_ml.hpp"
 namespace bayesopt
 {
 
-  using boost::numeric::ublas::inplace_solve;
-  using boost::numeric::ublas::inner_prod;
-  using boost::numeric::ublas::lower_tag;
-  using boost::numeric::ublas::lower;
-  using boost::numeric::ublas::trans;
-  
+  namespace ublas = boost::numeric::ublas;
 
   GaussianProcessML::GaussianProcessML(size_t dim, bopt_params params):
     HierarchicalGaussianProcess(dim, params)
     vectord phi = mMean->getFeatures(query);
   
     vectord v(kn);
-    inplace_solve(mL,v,lower_tag());
+    inplace_solve(mL,v,ublas::lower_tag());
 
     vectord rq = phi - prod(v,mKF);
 
     vectord rho(rq);
-    inplace_solve(mL2,rho,lower_tag());
+    inplace_solve(mL2,rho,ublas::lower_tag());
     
     double yPred = inner_prod(phi,mWML) + inner_prod(v,mAlphaF);
     double sPred = sqrt( mSigML * (kq - inner_prod(v,v) 
     size_t p = mMean->nFeatures();
 
     mKF = trans(mFeatM);
-    inplace_solve(mL,mKF,lower_tag());
+    inplace_solve(mL,mKF,ublas::lower_tag());
 
     matrixd FKF = prod(trans(mKF),mKF);
     mL2 = FKF;
     utils::cholesky_decompose(FKF,mL2);
 
     vectord Ky(mGPY);
-    inplace_solve(mL,Ky,lower_tag());
+    inplace_solve(mL,Ky,ublas::lower_tag());
 
     mWML = prod(Ky,mKF);
-    utils::cholesky_solve(mL2,mWML,lower());
+    utils::cholesky_solve(mL2,mWML,ublas::lower());
 
     mAlphaF = mGPY - prod(mWML,mFeatM);
-    inplace_solve(mL,mAlphaF,lower_tag());
+    inplace_solve(mL,mAlphaF,ublas::lower_tag());
     mSigML = inner_prod(mAlphaF,mAlphaF)/(n-p);
   
     return 1;

File src/student_t_process_jef.cpp

 namespace bayesopt
 {
 
-  using boost::numeric::ublas::inplace_solve;
-  using boost::numeric::ublas::inner_prod;
-  using boost::numeric::ublas::lower_tag;
-  using boost::numeric::ublas::lower;
-  using boost::numeric::ublas::trans;
-  
+  namespace ublas = boost::numeric::ublas; 
 
   StudentTProcessJeffreys::StudentTProcessJeffreys(size_t dim, 
 						   bopt_params params):
     vectord phi = mMean->getFeatures(query);
   
     vectord v(kn);
-    inplace_solve(mL,v,lower_tag());
+    inplace_solve(mL,v,ublas::lower_tag());
 
     vectord rq = phi - prod(v,mKF);
 
     vectord rho(rq);
-    inplace_solve(mL2,rho,lower_tag());
+    inplace_solve(mL2,rho,ublas::lower_tag());
     
     double yPred = inner_prod(phi,mWML) + inner_prod(v,mAlphaF);
     double sPred = sqrt( mSigML * (kq - inner_prod(v,v) 
     size_t p = mMean->nFeatures();
 
     mKF = trans(mFeatM);
-    inplace_solve(mL,mKF,lower_tag());
+    inplace_solve(mL,mKF,ublas::lower_tag());
 
     matrixd FKF = prod(trans(mKF),mKF);
     mL2 = FKF;
     utils::cholesky_decompose(FKF,mL2);
 
     vectord Ky(mGPY);
-    inplace_solve(mL,Ky,lower_tag());
+    inplace_solve(mL,Ky,ublas::lower_tag());
 
     mWML = prod(Ky,mKF);
-    utils::cholesky_solve(mL2,mWML,lower());
+    utils::cholesky_solve(mL2,mWML,ublas::lower());
 
     mAlphaF = mGPY - prod(mWML,mFeatM);
-    inplace_solve(mL,mAlphaF,lower_tag());
+    inplace_solve(mL,mAlphaF,ublas::lower_tag());
     mSigML = inner_prod(mAlphaF,mAlphaF)/(n-p);
     
     d_->setDof(n-p);