Commit 8105243c authored by Konstantinos Chatzilygeroudis's avatar Konstantinos Chatzilygeroudis
Browse files

Small cleaning and trying to fix the error in travis

parent 8b3b9587
......@@ -244,7 +244,7 @@ namespace limbo {
if (update_full_kernel)
this->_compute_full_kernel();
else
this->_compute_alpha();
this->_compute_alpha();
}
void compute_inv_kernel()
......@@ -415,11 +415,11 @@ namespace limbo {
bool inv_kernel_computed() { return _inv_kernel_updated; }
/// save the parameters and the data for the GP to the archive (text or binary)
template<typename A>
void save(A& archive)
template <typename A>
void save(A& archive)
{
archive.save(_kernel_function.h_params(), "kernel_params");
// archive.save(_mean_function.h_params(), "mean_params");
// archive.save(_mean_function.h_params(), "mean_params");
archive.save(_samples, "samples");
archive.save(_observations, "observations");
}
......@@ -436,9 +436,9 @@ namespace limbo {
std::vector<Eigen::VectorXd> samples;
archive.load(samples, "samples");
std::vector<Eigen::VectorXd> observations;
std::vector<Eigen::VectorXd> observations;
archive.load(observations, "observations");
compute(samples, observations);
}
......@@ -470,7 +470,7 @@ namespace limbo {
{
assert(!_samples.empty());
_mean_vector.resize(_samples.size(), _dim_out);
for (int i = 0; i < _mean_vector.rows(); i++){
for (int i = 0; i < _mean_vector.rows(); i++) {
assert(_samples[i].cols() == 1);
assert(_samples[i].rows() != 0);
assert(_samples[i].rows() == _dim_in);
......@@ -572,7 +572,7 @@ namespace limbo {
/// Determination (ARD), and hyper-parameter optimization based on Rprop
template <typename Params>
using GPOpt = GP<Params, kernel::SquaredExpARD<Params>, mean::Data<Params>, gp::KernelLFOpt<Params>>;
}
}
} // namespace model
} // namespace limbo
#endif
......@@ -2,7 +2,10 @@
#include <iostream>
#include <sstream>
#include <string>
// Quick hack for definition of 'I' in <complex.h>
#undef I
#include <boost/filesystem.hpp>
#include <Eigen/Core>
namespace limbo {
......@@ -11,7 +14,7 @@ namespace limbo {
class TextArchive {
public:
TextArchive(const std::string& dir_name) : _dir_name(dir_name),
_fmt(Eigen::FullPrecision, Eigen::DontAlignCols, " ", "\n", "", "") {}
_fmt(Eigen::FullPrecision, Eigen::DontAlignCols, " ", "\n", "", "") {}
/// write an Eigen::Matrix*
void save(const Eigen::MatrixXd& v, const std::string& object_name)
......@@ -27,7 +30,7 @@ namespace limbo {
_create_directory();
std::ofstream ofs(fname(object_name).c_str());
for (auto& x : v) {
ofs << x.transpose().format(_fmt) << std::endl;
ofs << x.transpose().format(_fmt) << std::endl;
}
}
......@@ -47,7 +50,7 @@ namespace limbo {
void load(std::vector<V>& m_list, const std::string& object_name)
{
m_list.clear();
auto values = _load(object_name);
auto values = _load(object_name);
assert(!values.empty());
for (size_t i = 0; i < values.size(); ++i) {
V v(values[i].size());
......@@ -65,8 +68,8 @@ namespace limbo {
protected:
std::string _dir_name;
Eigen::IOFormat _fmt;
//
Eigen::IOFormat _fmt;
void _create_directory()
{
boost::filesystem::path my_path(_dir_name);
......
......@@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(test_text_archive)
for (size_t i = 0; i < n; i++) {
Eigen::VectorXd s = tools::random_vector(3).array() * 4.0 - 2.0;
samples.push_back(s);
observations.push_back(tools::make_vector(std::cos(s(0)*s(1)*s(2))));
observations.push_back(tools::make_vector(std::cos(s(0) * s(1) * s(2))));
}
// 3-D inputs, 1-D outputs
model::GPOpt<Params> gp(3, 1);
......@@ -95,7 +95,31 @@ BOOST_AUTO_TEST_CASE(test_text_archive)
model::GPOpt<Params> gp2(3, 1);
serialize::TextArchive a2("/tmp/test_model.dat");
gp2.load(a2);
// check that the 2 GPs match
size_t N = 100;
double diff_mu = 0.;
double diff_sigma = 0.;
for (size_t i = 0; i < N; i++) {
Eigen::VectorXd s = tools::random_vector(3).array() * 4.0 - 2.0;
samples.push_back(s);
Eigen::VectorXd mu1, mu2;
double s1, s2;
std::tie(mu1, s1) = gp.query(s);
std::tie(mu2, s2) = gp2.query(s);
diff_mu += std::abs(mu1(0) - mu2(0));
diff_sigma += std::abs(s1 - s2);
}
diff_mu /= double(N);
diff_sigma /= double(N);
BOOST_CHECK(diff_mu < 1e-6);
BOOST_CHECK(diff_sigma < 1e-6);
}
BOOST_AUTO_TEST_CASE(test_bin_archive)
......
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