gpregressor.cpp
Go to the documentation of this file.
00001 #ifdef MKL
00002 #include "mkl.h"
00003 #endif
00004 
00005 #include "gpregressor.h"
00006 #include "covMaterniso3.h"
00007 // #include <iostream>
00008 
00009 
00010 using namespace Eigen;
00011 // using namespace std;
00012 
00013 void GPRegressor::train(const MatrixXf &_x, const MatrixXf &y) {
00014     x = MatrixXf(_x);
00015     K = covMaterniso3(x, x, sf2, ell);
00016     K = K + noise * MatrixXf::Identity(K.rows(), K.cols());
00017     LLT<MatrixXf> llt(K);
00018     alpha = llt.solve(y);
00019     L = llt.matrixL();
00020 }
00021 
00022 void GPRegressor::test(const MatrixXf &xs, MatrixXf &m, MatrixXf &s2) const {
00023     MatrixXf Ks = covMaterniso3(x, xs, sf2, ell);
00024     m = Ks.transpose() * alpha;
00025 #ifdef MKL
00026     int n, nrhs;
00027     n = L.rows();
00028     nrhs = Ks.cols();
00029     double *ap = (double *)mkl_malloc(n * (n + 1) / 2 * sizeof(double), 64);
00030     double *b = Ks.data();
00031     for (int i = 0, k = 0; i < n; ++i) {
00032         for (int j = i; j < n; ++j) {
00033             ap[k++] = L(j, i);
00034         }
00035     }
00036     LAPACKE_dtptrs(LAPACK_COL_MAJOR, 'L', 'N', 'N', n, nrhs, ap, b, n);
00037     mkl_free(ap);
00038     Map<MatrixXf> v(b, n, nrhs);
00039 #else
00040     MatrixXf v = L.triangularView<Lower>().solve(Ks);
00041 #endif // MKL
00042 
00043     MatrixXf Kss = covMaterniso3(xs, xs, sf2, ell, true);
00044     s2 = Kss - (v.transpose() * v).diagonal();
00045 }
00046 
00047 //void GPRegressor::bcm(const MatrixXf &m1, const MatrixXf &s21, MatrixXf &m2,
00048 //                      MatrixXf &s22) const {
00049 //    MatrixXf is21 = s21.cwiseInverse();
00050 //    MatrixXf is22 = s22.cwiseInverse();
00051 //    m2 = (is21.array() * m1.array() + is22.array() * m2.array()).matrix();
00052 //    s22 = (is21.array() + is22.array() - sf2).cwiseInverse();
00053 //    m2 = (s22.array() * m2.array()).matrix();
00054 //}
00055 
00056 
00057 // int main()
00058 // {
00059 //     GPRegressor g(1, 1, 1);
00060 //     MatrixXf x(2, 2), y(2, 1), xs(2, 2);
00061 //     x << 1, 2, 2, 3;
00062 //     y << 1, -1;
00063 //     xs(0,0) = 1;  xs(0,1) = 2;
00064 //     xs(1,0) = 2;  xs(1,1) = 3;
00065 
00066 //     MatrixXf m, s2;
00067 //     g.train(x, y);
00068 //     g.test(xs, m, s2);
00069 //     std::cout << "gp mean  : " << m << "size: " << m.size() << std::endl;
00070 //     std::cout << "gp cov   : " << s2 << std::endl;
00071 
00072 //     return 0;
00073 // }


turtlebot_exploration_3d
Author(s): Bona , Shawn
autogenerated on Thu Jun 6 2019 20:58:18