diff --git a/.travis.yml b/.travis.yml index 5d7ce35c..819ee4c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,12 +22,12 @@ before_install: before_script: - ./autogen.sh - - echo "#define CMAES_EXPORT" > cmaes_export.h + - echo "#define CMAES_EXPORT" > include/libcmaes/cmaes_export.h - if [ $TRAVIS_OS_NAME == linux ]; then ./configure --enable-python; fi - if [ $TRAVIS_OS_NAME == osx ]; then ./configure --enable-python LDFLAGS="-L/usr/local/lib/"; fi script: make -os: +os: - linux - osx diff --git a/CMakeLists.txt b/CMakeLists.txt index a900de79..d78fd3b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,7 @@ if 'real_prefix' in dir(sys): endif () # boost-python - FIND_PACKAGE(Boost COMPONENTS python) + find_package(Boost COMPONENTS python) if (Boost_FOUND) set (HAVE_BOOST_PYTHON TRUE) if (NOT TARGET Boost::python) @@ -137,6 +137,11 @@ if 'real_prefix' in dir(sys): endif () endif () +set (HAVE_SURROG ${LIBCMAES_ENABLE_SURROG}) +configure_file (include/libcmaes/libcmaes_config.h.cmake.in include/libcmaes/libcmaes_config.h) +install (FILES ${PROJECT_BINARY_DIR}/include/libcmaes/libcmaes_config.h + DESTINATION ${RELATIVE_INSTALL_INCLUDE_DIR}/libcmaes) + if (NOT MSVC) set (prefix ${CMAKE_INSTALL_PREFIX}) set (exec_prefix ${prefix}) diff --git a/Makefile.am b/Makefile.am index 7d57f8eb..f29c0e6c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,7 +9,7 @@ SUBDIRS += python endif libcmaesincludedir=$(includedir)/libcmaes -libcmaesinclude_HEADERS = libcmaes_config.h +libcmaesinclude_HEADERS = include/libcmaes/libcmaes_config.h include/libcmaes/cmaes_export.h pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libcmaes.pc diff --git a/README.md b/README.md index 988ae1ab..26434b80 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ sudo apt-get install autoconf automake libtool libgoogle-glog-dev libgflags-dev For compiling with basic options enabled: ``` ./autogen.sh -echo "#define CMAES_EXPORT" > cmaes_export.h +echo "#define CMAES_EXPORT" > include/libcmaes/cmaes_export.h ./configure make ``` diff --git a/configure.ac b/configure.ac index 49e7ddce..b6bef490 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_INIT(libcmaes,0.9.5) AC_MSG_NOTICE([libcmaes $PACKAGE_VERSION]) AC_CONFIG_SRCDIR(Makefile.am) AM_INIT_AUTOMAKE([subdir-objects]) -AM_CONFIG_HEADER([libcmaes_config.h]) +AM_CONFIG_HEADER([include/libcmaes/libcmaes_config.h]) AC_CONFIG_FILES(libcmaes.pc) #ac_default_prefix=`pwd` diff --git a/examples/Makefile.am b/examples/Makefile.am index d01e9dcd..8c66ab70 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -26,7 +26,7 @@ sample_code_surrogate_rsvm_SOURCES=surrogates/sample-code-surrogate-rsvm.cc endif endif -AM_CPPFLAGS=-I$(top_srcdir)/src/ -I$(EIGEN3_INC) $(GFLAGS_CFLAGS) +AM_CPPFLAGS=-I$(top_srcdir)/include/ -I$(EIGEN3_INC) $(GFLAGS_CFLAGS) AM_CXXFLAGS=-Wall -Wextra -g -O3 -mavx -mfma if !HAVE_CLANG AM_CXXFLAGS+=-fopenmp diff --git a/examples/sample-code-ask-tell-uh.cc b/examples/sample-code-ask-tell-uh.cc index 343cc3d8..481e885d 100644 --- a/examples/sample-code-ask-tell-uh.cc +++ b/examples/sample-code-ask-tell-uh.cc @@ -19,7 +19,7 @@ * along with libcmaes. If not, see . */ -#include "cmaes.h" +#include #include using namespace libcmaes; diff --git a/examples/sample-code-ask-tell.cc b/examples/sample-code-ask-tell.cc index 4bcbbe9f..1f96a4fa 100644 --- a/examples/sample-code-ask-tell.cc +++ b/examples/sample-code-ask-tell.cc @@ -19,7 +19,7 @@ * along with libcmaes. If not, see . */ -#include "cmaes.h" +#include #include using namespace libcmaes; diff --git a/examples/sample-code-bounds.cc b/examples/sample-code-bounds.cc index 476496a8..b2e25279 100644 --- a/examples/sample-code-bounds.cc +++ b/examples/sample-code-bounds.cc @@ -19,7 +19,7 @@ * along with libcmaes. If not, see . */ -#include "cmaes.h" +#include #include using namespace libcmaes; diff --git a/examples/sample-code-genopheno.cc b/examples/sample-code-genopheno.cc index 6e6f1992..e21028d0 100644 --- a/examples/sample-code-genopheno.cc +++ b/examples/sample-code-genopheno.cc @@ -19,7 +19,7 @@ * along with libcmaes. If not, see . */ -#include "cmaes.h" +#include #include using namespace libcmaes; diff --git a/examples/sample-code-gradient.cc b/examples/sample-code-gradient.cc index 4c40eb5e..a5c13cb4 100644 --- a/examples/sample-code-gradient.cc +++ b/examples/sample-code-gradient.cc @@ -19,7 +19,7 @@ * along with libcmaes. If not, see . */ -#include "cmaes.h" +#include #include using namespace libcmaes; diff --git a/examples/sample-code-lscaling-sigmas.cc b/examples/sample-code-lscaling-sigmas.cc index a83c27e9..1afd8b2b 100644 --- a/examples/sample-code-lscaling-sigmas.cc +++ b/examples/sample-code-lscaling-sigmas.cc @@ -19,7 +19,7 @@ * along with libcmaes. If not, see . */ -#include "cmaes.h" +#include #include using namespace libcmaes; diff --git a/examples/sample-code-lscaling.cc b/examples/sample-code-lscaling.cc index 889353a1..76682e77 100644 --- a/examples/sample-code-lscaling.cc +++ b/examples/sample-code-lscaling.cc @@ -19,7 +19,7 @@ * along with libcmaes. If not, see . */ -#include "cmaes.h" +#include #include using namespace libcmaes; diff --git a/examples/sample-code-pffunc.cc b/examples/sample-code-pffunc.cc index 0dbf94a0..a7db1693 100644 --- a/examples/sample-code-pffunc.cc +++ b/examples/sample-code-pffunc.cc @@ -19,7 +19,7 @@ * along with libcmaes. If not, see . */ -#include "cmaes.h" +#include #include using namespace libcmaes; diff --git a/examples/sample-code-pfunc.cc b/examples/sample-code-pfunc.cc index d0508ca0..467147fa 100644 --- a/examples/sample-code-pfunc.cc +++ b/examples/sample-code-pfunc.cc @@ -19,7 +19,7 @@ * along with libcmaes. If not, see . */ -#include "cmaes.h" +#include #include using namespace libcmaes; diff --git a/examples/sample-code.cc b/examples/sample-code.cc index 927e03fe..9b2f3943 100644 --- a/examples/sample-code.cc +++ b/examples/sample-code.cc @@ -19,7 +19,7 @@ * along with libcmaes. If not, see . */ -#include "cmaes.h" +#include #include using namespace libcmaes; diff --git a/src/acovarianceupdate.h b/include/libcmaes/acovarianceupdate.h similarity index 93% rename from src/acovarianceupdate.h rename to include/libcmaes/acovarianceupdate.h index cf520ea2..8942ad78 100644 --- a/src/acovarianceupdate.h +++ b/include/libcmaes/acovarianceupdate.h @@ -22,9 +22,9 @@ #ifndef ACOVARIANCEUPDATE_H #define ACOVARIANCEUPDATE_H -#include "cmaparameters.h" -#include "cmasolutions.h" -#include "eigenmvn.h" +#include +#include +#include namespace libcmaes { diff --git a/src/bipopcmastrategy.h b/include/libcmaes/bipopcmastrategy.h similarity index 98% rename from src/bipopcmastrategy.h rename to include/libcmaes/bipopcmastrategy.h index c99c2be9..ea309fe7 100644 --- a/src/bipopcmastrategy.h +++ b/include/libcmaes/bipopcmastrategy.h @@ -22,7 +22,7 @@ #ifndef BIPOPCMASTRATEGY_H #define BIPOPCMASTRATEGY_H -#include "ipopcmastrategy.h" +#include #include namespace libcmaes diff --git a/src/candidate.h b/include/libcmaes/candidate.h similarity index 98% rename from src/candidate.h rename to include/libcmaes/candidate.h index 2a892a5e..d5ede0b9 100644 --- a/src/candidate.h +++ b/include/libcmaes/candidate.h @@ -22,8 +22,8 @@ #ifndef CANDIDATE_H #define CANDIDATE_H -#include "eo_matrix.h" -#include "cmaparameters.h" +#include +#include namespace libcmaes { diff --git a/src/cmaes.h b/include/libcmaes/cmaes.h similarity index 98% rename from src/cmaes.h rename to include/libcmaes/cmaes.h index 1252937b..f7e49e17 100644 --- a/src/cmaes.h +++ b/include/libcmaes/cmaes.h @@ -22,10 +22,10 @@ #ifndef CMAES_H #define CMAES_H -#include "esoptimizer.h" -#include "cmastrategy.h" -#include "ipopcmastrategy.h" -#include "bipopcmastrategy.h" +#include +#include +#include +#include namespace cma = libcmaes; diff --git a/src/cmaparameters.h b/include/libcmaes/cmaparameters.h similarity index 99% rename from src/cmaparameters.h rename to include/libcmaes/cmaparameters.h index 0f1ecddf..da9f0388 100644 --- a/src/cmaparameters.h +++ b/include/libcmaes/cmaparameters.h @@ -22,9 +22,9 @@ #ifndef CMAPARAMETERS_H #define CMAPARAMETERS_H -#include "parameters.h" -#include "eo_matrix.h" -#include "cmaes_export.h" +#include +#include +#include #include namespace libcmaes diff --git a/src/cmasolutions.h b/include/libcmaes/cmasolutions.h similarity index 98% rename from src/cmasolutions.h rename to include/libcmaes/cmasolutions.h index 49c2fa50..23aca8a1 100644 --- a/src/cmasolutions.h +++ b/include/libcmaes/cmasolutions.h @@ -22,12 +22,12 @@ #ifndef CMASOLUTIONS_H #define CMASOLUTIONS_H -#include "libcmaes_config.h" -#include "candidate.h" -#include "eo_matrix.h" -#include "cmaparameters.h" -#include "cmastopcriteria.h" -#include "pli.h" +#include +#include +#include +#include +#include +#include #include #include diff --git a/src/cmastopcriteria.h b/include/libcmaes/cmastopcriteria.h similarity index 98% rename from src/cmastopcriteria.h rename to include/libcmaes/cmastopcriteria.h index 669262ee..33d2531f 100644 --- a/src/cmastopcriteria.h +++ b/include/libcmaes/cmastopcriteria.h @@ -22,7 +22,7 @@ #ifndef CMASTOPCRITERIA_H #define CMASTOPCRITERIA_H -#include "cmaparameters.h" +#include #include #include diff --git a/src/cmastrategy.h b/include/libcmaes/cmastrategy.h similarity index 94% rename from src/cmastrategy.h rename to include/libcmaes/cmastrategy.h index 2f68cc1d..c8dc1f60 100644 --- a/src/cmastrategy.h +++ b/include/libcmaes/cmastrategy.h @@ -22,14 +22,14 @@ #ifndef CMASTRATEGY_H #define CMASTRATEGY_H -#include "esostrategy.h" -#include "cmaparameters.h" -#include "cmasolutions.h" -#include "cmastopcriteria.h" -#include "covarianceupdate.h" -#include "acovarianceupdate.h" -#include "vdcmaupdate.h" -#include "eigenmvn.h" +#include +#include +#include +#include +#include +#include +#include +#include #include namespace libcmaes diff --git a/src/contour.h b/include/libcmaes/contour.h similarity index 100% rename from src/contour.h rename to include/libcmaes/contour.h diff --git a/src/covarianceupdate.h b/include/libcmaes/covarianceupdate.h similarity index 94% rename from src/covarianceupdate.h rename to include/libcmaes/covarianceupdate.h index 51029a78..6187f6fc 100644 --- a/src/covarianceupdate.h +++ b/include/libcmaes/covarianceupdate.h @@ -22,9 +22,9 @@ #ifndef COVARIANCEUPDATE_H #define COVARIANCEUPDATE_H -#include "cmaparameters.h" -#include "cmasolutions.h" -#include "eigenmvn.h" +#include +#include +#include namespace libcmaes { diff --git a/src/eigenmvn.h b/include/libcmaes/eigenmvn.h similarity index 100% rename from src/eigenmvn.h rename to include/libcmaes/eigenmvn.h diff --git a/src/eo_matrix.h b/include/libcmaes/eo_matrix.h similarity index 100% rename from src/eo_matrix.h rename to include/libcmaes/eo_matrix.h diff --git a/src/errstats.h b/include/libcmaes/errstats.h similarity index 99% rename from src/errstats.h rename to include/libcmaes/errstats.h index 9cbc0bcc..cdc8b1b0 100644 --- a/src/errstats.h +++ b/include/libcmaes/errstats.h @@ -22,9 +22,9 @@ #ifndef ERRSTATS_H #define ERRSTATS_H -#include "pli.h" -#include "contour.h" -#include "cmaes.h" +#include +#include +#include namespace libcmaes { diff --git a/src/esoptimizer.h b/include/libcmaes/esoptimizer.h similarity index 96% rename from src/esoptimizer.h rename to include/libcmaes/esoptimizer.h index d905912c..2c357d4f 100644 --- a/src/esoptimizer.h +++ b/include/libcmaes/esoptimizer.h @@ -24,9 +24,9 @@ #include #include -#include "parameters.h" -#include "esostrategy.h" -#include "cmasolutions.h" +#include +#include +#include /* algorithms */ enum { diff --git a/src/esostrategy.h b/include/libcmaes/esostrategy.h similarity index 98% rename from src/esostrategy.h rename to include/libcmaes/esostrategy.h index 3f058054..5bd1aa42 100644 --- a/src/esostrategy.h +++ b/include/libcmaes/esostrategy.h @@ -22,9 +22,9 @@ #ifndef ESOSTRATEGY_H #define ESOSTRATEGY_H -#include "eo_matrix.h" // to include Eigen everywhere. -#include "candidate.h" -#include "eigenmvn.h" +#include // to include Eigen everywhere. +#include +#include #include namespace libcmaes diff --git a/src/genopheno.h b/include/libcmaes/genopheno.h similarity index 98% rename from src/genopheno.h rename to include/libcmaes/genopheno.h index f87f3b9b..7c1b4ef6 100644 --- a/src/genopheno.h +++ b/include/libcmaes/genopheno.h @@ -22,9 +22,9 @@ #ifndef GENOPHENO_H #define GENOPHENO_H -#include "noboundstrategy.h" -#include "pwq_bound_strategy.h" -#include "scaling.h" +#include +#include +#include #include namespace libcmaes diff --git a/src/ipopcmastrategy.h b/include/libcmaes/ipopcmastrategy.h similarity index 98% rename from src/ipopcmastrategy.h rename to include/libcmaes/ipopcmastrategy.h index dd593fc8..1b4059bf 100644 --- a/src/ipopcmastrategy.h +++ b/include/libcmaes/ipopcmastrategy.h @@ -22,7 +22,7 @@ #ifndef IPOPCMASTRATEGY_H #define IPOPCMASTRATEGY_H -#include "cmastrategy.h" +#include namespace libcmaes { diff --git a/src/libcmaes_config.h.cmake.in b/include/libcmaes/libcmaes_config.h.cmake.in similarity index 100% rename from src/libcmaes_config.h.cmake.in rename to include/libcmaes/libcmaes_config.h.cmake.in diff --git a/src/llogging.h b/include/libcmaes/llogging.h similarity index 97% rename from src/llogging.h rename to include/libcmaes/llogging.h index d3722b65..840f035e 100644 --- a/src/llogging.h +++ b/include/libcmaes/llogging.h @@ -22,7 +22,7 @@ #ifndef LLOGGING_H #define LLOGGING_H -#include "libcmaes_config.h" +#include #ifdef HAVE_GLOG // HAVE_LIB_GLOG #include diff --git a/src/noboundstrategy.h b/include/libcmaes/noboundstrategy.h similarity index 98% rename from src/noboundstrategy.h rename to include/libcmaes/noboundstrategy.h index 98265a9f..6cefa6b9 100644 --- a/src/noboundstrategy.h +++ b/include/libcmaes/noboundstrategy.h @@ -22,7 +22,7 @@ #ifndef NOBOUNDSTRATEGY_H #define NOBOUNDSTRATEGY_H -#include "eo_matrix.h" +#include #include #include diff --git a/src/opti_err.h b/include/libcmaes/opti_err.h similarity index 100% rename from src/opti_err.h rename to include/libcmaes/opti_err.h diff --git a/src/parameters.h b/include/libcmaes/parameters.h similarity index 99% rename from src/parameters.h rename to include/libcmaes/parameters.h index 0c74edeb..be42b044 100644 --- a/src/parameters.h +++ b/include/libcmaes/parameters.h @@ -22,9 +22,9 @@ #ifndef PARAMETERS_H #define PARAMETERS_H -#include "eo_matrix.h" -#include "genopheno.h" -#include "llogging.h" +#include +#include +#include #include #include #include diff --git a/src/pli.h b/include/libcmaes/pli.h similarity index 99% rename from src/pli.h rename to include/libcmaes/pli.h index 362efa95..3d284c63 100644 --- a/src/pli.h +++ b/include/libcmaes/pli.h @@ -22,7 +22,7 @@ #ifndef PLI_H #define PLI_H -#include "eo_matrix.h" +#include #include namespace libcmaes diff --git a/src/pwq_bound_strategy.h b/include/libcmaes/pwq_bound_strategy.h similarity index 97% rename from src/pwq_bound_strategy.h rename to include/libcmaes/pwq_bound_strategy.h index 4458bd61..dc5d5552 100644 --- a/src/pwq_bound_strategy.h +++ b/include/libcmaes/pwq_bound_strategy.h @@ -22,8 +22,8 @@ #ifndef PWQ_BOUND_STRATEGY_H #define PWQ_BOUND_STRATEGY_H -#include "eo_matrix.h" -#include "cmaes_export.h" +#include +#include #include namespace libcmaes diff --git a/src/scaling.h b/include/libcmaes/scaling.h similarity index 99% rename from src/scaling.h rename to include/libcmaes/scaling.h index cc958c09..86aedb1c 100644 --- a/src/scaling.h +++ b/include/libcmaes/scaling.h @@ -27,7 +27,7 @@ #ifndef LSCALING_H #define LSCALING_H -#include "eo_matrix.h" +#include #include #include diff --git a/src/surrcmaes.h b/include/libcmaes/surrcmaes.h similarity index 97% rename from src/surrcmaes.h rename to include/libcmaes/surrcmaes.h index 251c9d25..609ab97b 100644 --- a/src/surrcmaes.h +++ b/include/libcmaes/surrcmaes.h @@ -22,9 +22,9 @@ #ifndef SURRCMAES_H #define SURRCMAES_H -#include "cmaes.h" -#include "surrogates/rankingsvm.hpp" -#include "surrogates/rsvm_surr_strategy.hpp" +#include +#include +#include namespace libcmaes { diff --git a/src/surrogates/rankingsvm.hpp b/include/libcmaes/surrogates/rankingsvm.hpp similarity index 99% rename from src/surrogates/rankingsvm.hpp rename to include/libcmaes/surrogates/rankingsvm.hpp index 8ba82fec..03e30fb8 100644 --- a/src/surrogates/rankingsvm.hpp +++ b/include/libcmaes/surrogates/rankingsvm.hpp @@ -29,7 +29,7 @@ #ifndef RANKINGSVM_H #define RANKINGSVM_H -#include "eo_matrix.h" +#include #include #include #include @@ -89,7 +89,7 @@ class RBFKernel : public SVMKernel RBFKernel() :SVMKernel() {} - + ~RBFKernel() {} double K(const dVec &x1, const dVec &x2) { return exp(-_gamma*((x1-x2).squaredNorm())); } @@ -103,12 +103,12 @@ class RBFKernel : public SVMKernel avgdist /= 0.5*(x.cols()*(x.cols()-1.0)); double sigma = _sigma_a * std::pow(avgdist,_sigma_pow); _gamma = 1.0/(2.0*sigma*sigma); - + //debug //std::cout << "avgdist=" << avgdist << " / sigma=" << sigma << " / gamma=" << _gamma << std::endl; - //debug + //debug } - + double _gamma = 1.0; double _sigma_a = 1.0; double _sigma_pow = 1.0; @@ -122,10 +122,10 @@ class RankingSVM { public: RankingSVM() - { + { _udist = std::uniform_real_distribution<>(0,1); } - + ~RankingSVM() { } @@ -147,7 +147,7 @@ class RankingSVM //debug //std::cout << "Learning RSVM with niter=" << niter << std::endl; //debug - + // init structures. int nalphas = x.cols()-1; _C = dMat::Constant(nalphas,1,_Cval); @@ -155,12 +155,12 @@ class RankingSVM _C(nalphas-1-i) = _Cval*pow(nalphas-i,2); _dKij = dMat::Zero(nalphas,nalphas); _alpha = dVec::Zero(nalphas); - + if (_encode) encode(x,covinv,xmean); compute_training_kernel(x); optimize(x,niter); - + //debug //std::cout << "alpha=" << _alpha.transpose() << std::endl; //debug @@ -202,7 +202,7 @@ class RankingSVM curfit += _alpha(j) * (Kvals(j)-Kvals(j+1)); fit(i) = curfit; } - + //debug //std::cout << "fit=" << fit.transpose() << std::endl; //debug @@ -241,7 +241,7 @@ class RankingSVM for (int i=0;i<_K.rows();i++) for (int j=i;j<_K.cols();j++) _K(i,j)=_K(j,i)=_kernel.K(x.col(i),x.col(j)); - + //debug //std::cout << "K=" << _K << std::endl; //debug @@ -282,7 +282,7 @@ class RankingSVM sum_alphas(i) = (_epsilon - sum_alpha) / _dKij(i,i); } } - + // optimize for niter double L=0.0; int i1 = 0; @@ -344,14 +344,14 @@ class RankingSVM public: bool _encode = false; /**< whether to use encoding from inverse sqrt covariance matrix of points. */ - + dMat _K; /**< pre-computed matrix of kernel values for a given training set. */ dVec _alpha; /**< vector of Ranking SVM parameters over ranking constraints. */ dMat _dKij; dMat _C; /**< constraint violation weights. */ double _Cval = 1e6; /**< constraing violation base weight value. */ double _epsilon = 1.0; - + TKernel _kernel; /**< kernel class. */ std::mt19937 _rng; diff --git a/src/surrogates/rsvm_surr_strategy.hpp b/include/libcmaes/surrogates/rsvm_surr_strategy.hpp similarity index 95% rename from src/surrogates/rsvm_surr_strategy.hpp rename to include/libcmaes/surrogates/rsvm_surr_strategy.hpp index f2b3953a..9c8f355e 100644 --- a/src/surrogates/rsvm_surr_strategy.hpp +++ b/include/libcmaes/surrogates/rsvm_surr_strategy.hpp @@ -19,10 +19,10 @@ * along with libcmaes. If not, see . */ -#include "cmaes.h" -#include "surrogatestrategy.h" -#include "opti_err.h" -#include "rankingsvm.hpp" +#include +#include +#include +#include #ifndef RSVMSURROGATESTRATEGY_H #define RSVMSURROGATESTRATEGY_H @@ -48,7 +48,7 @@ namespace libcmaes } template using eostrat = ESOStrategy,CMASolutions,CMAStopCriteria >; - + template