Commit 61d51f94 authored by Federico Allocati's avatar Federico Allocati
Browse files

Added the Stats "Best". Changed bo.best_observation to return the observation unaggregated

parent 7d74e698
......@@ -107,10 +107,11 @@ namespace limbo {
}
template <typename AggregatorFunction = FirstElem>
typename AggregatorFunction::result_type best_observation(const AggregatorFunction& afun = AggregatorFunction()) const
const Eigen::VectorXd& best_observation(const AggregatorFunction& afun = AggregatorFunction()) const
{
auto rewards = boost::adaptors::transform(this->_observations, afun);
return *std::max_element(rewards.begin(), rewards.end());
auto max_e = std::max_element(rewards.begin(), rewards.end());
return this->_observations[std::distance(rewards.begin(), max_e)];
}
template <typename AggregatorFunction = FirstElem>
......
#ifndef LIMBO_STAT_HPP
#define LIMBO_STAT_HPP
#include <limbo/stat/best_aggregated_observations.hpp>
#include <limbo/stat/best_observations.hpp>
#include <limbo/stat/best_samples.hpp>
#include <limbo/stat/aggregated_observations.hpp>
#include <limbo/stat/observations.hpp>
#include <limbo/stat/samples.hpp>
#endif
#ifndef LIMBO_STAT_BEST_AGGREGATED_OBSERVATIONS_HPP
#define LIMBO_STAT_BEST_AGGREGATED_OBSERVATIONS_HPP
#include <limbo/stat/stat_base.hpp>
namespace limbo {
namespace stat {
template <typename Params>
struct BestAggregatedObservations : 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;
this->_create_log_file(bo, "best_aggregated_observations.dat");
if (bo.total_iterations() == 0)
std::cout << "#iteration best_aggregated_observation" << std::endl;
if (!blacklisted)
(*this->_log_file) << bo.total_iterations() << " " << afun(bo.best_observation(afun)) << std::endl;
}
};
}
}
#endif
#ifndef LIMBO_STAT_BEST_OBSERVATIONS_HPP
#define LIMBO_STAT_BEST_OBSERVATIONS_HPP
#include <limbo/stat/stat_base.hpp>
namespace limbo {
namespace stat {
template <typename Params>
struct BestObservations : 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;
this->_create_log_file(bo, "best_observations.dat");
if (bo.total_iterations() == 0)
std::cout << "#iteration best_observation" << std::endl;
if (!blacklisted)
(*this->_log_file) << bo.total_iterations() << " " << bo.best_observation(afun).transpose() << std::endl;
}
};
}
}
#endif
#ifndef LIMBO_STAT_BEST_SAMPLES_HPP
#define LIMBO_STAT_BEST_SAMPLES_HPP
#include <limbo/stat/stat_base.hpp>
namespace limbo {
namespace stat {
template <typename Params>
struct BestSamples : public StatBase<Params> {
template <typename BO, typename AggregatorFunction>
void operator()(const BO& bo, const AggregatorFunction& afun, bool blacklisted)
{
if (!bo.stats_enabled() || bo.samples().empty())
return;
this->_create_log_file(bo, "best_samples.dat");
if (bo.total_iterations() == 0)
std::cout << "#iteration best_sample" << std::endl;
if (!blacklisted)
(*this->_log_file) << bo.total_iterations() << " " << bo.best_sample(afun).transpose() << std::endl;
}
};
}
}
#endif
......@@ -287,7 +287,7 @@ int main(int argc, char** argv)
opt.optimize(Sphere());
Eigen::Vector2d s_val(0.5, 0.5);
double x_opt = FirstElem()(Sphere()(s_val));
add_to_results("Sphere", results, std::make_pair(x_opt, opt.best_observation()));
add_to_results("Sphere", results, std::make_pair(x_opt, opt.best_observation()(0)));
// clang-format on
});
......@@ -298,7 +298,7 @@ int main(int argc, char** argv)
opt.optimize(Ellipsoid());
Eigen::Vector2d s_val(0.5, 0.5);
double x_opt = FirstElem()(Ellipsoid()(s_val));
add_to_results("Ellipsoid", results, std::make_pair(x_opt, opt.best_observation()));
add_to_results("Ellipsoid", results, std::make_pair(x_opt, opt.best_observation()(0)));
// clang-format on
});
......@@ -309,7 +309,7 @@ int main(int argc, char** argv)
opt.optimize(Rastrigin());
Eigen::Vector4d s_val(0, 0, 0, 0);
double x_opt = FirstElem()(Rastrigin()(s_val));
add_to_results("Rastrigin", results, std::make_pair(x_opt, opt.best_observation()));
add_to_results("Rastrigin", results, std::make_pair(x_opt, opt.best_observation()(0)));
// clang-format on
});
......@@ -321,7 +321,7 @@ int main(int argc, char** argv)
// double s_max = 3.86278;
Eigen::Vector3d s_val(0.114614, 0.555549, 0.852547);
double x_opt = FirstElem()(Hartman3()(s_val));
add_to_results("Hartman 3", results, std::make_pair(x_opt, opt.best_observation()));
add_to_results("Hartman 3", results, std::make_pair(x_opt, opt.best_observation()(0)));
// clang-format on
});
......@@ -334,7 +334,7 @@ int main(int argc, char** argv)
s_val << 0.20169, 0.150011, 0.476874, 0.275332, 0.311652, 0.6573;
//double s_max = 3.32237;
double x_opt = FirstElem()(Hartman6()(s_val));
add_to_results("Hartman 6", results, std::make_pair(x_opt, opt.best_observation()));
add_to_results("Hartman 6", results, std::make_pair(x_opt, opt.best_observation()(0)));
// clang-format on
});
......@@ -346,7 +346,7 @@ int main(int argc, char** argv)
// double s_max = -log(3);
Eigen::Vector2d s_val(0.5, 0.25);
double x_opt = FirstElem()(GoldenPrice()(s_val));
add_to_results("Golden Price", results, std::make_pair(x_opt, opt.best_observation()));
add_to_results("Golden Price", results, std::make_pair(x_opt, opt.best_observation()(0)));
// clang-format on
});
......
......@@ -25,7 +25,7 @@ def create(bld):
acquisitions = ['UCB', 'GP_UCB']
optimizers = ['RandomPoint', 'GridSearch', 'Cmaes']
inits = ['NoInit', 'RandomSampling', 'RandomSamplingGrid', 'GridSampling']
stats = ['Acquisitions']
stats = ['Samples', 'Observations', 'AggregatedObservations', 'BestSamples', 'BestObservations', 'BestAggregatedObservations']
stops = ['MaxIterations', 'MaxPredictedValue']
stats = 'typedef boost::fusion::vector<' + ', '.join(['stat::' + stat + '<Params>' for stat in stats]) + '> stats_t;\n'
......
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