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

Fixes for SquaredExpARD and kernel tests

parent 9f5cef2c
......@@ -116,7 +116,7 @@ namespace limbo {
grad.head(_input_dim) = (x1 - x2).cwiseQuotient(_ell).array().square() * k;
for (size_t j = 0; j < (unsigned int)Params::kernel_squared_exp_ard::k(); ++j) {
Eigen::MatrixXd G = -(x1 - x2).transpose() * _A.col(j) * (x1 - x2).cwiseProduct(_A.col(j)) * k;
Eigen::MatrixXd G = -(x1 - x2).transpose() * _A.col(j) * (x1 - x2).cwiseProduct(_A.col(j)).array() * k;
grad.segment((j + 1) * _input_dim, _input_dim) = G;
}
......
......@@ -136,7 +136,7 @@ std::tuple<double, Eigen::VectorXd, Eigen::VectorXd> check_grad(const Kernel& ke
}
template <typename Kernel>
void check_kernel(size_t N, size_t K)
void check_kernel(size_t N, size_t K, double e = 1e-4)
{
Kernel kern(N);
......@@ -149,8 +149,8 @@ void check_kernel(size_t N, size_t K)
Eigen::VectorXd x1 = tools::random_vector(N).array() * 10. - 5.;
Eigen::VectorXd x2 = tools::random_vector(N).array() * 10. - 5.;
std::tie(error, analytic, finite_diff) = check_grad(kern, hp, x1, x2);
std::cout << error << ": " << analytic.transpose() << " vs " << finite_diff.transpose() << std::endl;
std::tie(error, analytic, finite_diff) = check_grad(kern, hp, x1, x2, e);
// std::cout << error << ": " << analytic.transpose() << " vs " << finite_diff.transpose() << std::endl;
BOOST_CHECK(error < 1e-6);
}
}
......@@ -187,11 +187,9 @@ BOOST_AUTO_TEST_CASE(test_grad_SE_ARD)
check_kernel<kernel::SquaredExpARD<ParamsNoise>>(i, 100);
}
// THIS TEST FAILS!
std::cout << "START" << std::endl;
Params::kernel_squared_exp_ard::set_k(1);
for (int i = 1; i <= 10; i++) {
check_kernel<kernel::SquaredExpARD<Params>>(i, 100);
check_kernel<kernel::SquaredExpARD<Params>>(i, 100, 1e-6);
}
}
......
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