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

add 'update the examples and the tests to use the new tools::make_vector

parent 03736a60
......@@ -73,13 +73,6 @@ inline Eigen::VectorXd t_osz(const Eigen::VectorXd& x)
return r;
}
Eigen::VectorXd make_v1(double x)
{
Eigen::VectorXd v1(1);
v1 << x;
return v1;
}
struct Sphere {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
......@@ -87,7 +80,7 @@ struct Sphere {
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
Eigen::Vector2d opt(0.5, 0.5);
return make_v1(-(x - opt).squaredNorm());
return tools::make_vector(-(x - opt).squaredNorm());
}
};
......@@ -102,7 +95,7 @@ struct Ellipsoid {
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;
return make_v1(-r);
return tools::make_vector(-r);
}
};
......@@ -115,7 +108,7 @@ struct Rastrigin {
double f = 10 * x.size();
for (int i = 0; i < x.size(); ++i)
f += x(i) * x(i) - 10 * cos(2 * M_PI * x(i));
return make_v1(-f);
return tools::make_vector(-f);
}
};
......@@ -141,7 +134,7 @@ struct Hartman3 {
}
res += alpha(i) * exp(-s);
}
return make_v1(res);
return tools::make_vector(res);
}
};
......@@ -170,7 +163,7 @@ struct Hartman6 {
}
res += alpha(i) * exp(-s);
}
return make_v1(res);
return tools::make_vector(res);
}
};
......@@ -185,7 +178,7 @@ struct GoldenPrice {
Eigen::VectorXd x = (4.0 * xx).array() - 2.0;
double r = (1 + (x(0) + x(1) + 1) * (x(0) + x(1) + 1) * (19 - 14 * x(0) + 3 * x(0) * x(0) - 14 * x(1) + 6 * x(0) * x(1) + 3 * x(1) * x(1))) * (30 + (2 * x(0) - 3 * x(1)) * (2 * x(0) - 3 * x(1)) * (18 - 32 * x(0) + 12 * x(0) * x(0) + 48 * x(1) - 36 * x(0) * x(1) + 27 * x(1) * x(1)));
return make_v1(-log(r) + 5);
return tools::make_vector(-log(r) + 5);
}
};
......
......@@ -36,7 +36,7 @@ BO_PARAMS(std::cout,
};
struct bayes_opt_boptimizer {
BO_PARAM(double, noise, 0.001);
BO_PARAM(double, noise, 0.001);
};
struct init_randomsampling {
......@@ -54,11 +54,10 @@ struct fit_eval {
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
Eigen::VectorXd res(1);
res(0) = 0;
double res = 0;
for (int i = 0; i < x.size(); i++)
res(0) += 1 - (x[i] - 0.3) * (x[i] - 0.3) + sin(10 * x[i]) * 0.2;
return res;
res += 1 - (x[i] - 0.3) * (x[i] - 0.3) + sin(10 * x[i]) * 0.2;
return tools::make_vector(res);
}
};
......
......@@ -45,12 +45,7 @@ namespace limbo {
protected:
size_t _nb_objs;
Eigen::VectorXd _make_v1(double x)
{
Eigen::VectorXd v1(1);
v1 << x;
return v1;
}
std::vector<Eigen::VectorXd> _scalarize_obs(const std::vector<Eigen::VectorXd>& observations)
{
Eigen::VectorXd lambda = tools::random_vector(_nb_objs);
......@@ -61,7 +56,7 @@ namespace limbo {
for (auto x : observations) {
double y = (lambda.array() * x.array()).maxCoeff();
double s = (lambda.array() * x.array()).sum();
auto v = _make_v1(y + Params::model_gp_parego::rho() * s);
auto v = tools::make_vector(y + Params::model_gp_parego::rho() * s);
scalarized.push_back(v);
}
return scalarized;
......
......@@ -70,12 +70,6 @@ inline Eigen::VectorXd t_osz(const Eigen::VectorXd& x)
return r;
}
Eigen::VectorXd make_v1(double x)
{
Eigen::VectorXd v1(1);
v1 << x;
return v1;
}
struct Sphere {
static constexpr size_t dim_in = 2;
......@@ -84,7 +78,7 @@ struct Sphere {
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{
Eigen::Vector2d opt(0.5, 0.5);
return make_v1(-(x - opt).squaredNorm());
return tools::make_vector(-(x - opt).squaredNorm());
}
};
......@@ -99,7 +93,7 @@ struct Ellipsoid {
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;
return make_v1(-r);
return tools::make_vector(-r);
}
};
......@@ -112,7 +106,7 @@ struct Rastrigin {
double f = 10 * x.size();
for (int i = 0; i < x.size(); ++i)
f += x(i) * x(i) - 10 * cos(2 * M_PI * x(i));
return make_v1(-f);
return tools::make_vector(-f);
}
};
......@@ -138,7 +132,7 @@ struct Hartman3 {
}
res += alpha(i) * exp(-s);
}
return make_v1(res);
return tools::make_vector(res);
}
};
......@@ -167,7 +161,7 @@ struct Hartman6 {
}
res += alpha(i) * exp(-s);
}
return make_v1(res);
return tools::make_vector(res);
}
};
......@@ -182,7 +176,7 @@ struct GoldenPrice {
Eigen::VectorXd x = (4.0 * xx).array() - 2.0;
double r = (1 + (x(0) + x(1) + 1) * (x(0) + x(1) + 1) * (19 - 14 * x(0) + 3 * x(0) * x(0) - 14 * x(1) + 6 * x(0) * x(1) + 3 * x(1) * x(1))) * (30 + (2 * x(0) - 3 * x(1)) * (2 * x(0) - 3 * x(1)) * (18 - 32 * x(0) + 12 * x(0) * x(0) + 48 * x(1) - 36 * x(0) * x(1) + 27 * x(1) * x(1)));
return make_v1(-log(r) + 5);
return tools::make_vector(-log(r) + 5);
}
};
......
......@@ -16,9 +16,7 @@ using namespace limbo;
Eigen::VectorXd make_v1(double x)
{
Eigen::VectorXd v1(1);
v1 << x;
return v1;
return tools::make_vector(x);
}
Eigen::VectorXd make_v2(double x1, double x2)
......
......@@ -10,13 +10,6 @@
using namespace limbo;
Eigen::VectorXd make_v1(double x)
{
Eigen::VectorXd v1(1);
v1 << x;
return v1;
}
struct Params {
struct bayes_opt_bobase {
BO_PARAM(bool, stats_enabled, false);
......@@ -67,7 +60,7 @@ struct fit_eval {
double res = 0;
for (int i = 0; i < x.size(); i++)
res += 1 - (x[i] - 0.3) * (x[i] - 0.3) + sin(10 * x[i]) * 0.2;
return make_v1(res);
return tools::make_vector(res);
}
};
......
......@@ -11,13 +11,6 @@
using namespace limbo;
Eigen::VectorXd make_v1(double x)
{
Eigen::VectorXd v1(1);
v1 << x;
return v1;
}
struct Params {
struct opt_gridsearch {
BO_PARAM(int, bins, 20);
......
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