Commits

Ruben Martinez-Cantin  committed 3715632

Setting up testing callback procedures. Used std_copy in nlopt wrapper

  • Participants
  • Parent commits 41cd22c

Comments (0)

Files changed (9)

File CMakeLists.txt

 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
 
 option(BAYESOPT_BUILD_EXAMPLES "Build examples and demos?" ON)
+option(BAYESOPT_BUILD_TESTS "Build tests?" OFF)
 option(BAYESOPT_PYTHON_INTERFACE "Build Python interface?" OFF)
 option(BAYESOPT_MATLAB_COMPATIBLE "Build library compatible with Matlab?" ON)
 option(BAYESOPT_BUILD_SOBOL "Build support for Sobol sequences?" ON)
 LINK_DIRECTORIES( ${CMAKE_SOURCE_DIR}/lib )
 
 IF(NLOPT_BUILD)
-  ADD_SUBDIRECTORY(nlopt)
-  include_directories(${CMAKE_SOURCE_DIR}/nlopt/api)
+  ADD_SUBDIRECTORY(nlopt2)
+  include_directories(${CMAKE_SOURCE_DIR}/nlopt2/api)
   SET(EXT_LIBS nlopt)
 ELSE(NLOPT_BUILD)
   SET(EXT_LIBS ${NLOPT})
   
 TARGET_LINK_LIBRARIES(bayesopt ${EXT_LIBS})
 
+IF(BAYESOPT_BUILD_TESTS)
+  ADD_SUBDIRECTORY(tests)
+endif(BAYESOPT_BUILD_TESTS)
+
+
 IF(BAYESOPT_BUILD_EXAMPLES)
   ADD_SUBDIRECTORY(examples)
 endif(BAYESOPT_BUILD_EXAMPLES)

File examples/CMakeLists.txt

   add_dependencies(bo_display bayesopt)
   TARGET_LINK_LIBRARIES(bo_display bayesopt ${GLUT_LIBRARY} ${OPENGL_LIBRARY})
 endif()
-
-
-#Test for random number generator
-#ADD_EXECUTABLE(randtest ./testrand.cpp)
-
-#Test for parsers
-#ADD_EXECUTABLE(parsetest ../utils/parser.cpp ./testparser.cpp)

File examples/testparser.cpp

-#include <string>
-#include <iostream>
-#include "parser.hpp"
-
-int main()
-{
-  std::string test = "One(Two, Three, Four(Five, Six))";
-  std::string one;
-  std::vector<std::string> vs;
-  bayesopt::utils::parseExpresion(test,one,vs);
-
-  std::cout << one << std::endl;
-  for(std::vector<std::string>::iterator it = vs.begin();
-      it != vs.end(); ++it)
-    std::cout << *it << std::endl;
- 
-  return 0;
-}

File examples/testrand.cpp

-#include "randgen.hpp"
-
-int main()
-{
-  randEngine eng;
-  randFloat sample(eng, realUniformDist(0,1));
-
-  for (int i = 0; i<1000; i++)
-    std::cout << sample() << std::endl;
-
-  return 0;
-}

File include/nlopt_optimization.hpp

 #ifndef __NLOPT_OPTIMIZATION_HPP__
 #define __NLOPT_OPTIMIZATION_HPP__
 
-#include "dll_stuff.h"
 #include "optimizable.hpp"
 #include "nlopt.hpp"
-//#include "optimization.hpp"
+
 
 namespace bayesopt {
 

File src/empiricalbayesprocess.cpp

 
 #include "empiricalbayesprocess.hpp"
 #include "log.hpp"
-#include "optimizekernel.hpp"	
+//#include "optimizekernel.hpp"	
 
 
 namespace bayesopt

File tests/testparser.cpp

+#include <string>
+#include <iostream>
+#include "parser.hpp"
+
+int main()
+{
+  std::string test = "One(Two, Three, Four(Five, Six))";
+  std::string one;
+  std::vector<std::string> vs;
+  bayesopt::utils::parseExpresion(test,one,vs);
+
+  std::cout << one << std::endl;
+  for(std::vector<std::string>::iterator it = vs.begin();
+      it != vs.end(); ++it)
+    std::cout << *it << std::endl;
+ 
+  return 0;
+}

File tests/testrand.cpp

+#include "randgen.hpp"
+
+int main()
+{
+  randEngine eng;
+  randFloat sample(eng, realUniformDist(0,1));
+
+  for (int i = 0; i<1000; i++)
+    std::cout << sample() << std::endl;
+
+  return 0;
+}

File wrappers/nloptwpr.cpp

 			 double *grad, void *my_func_data)
 
   {
-    double xcopy[128];
-    for (unsigned int i=0;i<n;i++)
-      xcopy[i] = x[i];
-    ublas::array_adaptor<double> shared(n, xcopy);
-    ublas::vector<double, ublas::array_adaptor<double> > sharedN(n, shared); 
-    
+    // double xcopy[128];
+    // for (unsigned int i=0;i<n;i++)
+    //   xcopy[i] = x[i];
+    // ublas::array_adaptor<double> shared(n, xcopy);
+    // ublas::vector<double, ublas::array_adaptor<double> > sharedN(n, shared); 
+
+    ublas::vector<double> vx(n);
+    std::copy(x,x+n,vx.begin());
+
     // This is not very clever... but works!
     void *objPointer = my_func_data;
     RBOptimizable* OPTIMIZER = static_cast<RBOptimizable*>(objPointer);
     
-    return OPTIMIZER->evaluate(sharedN);
+    return OPTIMIZER->evaluate(vx);
   } /* evaluate_criteria_nlopt */
 
 
 			      double *grad, void *my_func_data)
 
   {
-    double xcopy[128];
-    for (unsigned int i=0;i<n;i++)
-      xcopy[i] = x[i];
-    ublas::array_adaptor<double> shared(n, xcopy);
-    ublas::vector<double, ublas::array_adaptor<double> > sharedN(n, shared); 
+    ublas::vector<double> vx(n);
+    std::copy(x,x+n,vx.begin());
     
     // This is not very clever... but works!
     void *objPointer = my_func_data;
     
 
     ublas::vector<double> vgrad = ublas::zero_vector<double>(n);
-    double f =  OPTIMIZER->evaluate(sharedN,vgrad);
+    double f =  OPTIMIZER->evaluate(vx,vgrad);
     if ((grad) && (grad != NULL) )
       for (unsigned int i=0;i<n;i++)
 	grad[i] = vgrad(i);