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

Fix for time issues

parent 6d4a69df
......@@ -66,7 +66,7 @@ void benchmark(const std::string& name)
DirectParams::opt_nloptnograd::set_iterations(static_cast<int>(iters_base * Function::dim_in * 0.9));
BobyqaParams::opt_nloptnograd::set_iterations(iters_base * Function::dim_in - DirectParams::opt_nloptnograd::iterations());
BobyqaParams_HP::opt_nloptnograd::set_iterations(10 * Function::dim_in);
BobyqaParams_HP::opt_nloptnograd::set_iterations(10 * Function::dim_in * Function::dim_in);
auto t1 = std::chrono::steady_clock::now();
Optimizer opt;
......
......@@ -268,7 +268,7 @@ public:
double diff = std::abs(x + f(sols.row(0)));
double min_diff = diff;
for (size_t i = 1; i < sols.rows(); i++) {
for (int i = 1; i < sols.rows(); i++) {
diff = std::abs(x + f(sols.row(i)));
if (diff < min_diff)
min_diff = diff;
......
......@@ -71,9 +71,15 @@ namespace limbo {
double operator()(const Eigen::VectorXd& x1, const Eigen::VectorXd& x2) const
{
assert(x1.size() == _ell.size());
Eigen::MatrixXd K = (_A * _A.transpose());
K.diagonal() += (Eigen::MatrixXd)(_ell.array().inverse().square());
double z = ((x1 - x2).transpose() * K * (x1 - x2)).norm();
double z;
if (Params::kernel_squared_exp_ard::k() > 0) {
Eigen::MatrixXd K = (_A * _A.transpose());
K.diagonal() += (Eigen::MatrixXd)(_ell.array().inverse().square());
z = ((x1 - x2).transpose() * K * (x1 - x2)).norm();
}
else {
z = (x1 - x2).cwiseQuotient(_ell).squaredNorm();
}
return _sf2 * std::exp(-0.5 * z);
}
......
......@@ -349,8 +349,9 @@ namespace limbo {
void _compute_alpha()
{
// alpha = K^{-1} * this->_obs_mean;
_alpha = _matrixL.template triangularView<Eigen::Lower>().solve(_obs_mean);
_matrixL.template triangularView<Eigen::Lower>().adjoint().solveInPlace(_alpha); //can probably be improved by avoiding to generate the view twice
auto triang = _matrixL.template triangularView<Eigen::Lower>();
_alpha = triang.solve(_obs_mean);
triang.adjoint().solveInPlace(_alpha);
}
void _compute_bl_kernel()
......
......@@ -59,7 +59,7 @@ 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}
......
......@@ -11,7 +11,9 @@ namespace limbo {
namespace opt {
// Needed for the variadic data structure
template <typename Params, typename... Optimizers> struct Chained {};
template <typename Params, typename... Optimizers>
struct Chained {
};
// Base case: just 1 optimizer to call
template <typename Params, typename Optimizer>
......@@ -29,7 +31,7 @@ namespace limbo {
template <typename F>
Eigen::VectorXd operator()(const F& f, const Eigen::VectorXd& init, bool bounded) const
{
return Chained<Params, Optimizers...>::operator ()(f, Optimizer()(f, init, bounded), bounded);
return Chained<Params, Optimizers...>::operator()(f, Optimizer()(f, init, bounded), bounded);
};
};
}
......
......@@ -74,12 +74,10 @@ namespace limbo {
double max;
try
{
try {
opt.optimize(x, max);
}
catch (nlopt::roundoff_limited& e)
{
catch (nlopt::roundoff_limited& e) {
// In theory it's ok to ignore this error
}
......
......@@ -91,12 +91,10 @@ namespace limbo {
double max;
try
{
try {
opt.optimize(x, max);
}
catch (nlopt::roundoff_limited& e)
{
catch (nlopt::roundoff_limited& e) {
// In theory it's ok to ignore this error
}
......
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