22 #ifndef _LINEARLEASTSQUARES_HPP_
23 #define _LINEARLEASTSQUARES_HPP_
36 template <LinearLeastSquaresType lls_type = LinearLeastSquaresType_LU>
37 class LinearLeastSquares;
44 boost::numeric::ublas::vector<T> solve(
const boost::numeric::ublas::matrix<T>&
A,
45 const boost::numeric::ublas::vector<T>&
y)
47 boost::numeric::ublas::permutation_matrix<std::size_t> m(A.size1());
48 boost::numeric::ublas::matrix<T> AtA = prod(trans(A), A);
49 boost::numeric::ublas::vector<T> b =
y;
50 boost::numeric::ublas::vector<T> r;
54 if (boost::numeric::ublas::lu_factorize(AtA, m) == 0.)
56 r = prod(trans(A), b);
58 boost::numeric::ublas::lu_substitute(AtA, m, r);
66 class LinearLeastSquares<LinearLeastSquaresType_QR>
71 boost::numeric::ublas::vector<T> solve(
72 const boost::numeric::ublas::matrix<T>&
A,
73 const boost::numeric::ublas::vector<T>&
x)
77 boost::numeric::ublas::vector<T>
y = solver.
solve(A, x);
86 #endif // _LINEARLEASTSQUARES_HPP_