Commit 8bf3cc85 authored by Antoine Cully's avatar Antoine Cully
Browse files

minor improvements and guard against call to non-const kernel_function accessor

parent 779d14bc
This diff is collapsed.
......@@ -3,8 +3,8 @@
#include <Eigen/Core>
#include <limbo/opt/rprop.hpp>
#include <limbo/opt/parallel_repeater.hpp>
#include <limbo/opt/rprop.hpp>
#include <limbo/tools/random_generator.hpp>
namespace limbo {
......@@ -59,10 +59,9 @@ namespace limbo {
// K^{-1} using Cholesky decomposition
Eigen::MatrixXd w = Eigen::MatrixXd::Identity(n, n);
gp.matrixL().template triangularView<Eigen::Lower>().solveInPlace(w);
gp.matrixL().template triangularView<Eigen::Lower>().solveInPlace(w);
gp.matrixL().template triangularView<Eigen::Lower>().transpose().solveInPlace(w);
// alpha * alpha.transpose() - K^{-1}
w = gp.alpha() * gp.alpha().transpose() - w;
......
......@@ -3,8 +3,8 @@
#include <Eigen/Core>
#include <limbo/opt/rprop.hpp>
#include <limbo/opt/parallel_repeater.hpp>
#include <limbo/opt/rprop.hpp>
#include <limbo/tools/random_generator.hpp>
namespace limbo {
......@@ -61,8 +61,7 @@ namespace limbo {
// K^{-1} using Cholesky decomposition
Eigen::MatrixXd K = Eigen::MatrixXd::Identity(n, n);
gp.matrixL().template triangularView<Eigen::Lower>().solveInPlace(K);
gp.matrixL().template triangularView<Eigen::Lower>().solveInPlace(K);
gp.matrixL().template triangularView<Eigen::Lower>().transpose().solveInPlace(K);
// alpha * alpha.transpose() - K^{-1}
......
......@@ -3,8 +3,8 @@
#include <Eigen/Core>
#include <limbo/opt/rprop.hpp>
#include <limbo/opt/parallel_repeater.hpp>
#include <limbo/opt/rprop.hpp>
#include <limbo/tools/random_generator.hpp>
namespace limbo {
......
#include <cmath>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <vector>
#include <Eigen/Core>
#ifdef USE_TBB
#include <tbb/task_scheduler_init.h>
#include <tbb/parallel_for.h>
#include <tbb/concurrent_hash_map.h>
#include <tbb/parallel_for.h>
#include <tbb/task_scheduler_init.h>
#else
#include <map>
#endif
#include <limbo/tools/macros.hpp>
#include <limbo/bayes_opt/boptimizer.hpp>
#include <limbo/tools/macros.hpp>
#include <limbo/tools/parallel.hpp>
using namespace limbo;
......@@ -236,7 +236,7 @@ void print_res(const T& r)
std::vector<std::pair<double, double>>& v = x.second;
std::sort(v.begin(), v.end(),
[](const std::pair<double, double>& x1,
const std::pair<double, double>& x2) {
const std::pair<double, double>& x2) {
// clang-format off
return x1.second < x2.second;
// clang-format on
......@@ -298,7 +298,7 @@ int main(int argc, char** argv)
if (!is_in_argv(argc, argv, "--only") || is_in_argv(argc, argv, "sphere"))
tools::par::replicate(nb_replicates, [&]() {
// clang-format off
// clang-format off
Opt_t opt;
opt.optimize(Sphere());
Eigen::Vector2d s_val(0.5, 0.5);
......@@ -309,7 +309,7 @@ int main(int argc, char** argv)
if (!is_in_argv(argc, argv, "--only") || is_in_argv(argc, argv, "ellipsoid"))
tools::par::replicate(nb_replicates, [&]() {
// clang-format off
// clang-format off
Opt_t opt;
opt.optimize(Ellipsoid());
Eigen::Vector2d s_val(0.5, 0.5);
......@@ -320,7 +320,7 @@ int main(int argc, char** argv)
if (!is_in_argv(argc, argv, "--only") || is_in_argv(argc, argv, "rastrigin"))
tools::par::replicate(nb_replicates, [&]() {
// clang-format off
// clang-format off
Opt_t opt;
opt.optimize(Rastrigin());
Eigen::Vector4d s_val(0, 0, 0, 0);
......@@ -331,7 +331,7 @@ int main(int argc, char** argv)
if (!is_in_argv(argc, argv, "--only") || is_in_argv(argc, argv, "hartman3"))
tools::par::replicate(nb_replicates, [&]() {
// clang-format off
// clang-format off
Opt_t opt;
opt.optimize(Hartman3());
// double s_max = 3.86278;
......@@ -343,7 +343,7 @@ int main(int argc, char** argv)
if (!is_in_argv(argc, argv, "--only") || is_in_argv(argc, argv, "hartman6"))
tools::par::replicate(nb_replicates, [&]() {
// clang-format off
// clang-format off
Opt_t opt;
opt.optimize(Hartman6());
Eigen::Matrix<double, 6, 1> s_val;
......@@ -356,7 +356,7 @@ int main(int argc, char** argv)
if (!is_in_argv(argc, argv, "--only") || is_in_argv(argc, argv, "golden_price"))
tools::par::replicate(nb_replicates, [&]() {
// clang-format off
// clang-format off
Opt_t opt;
opt.optimize(GoldenPrice());
// double s_max = -log(3);
......
......@@ -3,14 +3,14 @@
#include <boost/test/unit_test.hpp>
#include <limbo/tools/macros.hpp>
#include <limbo/acqui/ucb.hpp>
#include <limbo/kernel/matern_five_halfs.hpp>
#include <limbo/kernel/squared_exp_ard.hpp>
#include <limbo/mean/constant.hpp>
#include <limbo/model/gp.hpp>
#include <limbo/model/gp/kernel_lf_opt.hpp>
#include <limbo/acqui/ucb.hpp>
#include <limbo/opt/grid_search.hpp>
#include <limbo/tools/macros.hpp>
using namespace limbo;
......@@ -115,66 +115,59 @@ BOOST_AUTO_TEST_CASE(test_gp)
}
}
BOOST_AUTO_TEST_CASE(test_gp_bw_inversion)
{
using namespace limbo;
typedef kernel::MaternFiveHalfs<Params> KF_t;
typedef mean::Constant<Params> Mean_t;
typedef model::GP<Params, KF_t, Mean_t> GP_t;
BOOST_AUTO_TEST_CASE(test_gp_bw_inversion){
using namespace limbo;
typedef kernel::MaternFiveHalfs<Params> KF_t;
typedef mean::Constant<Params> Mean_t;
typedef model::GP<Params, KF_t, Mean_t> GP_t;
std::vector<Eigen::VectorXd> observations;
std::vector<Eigen::VectorXd> samples;
tools::rgen_double_t rgen(0.0, 10);
for(size_t i=0;i<100; i++)
{
observations.push_back(make_v1(rgen.rand()));
samples.push_back(make_v1(rgen.rand()));
std::vector<Eigen::VectorXd> observations;
std::vector<Eigen::VectorXd> samples;
tools::rgen_double_t rgen(0.0, 10);
for (size_t i = 0; i < 100; i++) {
observations.push_back(make_v1(rgen.rand()));
samples.push_back(make_v1(rgen.rand()));
}
GP_t gp;
auto t1 = std::chrono::steady_clock::now();
gp.compute(samples, observations, 0.0);
auto time_init = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout.precision(17);
std::cout << "Time running first batch: " << time_init << "us" << std::endl<<std::endl;
observations.push_back(make_v1(rgen.rand()));
samples.push_back(make_v1(rgen.rand()));
t1 = std::chrono::steady_clock::now();
gp.compute(samples, observations, 0.0);
auto time_increment = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout << "Time running increment: " << time_increment << "us" << std::endl<<std::endl;
t1 = std::chrono::steady_clock::now();
gp.compute(samples, observations, 0.0);
auto time_nothing = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout << "Time running no change: " << time_nothing << "us" << std::endl<<std::endl;
GP_t gp2;
t1 = std::chrono::steady_clock::now();
gp2.compute(samples, observations, 0.0);
auto time_full = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout << "Time running whole batch: " << time_full << "us" << std::endl<<std::endl;
GP_t gp;
auto t1 = std::chrono::steady_clock::now();
gp.compute(samples, observations, 0.0);
auto time_init = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout.precision(17);
std::cout << "Time running first batch: " << time_init << "us" << std::endl
<< std::endl;
observations.push_back(make_v1(rgen.rand()));
samples.push_back(make_v1(rgen.rand()));
Eigen::VectorXd s=make_v1(rgen.rand());
BOOST_CHECK((gp.mu(s)-gp2.mu(s)).norm()<1e-5);
BOOST_CHECK(gp.matrixL().isApprox(gp2.matrixL(),1e-5));
BOOST_CHECK(time_full>time_increment);
BOOST_CHECK(time_increment > time_nothing);
t1 = std::chrono::steady_clock::now();
gp.compute(samples, observations, 0.0);
auto time_increment = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout << "Time running increment: " << time_increment << "us" << std::endl
<< std::endl;
t1 = std::chrono::steady_clock::now();
gp.compute(samples, observations, 0.0);
auto time_nothing = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout << "Time running no change: " << time_nothing << "us" << std::endl
<< std::endl;
GP_t gp2;
t1 = std::chrono::steady_clock::now();
gp2.compute(samples, observations, 0.0);
auto time_full = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout << "Time running whole batch: " << time_full << "us" << std::endl
<< std::endl;
Eigen::VectorXd s = make_v1(rgen.rand());
BOOST_CHECK((gp.mu(s) - gp2.mu(s)).norm() < 1e-5);
BOOST_CHECK(gp.matrixL().isApprox(gp2.matrixL(), 1e-5));
BOOST_CHECK(time_full > time_increment);
BOOST_CHECK(time_increment > time_nothing);
}
BOOST_AUTO_TEST_CASE(test_gp_no_samples_acqui_opt)
{
using namespace limbo;
......
......@@ -3,10 +3,10 @@
#include <boost/test/unit_test.hpp>
#include <limbo/tools/macros.hpp>
#include <limbo/init.hpp>
#include <limbo/acqui.hpp>
#include <limbo/bayes_opt/boptimizer.hpp>
#include <limbo/init.hpp>
#include <limbo/tools/macros.hpp>
using namespace limbo;
......
......@@ -3,11 +3,11 @@
#include <boost/test/unit_test.hpp>
#include <limbo/tools/macros.hpp>
#include <limbo/opt/chained.hpp>
#include <limbo/opt/cmaes.hpp>
#include <limbo/opt/grid_search.hpp>
#include <limbo/opt/random_point.hpp>
#include <limbo/opt/chained.hpp>
#include <limbo/tools/macros.hpp>
using namespace limbo;
......
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