Commit 16817c85 authored by Konstantinos Chatzilygeroudis's avatar Konstantinos Chatzilygeroudis
Browse files

Fix for libcmaes and compilation errors

parent de31338e
......@@ -5,8 +5,9 @@ sudo mkdir build && cd build
sudo cmake ..
sudo make
sudo cp *.a /usr/lib
cd && git clone https://github.com/beniz/libcmaes.git
cd && git https://github.com/resibots/libcmaes.git
cd libcmaes
git checkout fix_flags
./autogen.sh
./configure
make
......
......@@ -54,7 +54,7 @@ void benchmark(const bopt_params& par, const std::string& name)
{
auto t1 = std::chrono::steady_clock::now();
Benchmark<Function> benchmark(par);
vectord result(Function::dim_in);
vectord result(Function::dim_in());
benchmark.optimize(result);
auto time_running = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout.precision(17);
......
......@@ -54,7 +54,7 @@ void benchmark(const bopt_params& par, const std::string& name)
{
auto t1 = std::chrono::steady_clock::now();
Benchmark<Function> benchmark(par);
vectord result(Function::dim_in);
vectord result(Function::dim_in());
benchmark.optimize(result);
auto time_running = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout.precision(17);
......
......@@ -97,8 +97,8 @@ inline vectord t_osz(const vectord& x)
}
struct Sphere {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
double operator()(const vectord& x) const
{
......@@ -117,8 +117,8 @@ struct Sphere {
};
struct Ellipsoid {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
double operator()(const vectord& x) const
{
......@@ -126,8 +126,8 @@ struct Ellipsoid {
opt <<= 0.5, 0.5;
vectord z = t_osz(x - opt);
double r = 0;
for (size_t i = 0; i < dim_in; ++i)
r += std::pow(10, ((double)i) / (dim_in - 1.0)) * z(i) * z(i) + 1;
for (size_t i = 0; i < dim_in(); ++i)
r += std::pow(10, ((double)i) / (dim_in() - 1.0)) * z(i) * z(i) + 1;
return r;
}
......@@ -140,21 +140,21 @@ struct Ellipsoid {
};
struct Rastrigin {
static constexpr size_t dim_in = 4;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 4);
BO_PARAM(size_t, dim_out, 1);
double operator()(const vectord& x) const
{
double f = 10 * dim_in;
for (size_t i = 0; i < dim_in; ++i)
double f = 10 * dim_in();
for (size_t i = 0; i < dim_in(); ++i)
f += x(i) * x(i) - 10 * cos(2 * M_PI * x(i));
return f;
}
matrixd solutions() const
{
matrixd sols(1, dim_in);
for (size_t i = 0; i < dim_in; ++i)
matrixd sols(1, dim_in());
for (size_t i = 0; i < dim_in(); ++i)
sols(0, i) = 0;
return sols;
}
......@@ -162,8 +162,8 @@ struct Rastrigin {
// see : http://www.sfu.ca/~ssurjano/hart3.html
struct Hartmann3 {
static constexpr size_t dim_in = 3;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 3);
BO_PARAM(size_t, dim_out, 1);
double operator()(const vectord& x) const
{
......@@ -196,8 +196,8 @@ struct Hartmann3 {
// see : http://www.sfu.ca/~ssurjano/hart6.html
struct Hartmann6 {
static constexpr size_t dim_in = 6;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 6);
BO_PARAM(size_t, dim_out, 1);
double operator()(const vectord& x) const
{
......@@ -234,8 +234,8 @@ struct Hartmann6 {
// see : http://www.sfu.ca/~ssurjano/goldpr.html
// (with ln, as suggested in Jones et al.)
struct GoldsteinPrice {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
double operator()(const vectord& xx) const
{
......@@ -256,8 +256,8 @@ struct GoldsteinPrice {
};
struct BraninNormalized {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
double operator()(const vectord& x) const
{
......@@ -277,8 +277,9 @@ struct BraninNormalized {
};
struct SixHumpCamel {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
double operator()(const vectord& x) const
{
double x1 = -3 + 6 * x(0);
......@@ -308,7 +309,7 @@ struct SixHumpCamel {
template <typename Function>
class Benchmark : public bayesopt::ContinuousModel {
public:
Benchmark(bopt_params par) : ContinuousModel(Function::dim_in, par) {}
Benchmark(bopt_params par) : ContinuousModel(Function::dim_in(), par) {}
double evaluateSample(const vectord& xin)
{
......
......@@ -109,10 +109,10 @@ template <typename Optimizer, typename Function>
void benchmark(const std::string& name)
{
int iters_base = 250;
DirectParams::opt_nloptnograd::set_iterations(static_cast<int>(iters_base * Function::dim_in * 0.9));
BobyqaParams::opt_nloptnograd::set_iterations(iters_base * Function::dim_in - DirectParams::opt_nloptnograd::iterations());
DirectParams::opt_nloptnograd::set_iterations(static_cast<int>(iters_base * Function::dim_in() * 0.9));
BobyqaParams::opt_nloptnograd::set_iterations(iters_base * Function::dim_in() - DirectParams::opt_nloptnograd::iterations());
BobyqaParams_HP::opt_nloptnograd::set_iterations(10 * Function::dim_in * Function::dim_in);
BobyqaParams_HP::opt_nloptnograd::set_iterations(10 * Function::dim_in() * Function::dim_in());
auto t1 = std::chrono::steady_clock::now();
Optimizer opt;
......
......@@ -99,8 +99,8 @@ template <typename Optimizer, typename Function>
void benchmark(const std::string& name)
{
int iters_base = 250;
DirectParams::opt_nloptnograd::set_iterations(static_cast<int>(iters_base * Function::dim_in * 0.9));
BobyqaParams::opt_nloptnograd::set_iterations(iters_base * Function::dim_in - DirectParams::opt_nloptnograd::iterations());
DirectParams::opt_nloptnograd::set_iterations(static_cast<int>(iters_base * Function::dim_in() * 0.9));
BobyqaParams::opt_nloptnograd::set_iterations(iters_base * Function::dim_in() - DirectParams::opt_nloptnograd::iterations());
auto t1 = std::chrono::steady_clock::now();
Optimizer opt;
......
......@@ -91,8 +91,8 @@ inline Eigen::VectorXd t_osz(const Eigen::VectorXd& x)
}
struct Sphere {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
double operator()(const Eigen::VectorXd& x) const
{
......@@ -111,8 +111,8 @@ struct Sphere {
};
struct Ellipsoid {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
double operator()(const Eigen::VectorXd& x) const
{
......@@ -120,8 +120,8 @@ struct Ellipsoid {
opt << 0.5, 0.5;
Eigen::VectorXd z = t_osz(x - opt);
double r = 0;
for (size_t i = 0; i < dim_in; ++i)
r += std::pow(10, ((double)i) / (dim_in - 1.0)) * z(i) * z(i) + 1;
for (size_t i = 0; i < dim_in(); ++i)
r += std::pow(10, ((double)i) / (dim_in() - 1.0)) * z(i) * z(i) + 1;
return r;
}
......@@ -134,14 +134,14 @@ struct Ellipsoid {
};
struct Rastrigin {
static constexpr size_t dim_in = 4;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 4);
BO_PARAM(size_t, dim_out, 1);
double operator()(const Eigen::VectorXd& x) const
{
double f = 10 * dim_in;
for (size_t i = 0; i < dim_in; ++i)
f += x(i) * x(i) - 10 * cos(2 * M_PI * x(i));
double f = 10 * dim_in();
for (size_t i = 0; i < dim_in(); ++i)
f += x(i) * x(i) - 10 * std::cos(2 * M_PI * x(i));
return f;
}
......@@ -156,8 +156,8 @@ struct Rastrigin {
// see : http://www.sfu.ca/~ssurjano/hart3.html
struct Hartmann3 {
static constexpr size_t dim_in = 3;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 3);
BO_PARAM(size_t, dim_out, 1);
double operator()(const Eigen::VectorXd& x) const
{
......@@ -190,8 +190,8 @@ struct Hartmann3 {
// see : http://www.sfu.ca/~ssurjano/hart6.html
struct Hartmann6 {
static constexpr size_t dim_in = 6;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 6);
BO_PARAM(size_t, dim_out, 1);
double operator()(const Eigen::VectorXd& x) const
{
......@@ -228,8 +228,8 @@ struct Hartmann6 {
// see : http://www.sfu.ca/~ssurjano/goldpr.html
// (with ln, as suggested in Jones et al.)
struct GoldsteinPrice {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
double operator()(const Eigen::VectorXd& xx) const
{
......@@ -250,8 +250,8 @@ struct GoldsteinPrice {
};
struct BraninNormalized {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
double operator()(const Eigen::VectorXd& x) const
{
......@@ -271,8 +271,9 @@ struct BraninNormalized {
};
struct SixHumpCamel {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
double operator()(const Eigen::VectorXd& x) const
{
double x1 = -3 + 6 * x(0);
......@@ -302,8 +303,8 @@ struct SixHumpCamel {
template <typename Function>
class Benchmark {
public:
static constexpr size_t dim_in = Function::dim_in;
static constexpr size_t dim_out = Function::dim_out;
BO_PARAM(size_t, dim_in, Function::dim_in());
BO_PARAM(size_t, dim_out, Function::dim_out());
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......
......@@ -93,9 +93,9 @@ struct Params {
};
struct cosine {
static constexpr size_t dim_in = 1;
static constexpr size_t dim_out = 1;
static constexpr size_t nb_constraints = 1;
BO_PARAM(size_t, dim_in, 1);
BO_PARAM(size_t, dim_out, 1);
BO_PARAM(size_t, nb_constraints, 1);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......
......@@ -119,8 +119,8 @@ inline Eigen::VectorXd t_osz(const Eigen::VectorXd& x)
}
struct Sphere {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......@@ -130,23 +130,23 @@ struct Sphere {
};
struct Ellipsoid {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
Eigen::Vector2d opt(0.5, 0.5);
Eigen::Vector2d z = t_osz(x - opt);
double r = 0;
for (size_t i = 0; i < dim_in; ++i)
r += std::pow(10, ((double)i) / (dim_in - 1.0)) * z(i) * z(i) + 1;
for (size_t i = 0; i < dim_in(); ++i)
r += std::pow(10, ((double)i) / (dim_in() - 1.0)) * z(i) * z(i) + 1;
return tools::make_vector(-r);
}
};
struct Rastrigin {
static constexpr size_t dim_in = 4;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 4);
BO_PARAM(size_t, dim_out, 1);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......@@ -159,8 +159,8 @@ struct Rastrigin {
// see : http://www.sfu.ca/~ssurjano/hart3.html
struct Hartman3 {
static constexpr size_t dim_in = 3;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 3);
BO_PARAM(size_t, dim_out, 1);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......@@ -185,8 +185,8 @@ struct Hartman3 {
// see : http://www.sfu.ca/~ssurjano/hart6.html
struct Hartman6 {
static constexpr size_t dim_in = 6;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 6);
BO_PARAM(size_t, dim_out, 1);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......@@ -215,8 +215,8 @@ struct Hartman6 {
// see : http://www.sfu.ca/~ssurjano/goldpr.html
// (with ln, as suggested in Jones et al.)
struct GoldenPrice {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
Eigen::VectorXd operator()(const Eigen::VectorXd& xx) const
{
......
......@@ -118,8 +118,8 @@ struct Params {
#endif
struct zdt1 {
static constexpr size_t dim_in = ZDT_DIM;
static constexpr size_t dim_out = 2;
BO_PARAM(size_t, dim_in, ZDT_DIM);
BO_PARAM(size_t, dim_out, 2);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......@@ -137,8 +137,8 @@ struct zdt1 {
};
struct zdt2 {
static constexpr size_t dim_in = ZDT_DIM;
static constexpr size_t dim_out = 2;
BO_PARAM(size_t, dim_in, ZDT_DIM);
BO_PARAM(size_t, dim_out, 2);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......@@ -156,8 +156,8 @@ struct zdt2 {
};
struct zdt3 {
static constexpr size_t dim_in = ZDT_DIM;
static constexpr size_t dim_out = 2;
BO_PARAM(size_t, dim_in, ZDT_DIM);
BO_PARAM(size_t, dim_out, 2);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......@@ -175,8 +175,8 @@ struct zdt3 {
};
struct mop2 {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 2;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 2);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......
......@@ -106,8 +106,8 @@ struct Params {
// original is mimimization, objectives in [0,1], we transform it to max
// ref point should be 10, 10 (same hypervolume)
struct zdt2 {
static constexpr size_t dim_in = 30;
static constexpr size_t dim_out = 2;
BO_PARAM(size_t, dim_in, 30);
BO_PARAM(size_t, dim_out, 2);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......@@ -125,8 +125,8 @@ struct zdt2 {
};
struct mop2 {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 2;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 2);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......
......@@ -101,8 +101,8 @@ BO_PARAMS(std::cout,
};)
struct fit_eval {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......
......@@ -92,8 +92,8 @@ struct Params {
};
struct StateEval {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 2;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 2);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......
......@@ -190,8 +190,8 @@ struct MeanComplet {
};
struct fit_eval {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 2;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 2);
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
......
......@@ -144,7 +144,7 @@ namespace limbo {
if (!this->_observations.empty())
_model.compute(this->_samples, this->_observations);
else
_model = model_t(StateFunction::dim_in, StateFunction::dim_out);
_model = model_t(StateFunction::dim_in(), StateFunction::dim_out());
acqui_optimizer_t acqui_optimizer;
......@@ -153,7 +153,7 @@ namespace limbo {
auto acqui_optimization =
[&](const Eigen::VectorXd& x, bool g) { return acqui(x,afun,g); };
Eigen::VectorXd starting_point = tools::random_vector(StateFunction::dim_in, Params::bayes_opt_bobase::bounded());
Eigen::VectorXd starting_point = tools::random_vector(StateFunction::dim_in(), Params::bayes_opt_bobase::bounded());
Eigen::VectorXd new_sample = acqui_optimizer(acqui_optimization, starting_point, Params::bayes_opt_bobase::bounded());
this->eval_and_add(sfun, new_sample);
......
......@@ -148,8 +148,8 @@ namespace limbo {
template <typename StateFunction, typename AggregatorFunction = FirstElem>
void optimize(const StateFunction& sfun, const AggregatorFunction& afun = AggregatorFunction(), bool reset = true)
{
_nb_constraints = StateFunction::nb_constraints;
_dim_out = StateFunction::dim_out;
_nb_constraints = StateFunction::nb_constraints();
_dim_out = StateFunction::dim_out();
this->_init(sfun, afun, reset);
......@@ -160,9 +160,9 @@ namespace limbo {
_constraint_model.compute(this->_samples, _obs[1]);
}
else {
_model = model_t(StateFunction::dim_in, StateFunction::dim_out);
_model = model_t(StateFunction::dim_in(), StateFunction::dim_out());
if (_nb_constraints > 0)
_constraint_model = constraint_model_t(StateFunction::dim_in, _nb_constraints);
_constraint_model = constraint_model_t(StateFunction::dim_in(), _nb_constraints);
}
acqui_optimizer_t acqui_optimizer;
......@@ -172,7 +172,7 @@ namespace limbo {
auto acqui_optimization =
[&](const Eigen::VectorXd& x, bool g) { return acqui(x,afun,g); };
Eigen::VectorXd starting_point = tools::random_vector(StateFunction::dim_in, Params::bayes_opt_cboptimizer::bounded());
Eigen::VectorXd starting_point = tools::random_vector(StateFunction::dim_in(), Params::bayes_opt_cboptimizer::bounded());
Eigen::VectorXd new_sample = acqui_optimizer(acqui_optimization, starting_point, Params::bayes_opt_cboptimizer::bounded());
this->eval_and_add(sfun, new_sample);
......
......@@ -107,7 +107,7 @@ namespace limbo {
acqui_optimizer_t inner_opt;
while (this->_samples.size() == 0 || !this->_stop(*this, FirstElem())) {
this->template update_pareto_model<EvalFunction::dim_in>();
this->template update_pareto_model<EvalFunction::dim_in()>();
this->update_pareto_data();
// copy in the ehvi structure to compute expected improvement
......
......@@ -99,12 +99,12 @@ namespace limbo {
_init_tree(h_upper);
// Init model
_model = model_t(StateFunction::dim_in, StateFunction::dim_out);
_model = model_t(StateFunction::dim_in(), StateFunction::dim_out());
// Init root
_tree[0].x_max.push_back(Eigen::VectorXd::Ones(StateFunction::dim_in));
_tree[0].x_min.push_back(Eigen::VectorXd::Zero(StateFunction::dim_in));
_tree[0].x.push_back(Eigen::VectorXd::Ones(StateFunction::dim_in) * 0.5);
_tree[0].x_max.push_back(Eigen::VectorXd::Ones(StateFunction::dim_in()));
_tree[0].x_min.push_back(Eigen::VectorXd::Zero(StateFunction::dim_in()));
_tree[0].x.push_back(Eigen::VectorXd::Ones(StateFunction::dim_in()) * 0.5);
_tree[0].f.push_back(sfun(_tree[0].x[0]));
_tree[0].leaf.push_back(true);
_tree[0].samp.push_back(true);
......
......@@ -74,7 +74,7 @@ namespace limbo {
while (this->_samples.size() == 0 || !this->_stop(*this, FirstElem())) {
std::cout << "updating pareto model...";
std::cout.flush();
this->template update_pareto_model<EvalFunction::dim_in>();
this->template update_pareto_model<EvalFunction::dim_in()>();
std::cout << "ok" << std::endl;
auto pareto = this->pareto_model();
......
......@@ -58,7 +58,7 @@ namespace limbo {
{
opt.update_pareto_data();