Commit bd92a748 authored by Konstantinos Chatzilygeroudis's avatar Konstantinos Chatzilygeroudis
Browse files

Merge remote-tracking branch 'origin/gp_multi' into libcmaes

Conflicts:
	src/limbo/opt/cmaes.hpp
parents af4a9c65 1defabaa
......@@ -2287,7 +2287,7 @@ long random_init(random_t* t, long unsigned inseed)
if (inseed < 1) {
while ((long)(cloc - clock()) == 0)
; /* TODO: remove this for time critical applications? */
inseed = (long unsigned)abs((long)(100 * time(NULL) + clock()));
inseed = (long unsigned)labs((long)(100 * time(NULL) + clock()));
}
return random_Start(t, inseed);
}
......@@ -2670,7 +2670,7 @@ void readpara_SupplementDefaults(readpara_t* t)
if (t->seed < 1) {
while ((int)(cloc - clock()) == 0)
; /* TODO: remove this for time critical applications!? */
t->seed = (unsigned int)abs((long)(100 * time(NULL) + clock()));
t->seed = (unsigned int)labs((long)(100 * time(NULL) + clock()));
}
if (t->stStopFitness.flg == -1)
......
......@@ -88,7 +88,7 @@ double ehvi3d_2term(deque<individual*> P, double r[], double mu[],
double Sminus; // Correction term for the integral.
deque<individual*> Py, Pz; // P sorted by y/z coordinate
sort(P.begin(), P.end(), ycomparator);
for (int i = 0; i < P.size(); i++) {
for (size_t i = 0; i < P.size(); i++) {
Py.push_back(P[i]);
}
sort(P.begin(), P.end(), zcomparator);
......@@ -145,7 +145,7 @@ double ehvi3d_5term(deque<individual*> P, double r[], double mu[],
double Sminus; // Correction term for the integral.
deque<individual*> Py, Pz; // P sorted by y/z coordinate
sort(P.begin(), P.end(), ycomparator);
for (int i = 0; i < P.size(); i++) {
for (size_t i = 0; i < P.size(); i++) {
Py.push_back(P[i]);
}
sort(P.begin(), P.end(), zcomparator);
......@@ -231,7 +231,7 @@ double ehvi3d_8term(deque<individual*> P, double r[], double mu[],
tempimp; // Correction term, rectangular volume, temp. improvement
deque<individual*> Py, Pz; // P sorted by y/z coordinate
sort(P.begin(), P.end(), ycomparator);
for (int i = 0; i < P.size(); i++) {
for (size_t i = 0; i < P.size(); i++) {
Py.push_back(P[i]);
}
sort(P.begin(), P.end(), zcomparator);
......
......@@ -20,15 +20,15 @@ vector<double> ehvi3d_5term(deque<individual*> P, double r[],
double Sminus; // Correction term for the integral.
deque<individual*> Py, Pz; // P sorted by y/z coordinate
sort(P.begin(), P.end(), ycomparator);
for (int i = 0; i < P.size(); i++) {
for (size_t i = 0; i < P.size(); i++) {
Py.push_back(P[i]);
}
sort(P.begin(), P.end(), zcomparator);
for (unsigned int i = 0; i < P.size(); i++) {
for (size_t i = 0; i < P.size(); i++) {
Pz.push_back(P[i]);
}
sort(P.begin(), P.end(), xcomparator);
for (int i = 0; i < pdf.size(); i++) {
for (size_t i = 0; i < pdf.size(); i++) {
answer.push_back(0);
}
for (int z = 0; z <= n; z++) {
......@@ -72,7 +72,7 @@ vector<double> ehvi3d_5term(deque<individual*> P, double r[],
double yslice = calculateslice(Py, v, cl, 1);
double zslice = calculateslice(Pz, v, cl, 2);
// And then we integrate.
for (int i = 0; i < pdf.size(); i++) {
for (size_t i = 0; i < pdf.size(); i++) {
double psi1 = exipsi(v[0], cl[0], pdf[i]->mu[0], pdf[i]->s[0]) - exipsi(v[0], cu[0], pdf[i]->mu[0], pdf[i]->s[0]);
double psi2 = exipsi(v[1], cl[1], pdf[i]->mu[1], pdf[i]->s[1]) - exipsi(v[1], cu[1], pdf[i]->mu[1], pdf[i]->s[1]);
double psi3 = exipsi(v[2], cl[2], pdf[i]->mu[2], pdf[i]->s[2]) - exipsi(v[2], cu[2], pdf[i]->mu[2], pdf[i]->s[2]);
......@@ -116,7 +116,7 @@ vector<double> ehvi3d_sliceupdate(deque<individual*> P, double r[DIMENSIONS],
// location in
// the other sorting orders to be ascertained in O(1).
sort(P.begin(), P.end(), xcomparator);
for (unsigned int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
newind = new specialind;
newind->point = P[i];
newind->xorder = i;
......@@ -125,11 +125,11 @@ vector<double> ehvi3d_sliceupdate(deque<individual*> P, double r[DIMENSIONS],
Pz.push_back(newind);
}
sort(Py.begin(), Py.end(), specialycomparator);
for (unsigned int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
Py[i]->yorder = i;
}
sort(Pz.begin(), Pz.end(), specialzcomparator);
for (unsigned int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
Pz[i]->zorder = i;
}
// Then also reserve memory for the structure array.
......@@ -244,7 +244,7 @@ vector<double> ehvi3d_sliceupdate(deque<individual*> P, double r[DIMENSIONS],
v[2] = (Pstruct[x + y * n].highestdominator == -1
? 0
: (Pz[Pstruct[x + y * n].highestdominator]->point->f[2] - r[2]));
for (int i = 0; i < pdf.size(); i++) {
for (size_t i = 0; i < pdf.size(); i++) {
double psi1 = exipsi(r[0], cl[0], pdf[i]->mu[0], pdf[i]->s[0]) - exipsi(r[0], cu[0], pdf[i]->mu[0], pdf[i]->s[0]);
double psi2 = exipsi(r[1], cl[1], pdf[i]->mu[1], pdf[i]->s[1]) - exipsi(r[1], cu[1], pdf[i]->mu[1], pdf[i]->s[1]);
double psi3 = exipsi(r[2], cl[2], pdf[i]->mu[2], pdf[i]->s[2]) - exipsi(r[2], cu[2], pdf[i]->mu[2], pdf[i]->s[2]);
......
......@@ -27,7 +27,7 @@ double ehvi3d_sliceupdate(deque<individual*> P, double r[], double mu[],
// location in
// the other sorting orders to be ascertained in O(1).
sort(P.begin(), P.end(), xcomparator);
for (unsigned int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
newind = new specialind;
newind->point = P[i];
newind->xorder = i;
......@@ -36,11 +36,11 @@ double ehvi3d_sliceupdate(deque<individual*> P, double r[], double mu[],
Pz.push_back(newind);
}
sort(Py.begin(), Py.end(), specialycomparator);
for (unsigned int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
Py[i]->yorder = i;
}
sort(Pz.begin(), Pz.end(), specialzcomparator);
for (unsigned int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
Pz[i]->zorder = i;
}
// Then also reserve memory for the structure array.
......
......@@ -20,6 +20,7 @@
#include <limbo/stop/max_iterations.hpp>
#include <limbo/stat/samples.hpp>
#include <limbo/stat/aggregated_observations.hpp>
#include <limbo/stat/console_summary.hpp>
#include <limbo/tools/sys.hpp>
#include <limbo/kernel/squared_exp_ard.hpp>
#include <limbo/acqui/gp_ucb.hpp>
......@@ -108,7 +109,7 @@ namespace limbo {
// WARNING: you have to specify the acquisition function
// if you use a custom model
typedef acqui::GP_UCB<Params, model_t> acqui_t; // 4
typedef boost::fusion::vector<stat::Samples<Params>, stat::AggregatedObservations<Params>> stat_t; // 5
typedef boost::fusion::vector<stat::Samples<Params>, stat::AggregatedObservations<Params>, stat::ConsoleSummary<Params>> stat_t; // 5
typedef boost::fusion::vector<stop::MaxIterations<Params>> stop_t; // 6
};
......
......@@ -6,7 +6,6 @@
#include <iterator>
#include <boost/parameter/aux_/void.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <Eigen/Core>
......@@ -86,23 +85,6 @@ namespace limbo {
this->_update_stats(*this, afun, blacklisted);
std::cout << this->_current_iteration << " new point: "
<< (blacklisted ? this->_bl_samples.back()
: this->_samples.back()).transpose();
if (blacklisted)
std::cout << " value: " << "No data, blacklisted";
else
std::cout << " value: " << afun(this->_observations.back());
// std::cout << " mu: "<< _model.mu(blacklisted ? this->_bl_samples.back()
// : this->_samples.back()).transpose()
//<< " mean: " << _model.mean_function()(new_sample, _model).transpose()
//<< " sigma: "<< _model.sigma(blacklisted ? this->_bl_samples.back() :
//this->_samples.back())
//<< " acqui: "<< acqui(blacklisted ? this->_bl_samples.back() :
//this->_samples.back(), afun)
std::cout << " best:" << afun(this->best_observation(afun)) << std::endl;
if (!this->_observations.empty())
_model.compute(this->_samples, this->_observations, Params::bayes_opt_boptimizer::noise(), this->_bl_samples);
......@@ -114,7 +96,8 @@ namespace limbo {
template <typename AggregatorFunction = FirstElem>
const Eigen::VectorXd& best_observation(const AggregatorFunction& afun = AggregatorFunction()) const
{
auto rewards = boost::adaptors::transform(this->_observations, afun);
auto rewards = std::vector<double>(this->_observations.size());
std::transform(this->_observations.begin(), this->_observations.end(), rewards.begin(), afun);
auto max_e = std::max_element(rewards.begin(), rewards.end());
return this->_observations[std::distance(rewards.begin(), max_e)];
}
......@@ -122,7 +105,8 @@ namespace limbo {
template <typename AggregatorFunction = FirstElem>
const Eigen::VectorXd& best_sample(const AggregatorFunction& afun = AggregatorFunction()) const
{
auto rewards = boost::adaptors::transform(this->_observations, afun);
auto rewards = std::vector<double>(this->_observations.size());
std::transform(this->_observations.begin(), this->_observations.end(), rewards.begin(), afun);
auto max_e = std::max_element(rewards.begin(), rewards.end());
return this->_samples[std::distance(rewards.begin(), max_e)];
}
......
......@@ -4,7 +4,7 @@
#include <Eigen/Core>
#include <limbo/tools/macros.hpp>
#include <limbo/tools/rand.hpp>
#include <limbo/tools/math.hpp>
namespace limbo {
namespace defaults {
......@@ -20,8 +20,8 @@ namespace limbo {
{
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);
for (size_t j = 0; j < StateFunction::dim_in; j++)
new_sample[j] = tools::rand<double>(0, 1);
opt.add_new_sample(new_sample, seval(new_sample));
}
}
......
......@@ -180,8 +180,8 @@ namespace limbo {
{
// O(n^2) [should be negligible]
_kernel.resize(_samples.size(), _samples.size());
for (int i = 0; i < _samples.size(); i++)
for (int j = 0; j < _samples.size(); ++j)
for (size_t i = 0; i < _samples.size(); i++)
for (size_t j = 0; j < _samples.size(); ++j)
_kernel(i, j) = _kernel_function(_samples[i], _samples[j]) + ((i == j) ? _noise : 0); // noise only on the diagonal
// O(n^3)
......
......@@ -27,7 +27,7 @@ namespace limbo {
protected:
template <typename F>
Eigen::VectorXd _inner_search(const F& f, int depth, const Eigen::VectorXd& current) const
Eigen::VectorXd _inner_search(const F& f, size_t depth, const Eigen::VectorXd& current) const
{
double step_size = 1.0 / (double)Params::opt_gridsearch::bins();
double upper_lim = 1.0 + step_size;
......
......@@ -3,8 +3,6 @@
#include <algorithm>
#include <boost/math/special_functions/sign.hpp>
#include <Eigen/Core>
#include <limbo/tools/macros.hpp>
......
......@@ -8,6 +8,7 @@
#include <Eigen/Core>
#include <limbo/tools/macros.hpp>
#include <limbo/tools/math.hpp>
namespace limbo {
namespace defaults {
......@@ -70,7 +71,7 @@ namespace limbo {
delta(j) = std::max(delta(j) * etaminus, deltamin);
grad(j) = 0;
}
params(j) += -boost::math::sign(grad(j)) * delta(j);
params(j) += -tools::signum(grad(j)) * delta(j);
if (bounded && params(j) < 0)
params(j) = 0;
......
......@@ -5,6 +5,7 @@
#include <limbo/stat/best_observations.hpp>
#include <limbo/stat/best_samples.hpp>
#include <limbo/stat/bl_samples.hpp>
#include <limbo/stat/console_summary.hpp>
#include <limbo/stat/aggregated_observations.hpp>
#include <limbo/stat/observations.hpp>
#include <limbo/stat/gp_acquisitions.hpp>
......
#ifndef LIMBO_STAT_CONSOLE_SUMMARY_HPP
#define LIMBO_STAT_CONSOLE_SUMMARY_HPP
#include <limbo/stat/stat_base.hpp>
namespace limbo {
namespace stat {
template <typename Params>
struct ConsoleSummary : public StatBase<Params> {
template <typename BO, typename AggregatorFunction>
void operator()(const BO& bo, const AggregatorFunction& afun, bool blacklisted)
{
if (!bo.stats_enabled() || bo.observations().empty())
return;
std::cout << bo.total_iterations() << " new point: "
<< (blacklisted ? bo.bl_samples().back()
: bo.samples().back()).transpose();
if (blacklisted)
std::cout << " value: "
<< "No data, blacklisted";
else
std::cout << " value: " << afun(bo.observations().back());
std::cout << " best:" << afun(bo.best_observation(afun)) << std::endl;
}
};
}
}
#endif
......@@ -4,7 +4,7 @@
#include <fstream>
#include <string>
#include <boost/shared_ptr.hpp>
#include <memory>
namespace limbo {
namespace stat {
......@@ -19,14 +19,14 @@ namespace limbo {
}
protected:
boost::shared_ptr<std::ofstream> _log_file;
std::shared_ptr<std::ofstream> _log_file;
template <typename BO>
void _create_log_file(const BO& bo, const std::string& name)
{
if (!_log_file && bo.stats_enabled()) {
std::string log = bo.res_dir() + "/" + name;
_log_file = boost::shared_ptr<std::ofstream>(new std::ofstream(log.c_str()));
_log_file = std::make_shared<std::ofstream>(log.c_str());
}
}
};
......
......@@ -3,7 +3,7 @@
#include <limbo/tools/macros.hpp>
#include <limbo/tools/parallel.hpp>
#include <limbo/tools/rand.hpp>
#include <limbo/tools/math.hpp>
#include <limbo/tools/sys.hpp>
#endif
......@@ -34,8 +34,8 @@
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef LIMBO_TOOLS_RAND_HPP
#define LIMBO_TOOLS_RAND_HPP
#ifndef LIMBO_TOOLS_MATH_HPP
#define LIMBO_TOOLS_MATH_HPP
#include <cstdlib>
#include <cmath>
......@@ -43,8 +43,7 @@
#include <list>
#include <stdlib.h>
#include <random>
#include <boost/swap.hpp>
#include <utility>
// someday we will have a real thread-safe random number generator...
namespace limbo {
......@@ -87,7 +86,7 @@ namespace limbo {
for (size_t i = 0; i < a1.size(); ++i) {
size_t k = rand(i, a1.size());
assert(k < a1.size());
boost::swap(a1[i], a1[k]);
std::swap(a1[i], a1[k]);
}
}
......@@ -113,6 +112,25 @@ namespace limbo {
++it;
return it;
}
// get sign of number
template <typename T>
inline constexpr int signum(T x, std::false_type is_signed)
{
return T(0) < x;
}
template <typename T>
inline constexpr int signum(T x, std::true_type is_signed)
{
return (T(0) < x) - (x < T(0));
}
template <typename T>
inline constexpr int signum(T x)
{
return signum(x, std::is_signed<T>());
}
}
}
......
......@@ -39,8 +39,6 @@
#include <unistd.h>
#include <string>
#include <boost/lexical_cast.hpp>
namespace limbo {
namespace tools {
inline std::string date()
......@@ -49,7 +47,7 @@ namespace limbo {
time_t date_time;
time(&date_time);
strftime(date, 30, "%Y-%m-%d_%H_%M_%S", localtime(&date_time));
return date;
return std::string(date);
}
inline std::string hostname()
......@@ -63,7 +61,7 @@ namespace limbo {
inline std::string getpid()
{
return boost::lexical_cast<std::string>(::getpid());
return std::to_string(::getpid());
}
}
}
......
......@@ -53,15 +53,15 @@ BOOST_AUTO_TEST_CASE(test_gp)
Eigen::VectorXd mu;
double sigma;
std::tie(mu, sigma) = gp.query(make_v1(1));
BOOST_CHECK(abs((mu(0) - 5)) < 1);
BOOST_CHECK(std::abs((mu(0) - 5)) < 1);
BOOST_CHECK(sigma < 1e-5);
std::tie(mu, sigma) = gp.query(make_v1(2));
BOOST_CHECK(abs((mu(0) - 10)) < 1);
BOOST_CHECK(std::abs((mu(0) - 10)) < 1);
BOOST_CHECK(sigma < 1e-5);
std::tie(mu, sigma) = gp.query(make_v1(3));
BOOST_CHECK(abs((mu(0) - 5)) < 1);
BOOST_CHECK(std::abs((mu(0) - 5)) < 1);
BOOST_CHECK(sigma < 1e-5);
for (double x = 0; x < 4; x += 0.05) {
......@@ -123,14 +123,14 @@ BOOST_AUTO_TEST_CASE(test_gp_auto)
Eigen::VectorXd mu;
double sigma;
std::tie(mu, sigma) = gp.query(make_v1(1));
BOOST_CHECK(abs((mu(0) - 5)) < 1);
BOOST_CHECK(std::abs((mu(0) - 5)) < 1);
BOOST_CHECK(sigma < 1e-5);
std::tie(mu, sigma) = gp.query(make_v1(2));
BOOST_CHECK(abs((mu(0) - 10)) < 1);
BOOST_CHECK(std::abs((mu(0) - 10)) < 1);
BOOST_CHECK(sigma < 1e-5);
std::tie(mu, sigma) = gp.query(make_v1(3));
BOOST_CHECK(abs((mu(0) - 5)) < 1);
BOOST_CHECK(std::abs((mu(0) - 5)) < 1);
BOOST_CHECK(sigma < 1e-5);
}
......@@ -28,7 +28,6 @@ BOOST_AUTO_TEST_CASE(test_macros)
Params::test::set_b(3);
BOOST_CHECK(Params::test::b() == 3);
BOOST_CHECK(__VA_NARG__() == 0);
BOOST_CHECK(__VA_NARG__(1) == 1);
BOOST_CHECK(__VA_NARG__(10, 11, 12, 13) == 4);
......
......@@ -72,7 +72,7 @@ public:
protected:
const Functor& _f;
const Eigen::VectorXd& _init;
Eigen::VectorXd _init;
};
template <typename Functor>
......
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