Commit 84dc0fbd authored by Federico Allocati's avatar Federico Allocati
Browse files

Renamed all parameters struct to follow a convention. Made parameters names consistent

parent 72a3a00f
......@@ -9,32 +9,35 @@ using namespace limbo;
BO_PARAMS(std::cout,
struct Params {
struct gp_ucb : public defaults::gp_ucb {
struct acqui_gpucb : public defaults::acqui_gpucb {
};
struct cmaes : public defaults::cmaes {
struct opt_cmaes : public defaults::opt_cmaes {
};
struct ucb {
struct acqui_ucb {
BO_PARAM(double, alpha, 0.1);
};
struct kf_maternfivehalfs {
struct kernel_maternfivehalfs {
BO_PARAM(double, sigma, 1);
BO_PARAM(double, l, 0.2);
};
struct boptimizer {
BO_PARAM(double, noise, 0.001);
BO_PARAM(bool, stats_enabled, true);
struct bayes_opt_bobase {
BO_PARAM(bool, stats_enabled, true);
};
struct init {
BO_PARAM(int, nb_samples, 5);
struct bayes_opt_boptimizer {
BO_PARAM(double, noise, 0.001);
};
struct maxiterations {
BO_PARAM(int, n_iterations, 20);
struct init_randomsampling {
BO_PARAM(int, samples, 5);
};
struct stop_maxiterations {
BO_PARAM(int, iterations, 20);
};
};)
......
......@@ -8,28 +8,31 @@
using namespace limbo;
struct Params {
struct gp_ucb : public defaults::gp_ucb {
struct acqui_gpucb : public defaults::acqui_gpucb {
};
struct cmaes : public defaults::cmaes {
struct opt_cmaes : public defaults::opt_cmaes {
};
struct kf_maternfivehalfs {
struct kernel_maternfivehalfs {
BO_PARAM(double, sigma, 1);
BO_PARAM(double, l, 0.2);
};
struct boptimizer {
BO_PARAM(double, noise, 0.001);
struct bayes_opt_bobase {
BO_PARAM(bool, stats_enabled, true);
};
struct init {
BO_PARAM(int, nb_samples, 5);
struct bayes_opt_boptimizer {
BO_PARAM(double, noise, 0.001);
};
struct init_randomsampling {
BO_PARAM(int, samples, 5);
};
struct maxiterations {
BO_PARAM(int, n_iterations, 20);
struct stop_maxiterations {
BO_PARAM(int, iterations, 20);
};
};
......
......@@ -8,36 +8,35 @@
using namespace limbo;
struct Params {
struct gp_auto_mean {
BO_PARAM(int, n_rprop, 100);
BO_PARAM(int, rprop_restart, 10);
struct opt_cmaes : public defaults::opt_cmaes {
};
struct cmaes : public defaults::cmaes {
struct opt_rprop : public defaults::opt_rprop {
};
struct rprop : public defaults::rprop {
};
struct kf_maternfivehalfs {
struct kernel_maternfivehalfs {
BO_PARAM(double, sigma, 1);
BO_PARAM(double, l, 0.2);
};
struct boptimizer {
struct bayes_opt_bobase {
BO_PARAM(bool, stats_enabled, true);
};
struct bayes_opt_boptimizer {
BO_PARAM(double, noise, 0.001);
BO_PARAM(bool, stats_enabled, true);
};
struct init {
BO_PARAM(int, nb_samples, 5);
struct init_randomsampling {
BO_PARAM(int, samples, 5);
};
struct maxiterations {
BO_PARAM(int, n_iterations, 100);
struct stop_maxiterations {
BO_PARAM(int, iterations, 100);
};
struct parallel_repeater : defaults::parallel_repeater {
struct opt_parallelrepeater : defaults::opt_parallelrepeater {
};
};
......
......@@ -3,37 +3,34 @@
using namespace limbo;
struct Params {
struct boptimizer {
BO_PARAM(double, noise, 0.005);
BO_PARAM(bool, stats_enabled, true);
};
struct init {
BO_PARAM(int, nb_samples, 21);
struct init_randomsampling {
BO_PARAM(int, samples, 21);
// calandra: number of dimensions * 5
// knowles : 11 * dim - 1
};
struct maxiterations {
BO_PARAM(int, n_iterations, 30);
struct stop_maxiterations {
BO_PARAM(int, iterations, 30);
};
struct ucb : public defaults::ucb {
struct acqui_ucb : public defaults::acqui_ucb {
};
struct gp_ucb : public defaults::gp_ucb {
struct acqui_gpucb : public defaults::acqui_gpucb {
};
struct cmaes : public defaults::cmaes {
struct opt_cmaes : public defaults::opt_cmaes {
};
struct gp_auto : public defaults::gp_auto {
struct mean_constant : public defaults::mean_constant {
};
struct meanconstant : public defaults::meanconstant {
struct bayes_opt_bobase {
BO_PARAM(bool, stats_enabled, true);
};
struct parego : public defaults::parego {
struct bayes_opt_parego : public defaults::bayes_opt_parego {
BO_PARAM(double, noise, 0.005);
};
};
......@@ -85,7 +82,7 @@ int main()
// typedef model::GP<Params, kernel_t, mean_t> gp_t;
// typedef acquisition_functions::UCB<Params, gp_t> ucb_t;
// Parego<Params, model_fun<gp_t>, acq_fun<ucb_t> > opt;
Parego<Params> opt;
bayes_opt::Parego<Params> opt;
opt.optimize(mop2());
std::cout << "optimization done" << std::endl;
......
......@@ -6,13 +6,11 @@
#include <limbo/tools/macros.hpp>
namespace limbo {
namespace defaults {
struct gp_ucb {
struct acqui_gpucb {
BO_PARAM(double, delta, 0.001);
};
}
namespace acqui {
template <typename Params, typename Model>
class GP_UCB {
......@@ -20,7 +18,7 @@ namespace limbo {
GP_UCB(const Model& model, int iteration) : _model(model)
{
double t3 = pow(iteration, 3.0);
static constexpr double delta3 = Params::gp_ucb::delta() * 3;
static constexpr double delta3 = Params::acqui_gpucb::delta() * 3;
static constexpr double pi2 = M_PI * M_PI;
_beta = sqrtf(2.0 * log(t3 * pi2 / delta3));
}
......
......@@ -6,13 +6,11 @@
#include <limbo/tools/macros.hpp>
namespace limbo {
namespace defaults {
struct ucb {
struct acqui_ucb {
BO_PARAM(double, alpha, 0.5);
};
}
namespace acqui {
template <typename Params, typename Model>
class UCB {
......@@ -29,7 +27,7 @@ namespace limbo {
Eigen::VectorXd mu;
double sigma;
std::tie(mu, sigma) = _model.query(v);
return (afun(mu) + Params::ucb::alpha() * sqrt(sigma));
return (afun(mu) + Params::acqui_ucb::alpha() * sqrt(sigma));
}
protected:
......
......@@ -15,6 +15,7 @@
#include <Eigen/Core>
// we need everything to have the defaults
#include <limbo/tools/macros.hpp>
#include <limbo/stop/chain_criteria.hpp>
#include <limbo/stop/max_iterations.hpp>
#include <limbo/stat/samples.hpp>
......@@ -29,7 +30,11 @@
#include <limbo/init/random_sampling.hpp>
namespace limbo {
namespace defaults {
struct bayes_opt_bobase {
BO_PARAM(bool, stats_enabled, true);
};
}
template <typename BO, typename AggregatorFunction>
struct RefreshStat_f {
RefreshStat_f(BO& bo, const AggregatorFunction& afun, bool blacklisted)
......@@ -125,7 +130,7 @@ namespace limbo {
BoBase(const BoBase& other) = delete;
BoBase& operator=(const BoBase& other) = delete;
bool stats_enabled() const { return Params::boptimizer::stats_enabled(); }
bool stats_enabled() const { return Params::bayes_opt_bobase::stats_enabled(); }
const std::string& res_dir() const { return _res_dir; }
......@@ -183,7 +188,7 @@ namespace limbo {
void _make_res_dir()
{
if (!Params::boptimizer::stats_enabled())
if (!Params::bayes_opt_bobase::stats_enabled())
return;
_res_dir = tools::hostname() + "_" + tools::date() + "_" + tools::getpid();
boost::filesystem::path my_path(_res_dir);
......
......@@ -10,9 +10,15 @@
#include <Eigen/Core>
#include <limbo/tools/macros.hpp>
#include <limbo/bayes_opt/bo_base.hpp>
namespace limbo {
namespace defaults {
struct bayes_opt_boptimizer {
BO_PARAM(double, noise, 1e-6);
};
}
namespace bayes_opt {
template <class Params, class A1 = boost::parameter::void_,
......@@ -59,7 +65,7 @@ namespace limbo {
this->_init(sfun, afun, reset);
if (!this->_observations.empty())
_model.compute(this->_samples, this->_observations, Params::boptimizer::noise(), this->_bl_samples);
_model.compute(this->_samples, this->_observations, Params::bayes_opt_boptimizer::noise(), this->_bl_samples);
acqui_optimizer_t acqui_optimizer;
......@@ -98,7 +104,7 @@ namespace limbo {
std::cout << " best:" << afun(this->best_observation(afun)) << std::endl;
if (!this->_observations.empty())
_model.compute(this->_samples, this->_observations, Params::boptimizer::noise(), this->_bl_samples);
_model.compute(this->_samples, this->_observations, Params::bayes_opt_boptimizer::noise(), this->_bl_samples);
this->_current_iteration++;
this->_total_iterations++;
......
......@@ -6,10 +6,17 @@
#include <ehvi/ehvi_calculations.h>
#include <ehvi/ehvi_sliceupdate.h>
#include <limbo/tools/macros.hpp>
#include <limbo/bayes_opt/bo_multi.hpp>
#include <limbo/acqui/ehvi.hpp>
namespace limbo {
namespace defaults {
struct bayes_opt_ehvi {
BO_PARAM(double, x_ref, -11);
BO_PARAM(double, y_ref, -11);
};
}
namespace bayes_opt {
template <class Params, class A2 = boost::parameter::void_,
class A3 = boost::parameter::void_, class A4 = boost::parameter::void_,
......@@ -49,7 +56,7 @@ namespace limbo {
auto acqui = acqui::Ehvi<Params, model_t>(
this->_models, pop,
Eigen::Vector3d(Params::ehvi::x_ref(), Params::ehvi::y_ref(), 0));
Eigen::Vector3d(Params::bayes_opt_ehvi::x_ref(), Params::bayes_opt_ehvi::y_ref(), 0));
// maximize with CMA-ES
typedef std::pair<Eigen::VectorXd, double> pair_t;
......
......@@ -3,16 +3,16 @@
#include <algorithm>
#include <limbo/limbo.hpp>
#include <limbo/tools/macros.hpp>
#include <limbo/bayes_opt/bo_multi.hpp>
namespace limbo {
namespace defaults {
struct parego {
struct bayes_opt_parego {
BO_PARAM(double, noise, 1e-6);
BO_PARAM(double, rho, 0.05);
};
}
namespace bayes_opt {
template <class Params, class A3 = boost::parameter::void_,
......@@ -34,7 +34,7 @@ namespace limbo {
std::vector<double> scalarized = _scalarize_obs();
model_t model(EvalFunction::dim);
model.compute(this->_samples, scalarized, Params::boptimizer::noise());
model.compute(this->_samples, scalarized, Params::bayes_opt_parego::noise());
acqui_optimizer_t inner_optimization;
......@@ -47,7 +47,7 @@ namespace limbo {
<< " | new sample:" << new_sample.transpose() << " => "
<< feval(new_sample).transpose() << std::endl;
scalarized = _scalarize_obs();
model.compute(this->_samples, scalarized, Params::boptimizer::noise());
model.compute(this->_samples, scalarized, Params::bayes_opt_parego::noise());
this->_update_stats(*this, FirstElem(), false);
this->_current_iteration++;
this->_total_iterations++;
......@@ -70,7 +70,7 @@ namespace limbo {
for (auto x : this->_observations) {
double y = (lambda.array() * x.array()).maxCoeff();
double s = (lambda.array() * x.array()).sum();
scalarized.push_back(y + Params::parego::rho() * s);
scalarized.push_back(y + Params::bayes_opt_parego::rho() * s);
}
return scalarized;
}
......
......@@ -3,10 +3,15 @@
#include <Eigen/Core>
#include <limbo/tools/macros.hpp>
namespace limbo {
namespace defaults {
struct init_gridsampling {
BO_PARAM(int, bins, 5);
};
}
namespace init {
// params:
// -init::nb_bins
template <typename Params>
struct GridSampling {
template <typename StateFunction, typename AggregatorFunction, typename Opt>
......@@ -16,12 +21,12 @@ namespace limbo {
}
private:
// recursively explore all the dim_inensions
// recursively explore all the dimensions
template <typename StateFunction, typename Opt>
void _explore(int dim_in, const StateFunction& seval, const Eigen::VectorXd& current,
Opt& opt) const
{
for (double x = 0; x <= 1.0f; x += 1.0f / (double)Params::init::nb_bins()) {
for (double x = 0; x <= 1.0f; x += 1.0f / (double)Params::init_gridsampling::bins()) {
Eigen::VectorXd point = current;
point[dim_in] = x;
if (dim_in == current.size() - 1) {
......
......@@ -3,18 +3,22 @@
#include <Eigen/Core>
#include <limbo/tools/macros.hpp>
#include <limbo/tools/rand.hpp>
namespace limbo {
namespace defaults {
struct init_randomsampling {
BO_PARAM(int, samples, 10);
};
}
namespace init {
// initialize in [0,1] !
// params: init::nb_samples
template <typename Params>
struct RandomSampling {
template <typename StateFunction, typename AggregatorFunction, typename Opt>
void operator()(const StateFunction& seval, const AggregatorFunction&, Opt& opt) const
{
for (int i = 0; i < Params::init::nb_samples(); i++) {
for (int i = 0; i < Params::init_randomsampling::samples(); i++) {
Eigen::VectorXd new_sample(StateFunction::dim_in);
for (int i = 0; i < StateFunction::dim_in; i++)
new_sample[i] = tools::rand<double>(0, 1);
......
......@@ -3,21 +3,25 @@
#include <Eigen/Core>
#include <limbo/tools/macros.hpp>
namespace limbo {
namespace defaults {
struct init_randomsamplinggrid {
BO_PARAM(int, samples, 10);
BO_PARAM(int, bins, 5);
};
}
namespace init {
// initialize in [0,1] !
// params:
// -init::nb_bins
// - init::nb_samples
template <typename Params>
struct RandomSamplingGrid {
template <typename StateFunction, typename AggregatorFunction, typename Opt>
void operator()(const StateFunction& seval, const AggregatorFunction&, Opt& opt) const
{
for (int i = 0; i < Params::init::nb_samples(); i++) {
for (int i = 0; i < Params::init_randomsamplinggrid::samples(); i++) {
Eigen::VectorXd new_sample(StateFunction::dim_in);
for (size_t i = 0; i < StateFunction::dim_in; i++)
new_sample[i] = int(((double)(Params::init::nb_bins() + 1) * rand()) / (RAND_MAX + 1.0)) / double(Params::init::nb_bins());
new_sample[i] = int(((double)(Params::init_randomsamplinggrid::bins() + 1) * rand()) / (RAND_MAX + 1.0)) / double(Params::init_randomsamplinggrid::bins());
opt.add_new_sample(new_sample, seval(new_sample));
}
}
......
......@@ -3,14 +3,21 @@
#include <Eigen/Core>
#include <limbo/tools/macros.hpp>
namespace limbo {
namespace defaults {
struct kernel_exp {
BO_PARAM(double, sigma, 1);
};
}
namespace kernel {
template <typename Params>
struct Exp {
Exp(size_t dim = 1) {}
double operator()(const Eigen::VectorXd& v1, const Eigen::VectorXd& v2) const
{
double _sigma = Params::kf_exp::sigma();
double _sigma = Params::kernel_exp::sigma();
return (exp(-(1 / (2 * pow(_sigma, 2))) * pow((v1 - v2).norm(), 2)));
}
};
......
......@@ -3,7 +3,15 @@
#include <Eigen/Core>
#include <limbo/tools/macros.hpp>
namespace limbo {
namespace defaults {
struct kernel_maternfivehalfs {
BO_PARAM(double, sigma, 1);
BO_PARAM(double, l, 1);
};
}
namespace kernel {
template <typename Params>
struct MaternFiveHalfs {
......@@ -12,7 +20,7 @@ namespace limbo {
double operator()(const Eigen::VectorXd& v1, const Eigen::VectorXd& v2) const
{
double d = (v1 - v2).norm();
return Params::kf_maternfivehalfs::sigma() * (1 + sqrt(5) * d / Params::kf_maternfivehalfs::l() + 5 * d * d / (3 * Params::kf_maternfivehalfs::l() * Params::kf_maternfivehalfs::l())) * exp(-sqrt(5) * d / Params::kf_maternfivehalfs::l());
return Params::kernel_maternfivehalfs::sigma() * (1 + sqrt(5) * d / Params::kernel_maternfivehalfs::l() + 5 * d * d / (3 * Params::kernel_maternfivehalfs::l() * Params::kernel_maternfivehalfs::l())) * exp(-sqrt(5) * d / Params::kernel_maternfivehalfs::l());
}
};
}
......
......@@ -3,7 +3,15 @@
#include <Eigen/Core>
#include <limbo/tools/macros.hpp>
namespace limbo {
namespace defaults {
struct kernel_maternthreehalfs {
BO_PARAM(double, sigma, 1);
BO_PARAM(double, l, 1);
};
}
namespace kernel {
template <typename Params>
struct MaternThreeHalfs {
......@@ -12,7 +20,7 @@ namespace limbo {
double operator()(const Eigen::VectorXd& v1, const Eigen::VectorXd& v2) const
{
double d = (v1 - v2).norm();
return Params::kf_maternthreehalfs::sigma() * (1 + sqrt(3) * d / Params::kf_maternthreehalfs::l()) * exp(-sqrt(3) * d / Params::kf_maternthreehalfs::l());
return Params::kernel_maternthreehalfs::sigma() * (1 + sqrt(3) * d / Params::kernel_maternthreehalfs::l()) * exp(-sqrt(3) * d / Params::kernel_maternthreehalfs::l());
}
};
}
......
......@@ -3,17 +3,27 @@
#include <Eigen/Core>
#include <limbo/tools/macros.hpp>
namespace limbo {
namespace defaults {
struct mean_constant {
BO_PARAM(double, constant, 1);
};
}
namespace mean {
template <typename Params>
struct Constant {
Constant(size_t dim_out = 1) {}
Constant(size_t dim_out = 1) : _dim_out(dim_out) {}
template <typename GP>
Eigen::VectorXd operator()(const Eigen::VectorXd& v, const GP&) const
{
return Params::meanconstant::constant();
return Eigen::VectorXd::Constant(_dim_out, Params::mean_constant::constant());
}
protected:
size_t _dim_out;
};
}
}
......
......@@ -13,16 +13,16 @@
#include <cmaes/cmaes_interface.h>
#include <cmaes/boundary_transformation.h>
#include <limbo/tools/macros.hpp>
#include <limbo/tools/parallel.hpp>
namespace limbo {
namespace defaults {
struct cmaes {
BO_PARAM(int, nrestarts, 1);
struct opt_cmaes {
BO_PARAM(int, restarts, 1);
BO_PARAM(double, max_fun_evals, -1);