17#ifndef __math_least_squares_h__
18#define __math_least_squares_h__
20#include <Eigen/Cholesky>
38 template <
class MatrixType>
39 inline Eigen::Matrix<typename MatrixType::Scalar,Eigen::Dynamic, Eigen::Dynamic>
pinv (
const MatrixType& M)
41 if (M.rows() >= M.cols())
42 return (M.transpose()*M).ldlt().solve (M.transpose());
44 return (M*M.transpose()).ldlt().solve (M).transpose();
47 template <
class MatrixType>
48 inline size_t rank (
const MatrixType& M)
50 Eigen::FullPivLU<MatrixType> lu_decomp (M);
51 return lu_decomp.rank();
Eigen::Matrix< typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic > pinv(const MatrixType &M)
return Moore-Penrose pseudo-inverse of M
size_t rank(const MatrixType &M)