Commit b52d9bbf authored by Jean-Baptiste Mouret's avatar Jean-Baptiste Mouret
Browse files

enable compilation without libcmaes

parent bdc3da2a
......@@ -12,9 +12,16 @@ BO_PARAMS(std::cout,
struct acqui_gpucb : public defaults::acqui_gpucb {
};
#ifdef USE_LIBCMAES
struct opt_cmaes : public defaults::opt_cmaes {
};
};
#elif defined(USE_NLOPT)
struct opt_nloptnograd : public defaults::opt_nloptnograd {
};
#else
struct opt_gridsearch : public defaults::opt_gridsearch {
};
#endif
struct acqui_ucb {
BO_PARAM(double, alpha, 0.1);
};
......
......@@ -11,9 +11,16 @@ struct Params {
struct acqui_gpucb : public defaults::acqui_gpucb {
};
struct opt_cmaes : public defaults::opt_cmaes {
};
#ifdef USE_LIBCMAES
struct opt_cmaes : public defaults::opt_cmaes {
};
#elif defined(USE_NLOPT)
struct opt_nloptnograd : public defaults::opt_nloptnograd {
};
#else
struct opt_gridsearch : public defaults::opt_gridsearch {
};
#endif
struct kernel_maternfivehalfs {
BO_PARAM(double, sigma, 1);
BO_PARAM(double, l, 0.2);
......
......@@ -8,9 +8,16 @@
using namespace limbo;
struct Params {
#ifdef USE_LIBCMAES
struct opt_cmaes : public defaults::opt_cmaes {
};
#elif defined(USE_NLOPT)
struct opt_nloptnograd : public defaults::opt_nloptnograd {
};
#else
struct opt_gridsearch : public defaults::opt_gridsearch {
};
#endif
struct opt_rprop : public defaults::opt_rprop {
};
......
......@@ -25,7 +25,9 @@
#include <limbo/kernel/squared_exp_ard.hpp>
#include <limbo/acqui/gp_ucb.hpp>
#include <limbo/mean/data.hpp>
#include <limbo/opt/grid_search.hpp>
#include <limbo/opt/cmaes.hpp>
#include <limbo/opt/nlopt_no_grad.hpp>
#include <limbo/model/gp.hpp>
#include <limbo/model/gp/kernel_lf_opt.hpp>
#include <limbo/init/random_sampling.hpp>
......@@ -102,7 +104,15 @@ namespace limbo {
// defaults
struct defaults {
typedef init::RandomSampling<Params> init_t; // 1
#ifdef USE_LIBCMAES
typedef opt::Cmaes<Params> acquiopt_t; // 2
#elif defined(USE_NLOPT)
typedef opt::NLOptNoGrad<Params, NLOPT_GLOBAL_DIRECT_L_RAND> aquiopt_t;
#else
#warning NO NLOpt, and NO Libcmaes: the acquisition function will be optimized by a grid search algorithm (which is usually bad). Please install at least NLOpt or libcmaes to use limbo!.
typedef opt::GridSearch<Params> acquiopt_t;
#endif
typedef kernel::SquaredExpARD<Params> kf_t;
typedef mean::Data<Params> mean_t;
typedef model::GP<Params, kf_t, mean_t, model::gp::KernelLFOpt<Params>> model_t; // 3
......
#ifndef LIMBO_OPT_CMAES_HPP
#define LIMBO_OPT_CMAES_HPP
#ifndef USE_LIBCMAES
#warning NO libcmaes support
#else
#include <vector>
#include <iostream>
#include <Eigen/Core>
......@@ -11,6 +8,10 @@
#include <limbo/tools/macros.hpp>
#include <limbo/tools/parallel.hpp>
#ifndef USE_LIBCMAES
#warning NO libcmaes support
#else
#include <libcmaes/cmaes.h>
namespace limbo {
......@@ -52,7 +53,6 @@ namespace limbo {
double sigma = 0.5;
std::vector<double> x0(init.data(), init.data() + init.size());
// -1 for automatically decided lambda, 0 is for random seeding of the internal generator.
CMAParameters<> cmaparams(x0, sigma);
_set_common_params(cmaparams, dim);
// used by restart I think
......
......@@ -207,9 +207,16 @@ struct Params {
struct acqui_gpucb : public defaults::acqui_gpucb {
};
#ifdef USE_LIBCMAES
struct opt_cmaes : public defaults::opt_cmaes {
};
#elif defined(USE_NLOPT)
struct opt_nloptnograd : public defaults::opt_nloptnograd {
};
#else
struct opt_gridsearch : public defaults::opt_gridsearch {
};
#endif
struct opt_rprop : public defaults::opt_rprop {
};
......
......@@ -41,9 +41,16 @@ struct Params {
struct acqui_gpucb : public defaults::acqui_gpucb {
};
#ifdef USE_LIBCMAES
struct opt_cmaes : public defaults::opt_cmaes {
};
#elif defined(USE_NLOPT)
struct opt_nloptnograd : public defaults::opt_nloptnograd {
};
#else
struct opt_gridsearch : public defaults::opt_gridsearch {
};
#endif
struct opt_rprop : public defaults::opt_rprop {
};
......@@ -156,4 +163,4 @@ BOOST_AUTO_TEST_CASE(grid_sampling)
BOOST_CHECK(x[i] == 0 || x[i] == 0.25 || x[i] == 0.5 || x[i] == 0.75 || x[i] == 1.0);
}
}
}
\ No newline at end of file
}
......@@ -21,9 +21,6 @@ struct Params {
struct opt_gridsearch {
BO_PARAM(int, bins, 20);
};
struct opt_cmaes : public defaults::opt_cmaes {
};
};
int monodim_calls = 0;
......@@ -149,11 +146,17 @@ BOOST_AUTO_TEST_CASE(test_grid_search_bi_dim)
BOOST_CHECK_EQUAL(bidim_calls, (Params::opt_gridsearch::bins() + 1) * (Params::opt_gridsearch::bins() + 1) + 21);
}
#ifdef USE_LIBCMAES
struct Params2 {
struct opt_cmaes : public defaults::opt_cmaes {
};
};
BOOST_AUTO_TEST_CASE(test_cmaes_mono_dim)
{
using namespace limbo;
opt::Cmaes<Params> optimizer;
opt::Cmaes<Params2> optimizer;
FakeAcquiMono f;
Eigen::VectorXd best_point = optimizer(make_functor_optimization(f), true);
......@@ -166,7 +169,7 @@ BOOST_AUTO_TEST_CASE(test_cmaes_bi_dim)
{
using namespace limbo;
opt::Cmaes<Params> optimizer;
opt::Cmaes<Params2> optimizer;
FakeAcquiBi f;
auto f_optimization = make_functor_optimization(f);
......@@ -176,3 +179,4 @@ BOOST_AUTO_TEST_CASE(test_cmaes_bi_dim)
BOOST_CHECK_CLOSE(best_point(0), 1, 0.0001);
BOOST_CHECK_SMALL(best_point(1), 0.000001);
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment