Commits

Ruben Martinez-Cantin committed 9e15118

Solving a bug in matplotpp. Cleaned namespace hacks.

  • Participants
  • Parent commits 1a9d33a

Comments (0)

Files changed (6)

File CMakeLists.txt

 find_package(GLUT)
 find_package(OpenGL)
 if(OPENGL_FOUND AND GLUT_FOUND)
-  INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/matplotpp
-                      ${GLUT_INCLUDE_DIR})
+  INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/matplotpp)
+
+  include_directories(${GLUT_INCLUDE_DIRS})
+  link_directories(${GLUT_LIBRARY_DIRS})
+  add_definitions(${GLUT_DEFINITIONS})
+
+  include_directories(${OpenGL_INCLUDE_DIRS})
+  link_directories(${OpenGL_LIBRARY_DIRS})
+  add_definitions(${OpenGL_DEFINITIONS})
+
   enable_language(C)
   ADD_EXECUTABLE(bo_display 
     ./app/bo_display.cpp 

File app/bo_cont.cpp

   par.kernel.hp_std[1] = 1;
   par.kernel.n_hp = 2;
   par.mean.coef_mean[0] = 1.0;
-  par.mean.coef_mean[1] = 1.0;
   par.mean.coef_std[0] = MEAN_SIGMA;
-  par.mean.coef_std[1] = MEAN_SIGMA;
-  par.mean.n_coef = 2;
+  par.mean.n_coef = 1;
   par.alpha = PRIOR_ALPHA;
   par.beta = PRIOR_BETA;
   par.noise = DEFAULT_NOISE;
   par.surr_name = "sStudentTProcessJef";
   par.kernel.name = "kSum(kSEISO,kConst)";
-  par.mean.name = "mSum(mLinear,mConst)";
+  par.mean.name = "mConst";
   par.l_type = L_ML;
   par.n_iterations = 200;       // Number of iterations
   par.n_init_samples = 50;

File app/bo_display.cpp

 };
 
 //#include "unistd.h"
-using namespace std;
+//using namespace std;
 #include "matplotpp.h"  
 
-
 using namespace bayesopt;
 
-int is_run=1;
+int is_run=0;
 int is_step=0;
 size_t state_ii = 0;
 BayesOptBase* GLOBAL_MODEL;
-vector<double> lx,ly;
+std::vector<double> lx,ly;
 
 class MP :public MatPlot{ 
 void DISPLAY(){
   size_t nruns = GLOBAL_MODEL->getParameters()->n_iterations;
-    if ((is_run) && (state_ii < nruns))
+  if ((is_run) && (state_ii < nruns))
     {
       ++state_ii;
       GLOBAL_MODEL->stepOptimization(state_ii); 
       ly.push_back(res);
       lx.push_back(last(0));
 	  
-	  if (is_step) { is_run = 0; is_step = 0; }
+      if (is_step) { is_run = 0; is_step = 0; }
     }
     
-    int n=1000;
-    vector<double> x,y,z,su,sl,c;
-    x=linspace(0,1,n);
-    y = x; z = x; su = x; sl = x; c= x;
-    vectord q(1);
-    for(int i=0;i<n;++i)
-      {
-	q(0) = x[i];
-	ProbabilityDistribution* pd = GLOBAL_MODEL->getSurrogateModel()->prediction(q);
-	y[i] = pd->getMean();
-	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); set(3);
-    plot(lx,ly);set("k");set("*");
-    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); set(3);
+  int n=1000;
+  std::vector<double> x,y,z,su,sl,c;
+  x=linspace(0,1,n);
+  y = x; z = x; su = x; sl = x; c= x;
+  vectord q(1);
+  for(int i=0;i<n;++i)
+    {
+      q(0) = x[i];
+      ProbabilityDistribution* pd = GLOBAL_MODEL->getSurrogateModel()->prediction(q);
+      y[i] = pd->getMean();
+      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); set(3);
+  plot(lx,ly);set("k");set("*");
+  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); set(3);
 }
 }mp;
 
 void keyboard(unsigned char key, int x, int y){
     mp.keyboard(key, x, y); 
     if(key=='r'){ if(is_run==0){is_run=1;}else{is_run=0;}}
-	if(key=='s'){ is_run=1; is_step=1; } 
+    if(key=='s'){ is_run=1; is_step=1; } 
 }
 
 int main(int nargs, char *args[])
   parameters.kernel.hp_std[0] = 5;
   parameters.kernel.n_hp = 1;
 
-
-
   state_ii = 0;
 
   ExampleOneD* opt = new ExampleOneD(dim,parameters);
       ly.push_back(res);
       lx.push_back(last(0));
     }
-  
+
   glutInit(&nargs, args);
-  glutCreateWindow(100,100,900,700);
+  glutCreateWindow(50,50,800,650);
   glutDisplayFunc( display );
   glutReshapeFunc( reshape );
   glutIdleFunc( idle );

File matplotpp/matplotpp.cc

 Author: Yuichi Katori (yuichi.katori@gmail.com)
 Project:MATPLOT++ (MATLAB-like plotting tool in C++).
 Version:0.3.13
+
+TODO: This file only works in Debug mode. Revise!
+
 ****************************************************************************/
 using namespace std;
 #include "matplotpp.h"
 
 /// Layer
 Layer::Layer(int id_){ 
-    id=id_;	
+    id=id_;
+    Visible=1;
     Children.clear();	
 }
 /// Patch
 
 void MatPlot::display_figure(){
 
-    if(is_debug1){printf("mode: %d handle: %4d Figure\n",
-			 mode,cf->id);}
+    if(is_debug1){printf("mode: %d handle: %4d Figure %d layers\n",
+			 mode,cf->id, cf->Children.size());}
 
     int tObj;// type of child object
     int iObj;// index of child object

File matplotpp/matplotpp.h

 
 #define PI 3.14159265358979323846264
 
-typedef vector<double> dvec;
-typedef vector< vector<double> > dmat;
-typedef vector< vector<float> > tcvec;
-typedef vector< vector< vector<float> > > tcmat;
+typedef std::vector<double> dvec;
+typedef std::vector< std::vector<double> > dmat;
+typedef std::vector< std::vector<float> > tcvec;
+typedef std::vector< std::vector< std::vector<float> > > tcmat;
 
-inline vector<double> linspace(double min,double max,int n){
-    vector<double> a;
+inline dvec linspace(double min,double max,int n){
+    dvec a;
     if(n<1){n=1;}
     a.resize(n);
     for(int i=0;i<n;++i){a[i]=min+(max-min)*i/(n-1);}
     return a;
 };
 
-inline valarray<double> valinspace(double min,double max,int n){
-    valarray<double> a; 
+inline std::valarray<double> valinspace(double min,double max,int n){
+    std::valarray<double> a; 
     a.resize(n);
     for(int i=0;i<n;++i){a[i]=min+(max-min)*i/(n-1);}
     return a;
     //int Status;// 0:minimized, 1:default position, 2:maximized 
     int Position[4];//left top width height
     int Visible;
-    vector<int> Children;
+    std::vector<int> Children;
 
     void add_child(int i);
     Figure(int id_){
  public:
     int id;
     int Visible;
-    string layername;
-    vector<int> Children;
+    std::string layername;
+    std::vector<int> Children;
     Layer(int id_);
     void add_child(int i);
 };
     
     int View;// 0:2D, 1:3D
 
-    vector<vector<float> > ColorMap;// for colorbar
+    tcvec ColorMap;// for colorbar
 
     // Matlab variables //
     // styles
     int Box;//0:Off, 1:On
-    string GridLineStyle;
+    std::string GridLineStyle;
     float LineWidth;
-    string TickDir;// {in} | out
+    std::string TickDir;// {in} | out
     //string TickDirMode;
     //TickLength
     int Visible;//0:Off, 1:On
 
     // General Information 
     int Parent;
-    vector<int> Children;
+    std::vector<int> Children;
     int Selected;
     float Position[4];//left bottom width height
     float Viewport3d[4];//left bottom width height
 
     //Scale
-    string XAxisLocation;
-    string YAxisLocation;
+    std::string XAxisLocation;
+    std::string YAxisLocation;
 
     //string XDir,YDir,ZDir;
 
     int XScale,YScale,ZScale;// linear | log
 
     dvec XTick,YTick,ZTick;
-    string XTickMode,YTickMode,ZTickMode;
+    std::string XTickMode,YTickMode,ZTickMode;
     int TickLabel;// 0:Off, {1:On}
     //View
     float CameraPosition[3];
     float CameraUpVector[3];
 
     // Label
-    string Title;
-    string XLabel,YLabel,ZLabel;
+    std::string Title;
+    std::string XLabel,YLabel,ZLabel;
 
     double CLim[2];
 
     //dmat EData,UData,LData;
     //dmat VData,WData;
 
-    string Color;
-    string LineStyle;// {-} | - - | : | -. | none
+    std::string Color;
+    std::string LineStyle;// {-} | - - | : | -. | none
     float  LineWidth;
-    string Marker;// {none}
+    std::string Marker;// {none}
     float  MarkerSize;
-    string MarkerEdgeColor;
-    string MarkerFaceColor;
+    std::string MarkerEdgeColor;
+    std::string MarkerFaceColor;
 
     int Clipping;
     //string EraseMode;
  public:
     int type;
     int id;
-    string ColorMap;
+    std::string ColorMap;
 
     //dvec XData,YData;
     dmat XData,YData,ZData,CDataIndex;
     dvec V,UserData;
     tcmat CData;
     
-    string FaceColor;//ColorSpec    | none | {flat} 
-    string EdgeColor;//ColorSpec{k} | none | flat
+    std::string FaceColor;//ColorSpec    | none | {flat} 
+    std::string EdgeColor;//ColorSpec{k} | none | flat
     
-    string LineStyle;// {-} | - - | : | -. | none
+    std::string LineStyle;// {-} | - - | : | -. | none
     float  LineWidth;
-    string Marker;// {none}
+    std::string Marker;// {none}
     float  MarkerSize;
-    string MarkerEdgeColor;
-    string MarkerFaceColor;
+    std::string MarkerEdgeColor;
+    std::string MarkerFaceColor;
 
     int Parent;
 
 	
     }
     void get(){
-	cout <<"FaceColor: "<< FaceColor <<endl;
-	cout <<"EdgeColor: "<< EdgeColor <<endl;
-	cout <<"LineStyle: "<< LineStyle <<endl;
-	cout <<"LineWidth: "<< LineWidth <<endl;
+	std::cout <<"FaceColor: "<< FaceColor <<std::endl;
+	std::cout <<"EdgeColor: "<< EdgeColor <<std::endl;
+	std::cout <<"LineStyle: "<< LineStyle <<std::endl;
+	std::cout <<"LineWidth: "<< LineWidth <<std::endl;
     }
 };
 //Note: 
  public:
     int id;
     int type;
-    vector< vector<int> > Faces;
+    std::vector< std::vector<int> > Faces;
     dmat Vertices;
     dmat FaceVertexCData;
     dmat XData,YData,ZData;
     //tcmat CData;
     tcvec CData;
 
-    string EdgeColor,FaceColor;//{ColorSpec}|none|flat|interp 
+    std::string EdgeColor,FaceColor;//{ColorSpec}|none|flat|interp 
 
-    string LineStyle; // {-} | - - | : | -. | none
+    std::string LineStyle; // {-} | - - | : | -. | none
     float  LineWidth;
 
     Patch(int id_){	
 class Text{///  
  public:
     int id;
-    string String;
+    std::string String;
     float Position[3];
     int Parent;
     int type;//0:axis 1:figure
     int is_debug1;
     int is_debug2;
     
-    vector<vector<float> > cmap;//TODO move to class Figure
+    tcvec cmap;//TODO move to class Figure
     
     int mode;//0:initialization 1:configuration
     int init_level;// initialization level of objects
     Text *ct;    
 
     // objects containers //
-    vector< Figure > vFigure;
-    vector< Layer > vLayer;
-    vector< Axes > vAxes; 
-    vector< Line > vLine;
-    vector< Surface > vSurface;
-    vector< Patch > vPatch;
-    vector< Text > vText;
+    std::vector< Figure > vFigure;
+    std::vector< Layer > vLayer;
+    std::vector< Axes > vAxes; 
+    std::vector< Line > vLine;
+    std::vector< Surface > vSurface;
+    std::vector< Patch > vPatch;
+    std::vector< Text > vText;
 
     // objects counter //
     int iFigure;
     // Layer ///
     int layer();
     //int layer(string s);    
-    int layer(string s,int Visible);
-    int frame(string s,int Visible);// do not use
+    int layer(std::string s,int Visible);
+    int frame(std::string s,int Visible);// do not use
 
     // Axes ///
     
     void axis(double xMin,double xMax,double yMin,double yMax);
     void axis(double xMin,double xMax,double yMin,double yMax,double zMin,double zMax);
 
-    void axis(string s);
+    void axis(std::string s);
     void axis(int s);
     
-    void grid(string s);
+    void grid(std::string s);
     void grid(int s);
 
-    void ticklabel(string s);
+    void ticklabel(std::string s);
     void ticklabel(int s);
 
-    void title(string s);
-    void xlabel(string s);
-    void ylabel(string s);
-    void zlabel(string s);
+    void title(std::string s);
+    void xlabel(std::string s);
+    void ylabel(std::string s);
+    void zlabel(std::string s);
 
     //void xlim(double min,double max);
     //void xlim(string s);
     void mouse_capture(double *xmouse,double *ymouse);   
     
     // set, General Object Handling ///
-    void set(string v);
+    void set(std::string v);
     void set(float v);  
-    void set(string p,float v);
-    void set(string p,string v);
-    void set(int h,string p,string v);
-    void set(int h,string p,float v);      
+    void set(std::string p,float v);
+    void set(std::string p,std::string v);
+    void set(int h,std::string p,std::string v);
+    void set(int h,std::string p,float v);      
     int gco();
     
     // Line ///
     //int plot(dmat Y);
     //int plot(dvec x,dmat Y);
     //int plot(dmat X,dmat Y);
-    int plot(valarray<double> x,valarray<double> y);
+    int plot(std::valarray<double> x,std::valarray<double> y);
     
     int plot3(dvec x,dvec y,dvec z);
     //int plot3(dvec X,dvec Y,dvec Z);
     // Text ///
     //TODO: more fonts    
     int text();
-    int text(double x,double y,string s);
+    int text(double x,double y,std::string s);
     void set_font(char font_[],int size);
-    void ptext(float x,float y,string s);
-    void ptext3(float x,float y,float z,string s);
-    void ptext3c(float x,float y,float z,string s);
+    void ptext(float x,float y,std::string s);
+    void ptext3(float x,float y,float z,std::string s);
+    void ptext3c(float x,float y,float z,std::string s);
 
     // Colors ///
     void color(float r,float g,float b);
-    vector<float> colormap(string c,float t);
-    void colormap(string c);
-    void colormap(vector<vector<float> > c);
+    std::vector<float> colormap(std::string c,float t);
+    void colormap(std::string c);
+    void colormap(tcvec c);
 
     void gray();
     void jet();
     void autumn();
     void winter();
 
-    vector<float> map2color(double x,double xmin,double xmax);
+    std::vector<float> map2color(double x,double xmin,double xmax);
     
-    void Shading(string c);
-    void shading(string c);
-    vector<float> ColorSpec2RGB(string c);
-    string rgb2colorspec(vector<float> rgb);
+    void Shading(std::string c);
+    void shading(std::string c);
+    std::vector<float> ColorSpec2RGB(std::string c);
+    std::string rgb2colorspec(std::vector<float> rgb);
 
     // print ///
     void print();

File python/demo_cam.py

     return ((countW-countB)/float(mat.size))**2
 
 params = bayesopt.initialize_params()
-params['n_iterations'] = 15
+params['n_iterations'] = 20
 params['n_init_samples'] = 10
 params['sigma_s'] = 1
 params['crit_name'] = "cEI"