Commit 710e01b1 authored by Konstantinos Chatzilygeroudis's avatar Konstantinos Chatzilygeroudis
Browse files

Compiling and cleaning

parent 5d78c14e
......@@ -7,56 +7,54 @@
template <typename Function>
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);
benchmark.optimize(result);
auto time_running = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout.precision(17);
std::cout << std::endl;
auto best = benchmark.evaluateSample(result);
double accuracy = benchmark.accuracy(best);
std::cout << name << std::endl;
std::cout << "Result: " << std::fixed << result << " -> " << best << std::endl;
std::cout << "Smallest difference: " << accuracy << std::endl;
std::cout << "Time running: " << time_running << "ms" << std::endl << std::endl;
std::ofstream res_file(name + ".dat",std::ios_base::out | std::ios_base::app);
res_file.precision(17);
res_file << std::fixed << accuracy << " "<< time_running << std::endl;
auto t1 = std::chrono::steady_clock::now();
Benchmark<Function> benchmark(par);
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);
std::cout << std::endl;
auto best = benchmark.evaluateSample(result);
double accuracy = benchmark.accuracy(best);
std::cout << name << std::endl;
std::cout << "Result: " << std::fixed << result << " -> " << best << std::endl;
std::cout << "Smallest difference: " << accuracy << std::endl;
std::cout << "Time running: " << time_running << "ms" << std::endl
<< std::endl;
std::ofstream res_file(name + ".dat", std::ios_base::out | std::ios_base::app);
res_file.precision(17);
res_file << std::fixed << accuracy << " " << time_running << std::endl;
}
int main(int nargs, char *args[])
int main(int nargs, char* args[])
{
srand(time(NULL));
bopt_params par = initialize_parameters_to_default();
par.n_iterations = 190;
par.n_inner_iterations = 250;
par.n_iter_relearn = 1;
//par.random_seed = 0;
par.verbose_level = 0;
par.noise = 1e-10;
par.sigma_s = 1;
par.sc_type = SC_ML;
par.init_method = 3;
strcpy(par.crit_name,"cLCB");
par.crit_params[0] = 0.125;
par.n_crit_params = 1;
par.force_jump = 0;
strcpy(par.kernel.name,"kSEARD");
benchmark<BraninNormalized>(par, "branin");
benchmark<Hartman6>(par, "hartman6");
benchmark<Hartman3>(par, "hartman3");
benchmark<Rastrigin>(par, "rastrigin");
benchmark<Sphere>(par, "sphere");
benchmark<Ellipsoid>(par, "ellipsoid");
benchmark<GoldenPrice>(par, "goldenprice");
benchmark<SixHumpCamel>(par, "sixhumpcamel");
srand(time(NULL));
bopt_params par = initialize_parameters_to_default();
par.n_iterations = 190;
par.n_inner_iterations = 250;
par.n_iter_relearn = 1;
//par.random_seed = 0;
par.verbose_level = 0;
par.noise = 1e-10;
par.sigma_s = 1;
par.sc_type = SC_ML;
par.init_method = 3;
strcpy(par.crit_name, "cLCB");
par.crit_params[0] = 0.125;
par.n_crit_params = 1;
par.force_jump = 0;
strcpy(par.kernel.name, "kSEARD");
benchmark<BraninNormalized>(par, "branin");
benchmark<Hartman6>(par, "hartman6");
benchmark<Hartman3>(par, "hartman3");
benchmark<Rastrigin>(par, "rastrigin");
benchmark<Sphere>(par, "sphere");
benchmark<Ellipsoid>(par, "ellipsoid");
benchmark<GoldenPrice>(par, "goldenprice");
benchmark<SixHumpCamel>(par, "sixhumpcamel");
return 0;
}
......@@ -7,54 +7,54 @@
template <typename Function>
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);
benchmark.optimize(result);
auto time_running = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout.precision(17);
std::cout << std::endl;
auto best = benchmark.evaluateSample(result);
double accuracy = benchmark.accuracy(best);
auto t1 = std::chrono::steady_clock::now();
Benchmark<Function> benchmark(par);
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);
std::cout << std::endl;
auto best = benchmark.evaluateSample(result);
double accuracy = benchmark.accuracy(best);
std::cout << name << std::endl;
std::cout << "Result: " << std::fixed << result << " -> " << best << std::endl;
std::cout << "Smallest difference: " << accuracy << std::endl;
std::cout << "Time running: " << time_running << "ms" << std::endl << std::endl;
std::cout << name << std::endl;
std::cout << "Result: " << std::fixed << result << " -> " << best << std::endl;
std::cout << "Smallest difference: " << accuracy << std::endl;
std::cout << "Time running: " << time_running << "ms" << std::endl
<< std::endl;
std::ofstream res_file(name + ".dat",std::ios_base::out | std::ios_base::app);
res_file.precision(17);
res_file << std::fixed << accuracy << " "<< time_running << std::endl;
std::ofstream res_file(name + ".dat", std::ios_base::out | std::ios_base::app);
res_file.precision(17);
res_file << std::fixed << accuracy << " " << time_running << std::endl;
}
int main(int nargs, char *args[])
int main(int nargs, char* args[])
{
srand(time(NULL));
bopt_params par = initialize_parameters_to_default();
par.n_iterations = 190;
par.n_inner_iterations = 250;
par.n_iter_relearn = 0;
//par.random_seed = 0;
par.verbose_level = 0;
par.noise = 1e-10;
par.sigma_s = 1;
par.sc_type = SC_ML;
par.init_method = 3;
strcpy(par.crit_name,"cLCB");
par.crit_params[0] = 0.125;
par.n_crit_params = 1;
par.force_jump = 0;
strcpy(par.kernel.name,"kMaternISO5");
srand(time(NULL));
bopt_params par = initialize_parameters_to_default();
par.n_iterations = 190;
par.n_inner_iterations = 250;
par.n_iter_relearn = 0;
//par.random_seed = 0;
par.verbose_level = 0;
par.noise = 1e-10;
par.sigma_s = 1;
par.sc_type = SC_ML;
par.init_method = 3;
strcpy(par.crit_name, "cLCB");
par.crit_params[0] = 0.125;
par.n_crit_params = 1;
par.force_jump = 0;
strcpy(par.kernel.name, "kMaternISO5");
benchmark<BraninNormalized>(par, "branin");
benchmark<Hartman6>(par, "hartman6");
benchmark<Hartman3>(par, "hartman3");
benchmark<Rastrigin>(par, "rastrigin");
benchmark<Sphere>(par, "sphere");
benchmark<Ellipsoid>(par, "ellipsoid");
benchmark<GoldenPrice>(par, "goldenprice");
benchmark<SixHumpCamel>(par, "sixhumpcamel");
benchmark<BraninNormalized>(par, "branin");
benchmark<Hartman6>(par, "hartman6");
benchmark<Hartman3>(par, "hartman3");
benchmark<Rastrigin>(par, "rastrigin");
benchmark<Sphere>(par, "sphere");
benchmark<Ellipsoid>(par, "ellipsoid");
benchmark<GoldenPrice>(par, "goldenprice");
benchmark<SixHumpCamel>(par, "sixhumpcamel");
return 0;
}
/*
-------------------------------------------------------------------------
This file is part of BayesOpt, an efficient C++ library for
This file is part of BayesOpt, an efficient C++ library for
Bayesian optimization.
Copyright (C) 2011-2013 Ruben Martinez-Cantin <rmcantin@unizar.es>
BayesOpt is free software: you can redistribute it and/or modify it
BayesOpt is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
BayesOpt is distributed in the hope that it will be useful, but
BayesOpt is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
......@@ -39,7 +39,7 @@ inline double sign(double x)
return 0;
}
inline double sqr(double x)
inline double sqr(double x)
{
return x * x;
};
......@@ -87,9 +87,9 @@ struct Sphere {
matrixd solutions() const
{
matrixd sols(1, 2);
sols <<= 0.5, 0.5;
return sols;
matrixd sols(1, 2);
sols <<= 0.5, 0.5;
return sols;
}
};
......@@ -110,9 +110,9 @@ struct Ellipsoid {
matrixd solutions() const
{
matrixd sols(1, 2);
sols <<= 0.5, 0.5;
return sols;
matrixd sols(1, 2);
sols <<= 0.5, 0.5;
return sols;
}
};
......@@ -130,10 +130,10 @@ struct Rastrigin {
matrixd solutions() const
{
matrixd sols(1, dim_in);
for (size_t i = 0; i < dim_in; ++i)
sols(0, i) = 0;
return sols;
matrixd sols(1, dim_in);
for (size_t i = 0; i < dim_in; ++i)
sols(0, i) = 0;
return sols;
}
};
......@@ -165,9 +165,9 @@ struct Hartman3 {
matrixd solutions() const
{
matrixd sols(1, 3);
sols <<= 0.114614, 0.555649, 0.852547;
return sols;
matrixd sols(1, 3);
sols <<= 0.114614, 0.555649, 0.852547;
return sols;
}
};
......@@ -202,9 +202,9 @@ struct Hartman6 {
matrixd solutions() const
{
matrixd sols(1, 6);
sols <<= 0.20169, 0.150011, 0.476874, 0.275332, 0.311652, 0.6573;
return sols;
matrixd sols(1, 6);
sols <<= 0.20169, 0.150011, 0.476874, 0.275332, 0.311652, 0.6573;
return sols;
}
};
......@@ -226,9 +226,9 @@ struct GoldenPrice {
matrixd solutions() const
{
matrixd sols(1, 2);
sols <<= 0.5, 0.25;
return sols;
matrixd sols(1, 2);
sols <<= 0.5, 0.25;
return sols;
}
};
......@@ -245,67 +245,66 @@ struct BraninNormalized {
matrixd solutions() const
{
matrixd sols(3, 2);
sols <<= 0.1238938, 0.818333,
0.5427728, 0.151667,
0.961652, 0.1650;
return sols;
matrixd sols(3, 2);
sols <<= 0.1238938, 0.818333,
0.5427728, 0.151667,
0.961652, 0.1650;
return sols;
}
};
struct SixHumpCamel {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
double operator()(const vectord& x) const
{
double x1_2 = x(0)*x(0);
double x2_2 = x(1)*x(1);
double tmp1 = (4 - 2.1 * x1_2 + (x1_2*x1_2)/3) * x1_2;
double tmp2 = x(0)*x(1);
double tmp3 = (-4 + 4 * x2_2) * x2_2;
return tmp1 + tmp2 + tmp3;
}
matrixd solutions() const
{
matrixd sols(2, 2);
sols <<= 0.0898, -0.7126,
-0.0898, 0.7126;
return sols;
}
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
double operator()(const vectord& x) const
{
double x1_2 = x(0) * x(0);
double x2_2 = x(1) * x(1);
double tmp1 = (4 - 2.1 * x1_2 + (x1_2 * x1_2) / 3) * x1_2;
double tmp2 = x(0) * x(1);
double tmp3 = (-4 + 4 * x2_2) * x2_2;
return tmp1 + tmp2 + tmp3;
}
matrixd solutions() const
{
matrixd sols(2, 2);
sols <<= 0.0898, -0.7126,
-0.0898, 0.7126;
return sols;
}
};
template <typename Function>
class Benchmark : public bayesopt::ContinuousModel
{
class Benchmark : public bayesopt::ContinuousModel {
public:
Benchmark(bopt_params par):
ContinuousModel(Function::dim_in, par) {}
double evaluateSample(const vectord& xin)
{
return f(xin);
}
bool checkReachability(const vectord &query)
{return true;};
double accuracy(double x)
{
matrixd sols = f.solutions();
double diff = std::abs(x - f(row(sols, 0)));
double min_diff = diff;
for (size_t i = 1; i < sols.size1(); i++) {
diff = std::abs(x - f(row(sols, i)));
if (diff < min_diff)
min_diff = diff;
Benchmark(bopt_params par) : ContinuousModel(Function::dim_in, par) {}
double evaluateSample(const vectord& xin)
{
return f(xin);
}
return min_diff;
}
bool checkReachability(const vectord& query)
{
return true;
};
Function f;
double accuracy(double x)
{
matrixd sols = f.solutions();
double diff = std::abs(x - f(row(sols, 0)));
double min_diff = diff;
for (size_t i = 1; i < sols.size1(); i++) {
diff = std::abs(x - f(row(sols, i)));
if (diff < min_diff)
min_diff = diff;
}
return min_diff;
}
Function f;
};
......@@ -8,52 +8,51 @@
using namespace limbo;
struct Params {
struct bayes_opt_bobase {
BO_PARAM(bool, stats_enabled, false);
};
struct bayes_opt_boptimizer {
BO_PARAM(double, noise, 1e-10);
BO_PARAM(int, dump_period, -1);
BO_PARAM(int, hp_period, 1);
};
struct stop_maxiterations {
BO_PARAM(int, iterations, 190);
};
struct kernel_maternfivehalfs {
BO_PARAM(double, sigma, 1);
BO_PARAM(double, l, 1);
};
struct acqui_ucb {
BO_PARAM(double, alpha, 0.125);
};
struct init_randomsampling {
BO_PARAM(int, samples, 10);
};
struct SquaredExpARD : public defaults::SquaredExpARD {
};
struct mean_constant {
BO_PARAM(double, constant, 1);
};
struct opt_rprop : public defaults::opt_rprop {
};
struct bayes_opt_bobase {
BO_PARAM(bool, stats_enabled, false);
};
struct bayes_opt_boptimizer {
BO_PARAM(double, noise, 1e-10);
BO_PARAM(int, dump_period, -1);
BO_PARAM(int, hp_period, 1);
};
struct stop_maxiterations {
BO_PARAM(int, iterations, 190);
};
struct kernel_maternfivehalfs {
BO_PARAM(double, sigma, 1);
BO_PARAM(double, l, 1);
};
struct acqui_ucb {
BO_PARAM(double, alpha, 0.125);
};
struct init_randomsampling {
BO_PARAM(int, samples, 10);
};
struct kernel_squared_exp_ard : public defaults::kernel_squared_exp_ard {
};
struct mean_constant {
BO_PARAM(double, constant, 1);
};
struct opt_rprop : public defaults::opt_rprop {
};
};
struct DirectParams {
struct opt_nloptnograd {
BO_DYN_PARAM(int, iterations);
};
struct opt_nloptnograd {
BO_DYN_PARAM(int, iterations);
};
};
struct BobyqaParams {
struct opt_nloptnograd {
BO_DYN_PARAM(int, iterations);
};
struct opt_nloptnograd {
BO_DYN_PARAM(int, iterations);
};
};
struct BobyqaParams_HP {
struct opt_nloptnograd {
BO_DYN_PARAM(int, iterations);
};
struct opt_nloptnograd {
BO_DYN_PARAM(int, iterations);
};
};
BO_DECLARE_DYN_PARAM(int, DirectParams::opt_nloptnograd, iterations);
......@@ -85,14 +84,14 @@ void benchmark(const std::string& name)
std::cout << "Time running: " << time_running << "ms" << std::endl
<< std::endl;
std::ofstream res_file(name + ".dat",std::ios_base::out | std::ios_base::app);
std::ofstream res_file(name + ".dat", std::ios_base::out | std::ios_base::app);
res_file.precision(17);
res_file << std::fixed << accuracy << " " << time_running << std::endl;
}
int main()
{
srand(time(NULL));
srand(time(NULL));
typedef kernel::SquaredExpARD<Params> Kernel_t;
typedef opt::Chained<Params, opt::NLOptNoGrad<DirectParams, nlopt::GN_DIRECT_L>, opt::NLOptNoGrad<BobyqaParams, nlopt::LN_BOBYQA>> AcquiOpt_t;
......@@ -101,7 +100,7 @@ int main()
typedef mean::Constant<Params> Mean_t;
typedef boost::fusion::vector<> Stat_t;
typedef init::RandomSampling<Params> Init_t;
typedef model::GP<Params, Kernel_t, Mean_t,model::gp::KernelLFOpt<Params,opt::NLOptNoGrad<BobyqaParams_HP, nlopt::LN_BOBYQA> > > GP_t;
typedef model::GP<Params, Kernel_t, Mean_t, model::gp::KernelLFOpt<Params, opt::NLOptNoGrad<BobyqaParams_HP, nlopt::LN_BOBYQA>>> GP_t;
typedef acqui::UCB<Params, GP_t> Acqui_t;
typedef bayes_opt::BOptimizer<Params, modelfun<GP_t>, initfun<Init_t>, acquifun<Acqui_t>, acquiopt<AcquiOpt_t>, statsfun<Stat_t>, stopcrit<Stop_t>> Opt_t;
......
......@@ -8,42 +8,42 @@
using namespace limbo;
struct Params {
struct bayes_opt_bobase {
BO_PARAM(bool, stats_enabled, false);
};
struct bayes_opt_boptimizer {
BO_PARAM(double, noise, 1e-10);
BO_PARAM(int, dump_period, -1);
BO_PARAM(int, hp_period, -1);
};
struct stop_maxiterations {
BO_PARAM(int, iterations, 190);
};
struct kernel_maternfivehalfs {
BO_PARAM(double, sigma, 1);
BO_PARAM(double, l, 1);
};
struct acqui_ucb {
BO_PARAM(double, alpha, 0.125);
};
struct init_randomsampling {
BO_PARAM(int, samples, 10);
};
struct mean_constant {
BO_PARAM(double, constant, 1);
};
struct bayes_opt_bobase {
BO_PARAM(bool, stats_enabled, false);
};
struct bayes_opt_boptimizer {
BO_PARAM(double, noise, 1e-10);
BO_PARAM(int, dump_period, -1);
BO_PARAM(int, hp_period, -1);
};
struct stop_maxiterations {
BO_PARAM(int, iterations, 190);
};
struct kernel_maternfivehalfs {
BO_PARAM(double, sigma, 1);
BO_PARAM(double, l, 1);
};
struct acqui_ucb {
BO_PARAM(double, alpha, 0.125);
};
struct init_randomsampling {
BO_PARAM(int, samples, 10);
};
struct mean_constant {
BO_PARAM(double, constant, 1);
};
};
struct DirectParams {