[mrpt-math]
Overview
Math C++ library: vectors and matrices, probability distributions, statistics, geometry, etc.
Library mrpt-math
This library is part of MRPT and can be installed in Debian-based systems with:
sudo apt install libmrpt-math-dev
Read also how to import MRPT into your CMake scripts.
The main classes and concepts associated with this library:
mrpt_math_vectors_matrices_grp: Vectors and matrices (compatible with the Eigen library).
mrpt_math_lwgeom_grp: TPose2D, TPose3D, TPoint3D, TLine3D, geometry functions, etc. (See also: [mrpt-poses])
Other important elements:
KD-Trees
Eigen integration (MRPT 3.x)
MRPT uses Eigen 3 for all matrix/vector types. Key points for MRPT 3 users:
mrpt::math::CMatrixDynamic<T>andmrpt::math::CMatrixFixed<T,R,C>wrap Eigen matrices and are fully serializable viamrpt::serialization::CArchive.Use
.asEigen()on any MRPT matrix to get the underlying Eigen expression for use with Eigen algorithms (decompositions, solvers, etc.).mrpt::math::CVectorDynamic<T>is a column-vector equivalent.Sparse matrices: use
Eigen::SparseMatrix<double>directly; MRPT does not wrap sparse types but provides helpers inmrpt::math::CSparseMatrix(CXSparse-backed) for serialization.Geometric operations (e.g. point clouds): lightweight structs
mrpt::math::TPoint2Df,mrpt::math::TPoint3Df(float) and their double variants are used for performance; they convert freely to/from Eigen vectors.
KD-tree nearest-neighbor search
mrpt::math::KDTreeCapable is a CRTP adapter around nanoflann providing:
kdTreeClosestPoint2D()/kdTreeClosestPoint3D()— single NN query.kdTreeNClosestPoint2D()/kdTreeNClosestPoint3D()— k-NN query.kdTreeRadiusSearch2D()/kdTreeRadiusSearch3D()— radius search.
Derived classes must implement kdtree_get_point_count() and kdtree_get_pt(idx, dim). The KD-tree index is built lazily on first query and invalidated by calling kdtree_mark_as_outdated().
Library contents
// typedefs typedef CLevenbergMarquardtTempl<mrpt::math::CVectorDouble> mrpt::math::CLevenbergMarquardt; // enums enum mrpt::math::TMatrixTextFileFormat; enum mrpt::math::TRobustKernelType; // structs template < typename Scalar, int NROWS, int NCOLS, typename INFO, bool HAS_REMAP, typename INDEX_REMAP_MAP_IMPL = mrpt::containers::map_as_vector<size_t, size_t> > struct mrpt::math::MatrixBlockSparseCols; template <typename T> struct mrpt::math::RobustKernel<rkPseudoHuber, T>; template <typename T> struct mrpt::math::RobustKernel<rkLeastSquares, T>; template <TRobustKernelType KERNEL_TYPE, typename T = double> struct mrpt::math::RobustKernel; struct mrpt::math::matrix_size_t; // classes class mrpt::math::CAtan2LookUpTable; class mrpt::math::CAtan2LookUpTableMultiRes; template <typename T, typename U, bool UIsObject = false> class mrpt::math::CBinaryRelation; class mrpt::math::CHistogram; template <typename VECTORTYPE = CVectorDouble, class USERPARAM = VECTORTYPE> class mrpt::math::CLevenbergMarquardtTempl; class mrpt::math::CMatrixB; class mrpt::math::CMatrixD; template <class T> class mrpt::math::CMatrixDynamic; class mrpt::math::CMatrixF; template <typename T, matrix_dim_t ROWS, matrix_dim_t COLS> class mrpt::math::CMatrixFixed; template <typename T, typename NUM, typename OTHER> class mrpt::math::CMonteCarlo; template <class TDATA, size_t STATE_LEN> class mrpt::math::CProbabilityDensityFunction; template <class T> class mrpt::math::CQuaternion; template <class T> class mrpt::math::CSparseMatrixTemplate; template <class T> class mrpt::math::CVectorDynamic; template < class Derived, typename num_t = float, typename metric_t = nanoflann::L2_Simple_Adaptor<num_t, Derived> > class mrpt::math::KDTreeCapable; template <typename Scalar, class Derived> class mrpt::math::MatrixBase; template <typename Scalar, class Derived> class mrpt::math::MatrixVectorBase; // global functions void mrpt::math::setEpsilon(double nE); double mrpt::math::getEpsilon(); template <class Derived> const Derived& mrpt::math::mat2eig(const Eigen::EigenBase<Derived>& m); template < class VECTORLIKE, class VECTORLIKE2, class VECTORLIKE3, class MATRIXLIKE, class USERPARAM > void mrpt::math::estimateJacobian( const VECTORLIKE& x, const std::function<void(const VECTORLIKE&x, const USERPARAM&y, VECTORLIKE3&out)>& functor, const VECTORLIKE2& increments, const USERPARAM& userParam, MATRIXLIKE& out_Jacobian ); void mrpt::math::registerAllClasses_mrpt_math();
Typedefs
typedef CLevenbergMarquardtTempl<mrpt::math::CVectorDouble> mrpt::math::CLevenbergMarquardt
The default name for the LM class is an instantiation for “double”.
Global Functions
void mrpt::math::setEpsilon(double nE)
Changes the value of the geometric epsilon (default = 1e-5)
See also:
double mrpt::math::getEpsilon()
Gets the value of the geometric epsilon (default = 1e-5)
See also:
template <class Derived> const Derived& mrpt::math::mat2eig(const Eigen::EigenBase<Derived>& m)
Returns an Eigen-compatible type, despite its argument already is an Eigen matrix, or an mrpt-math matrix/vector.
template < class VECTORLIKE, class VECTORLIKE2, class VECTORLIKE3, class MATRIXLIKE, class USERPARAM > void mrpt::math::estimateJacobian( const VECTORLIKE& x, const std::function<void(const VECTORLIKE&x, const USERPARAM&y, VECTORLIKE3&out)>& functor, const VECTORLIKE2& increments, const USERPARAM& userParam, MATRIXLIKE& out_Jacobian )
Estimate the Jacobian of a multi-dimensional function around a point “x”, using finite differences of a given size in each input dimension.
The template argument USERPARAM is for the data can be passed to the functor. If it is not required, set to “int” or any other basic type.
This is a generic template which works with: VECTORLIKE: vector_float, CVectorDouble, CVectorFixed<>, double [N], … MATRIXLIKE: CMatrixDynamic, CMatrixFixed
void mrpt::math::registerAllClasses_mrpt_math()
Forces manual RTTI registration of all serializable classes in this namespace.
Should never be required to be explicitly called by users, except if building MRPT as a static library.