Main MRPT website > C++ reference
MRPT logo
Namespaces | Functions
base/include/mrpt/math/utils.h File Reference
#include <mrpt/utils/utils_defs.h>
#include <mrpt/math/CMatrixTemplateNumeric.h>
#include <mrpt/math/CMatrixFixedNumeric.h>
#include <mrpt/math/CHistogram.h>
#include <mrpt/math/ops_vectors.h>
#include <mrpt/math/ops_matrices.h>
#include <numeric>
#include <cmath>
Include dependency graph for base/include/mrpt/math/utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 mrpt
 This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
 
 mrpt::math
 This base provides a set of functions for maths stuff.
 

Functions

bool BASE_IMPEXP mrpt::math::loadVector (utils::CFileStream &f, std::vector< int > &d)
 Loads one row of a text file as a numerical std::vector. More...
 
bool BASE_IMPEXP mrpt::math::loadVector (utils::CFileStream &f, std::vector< double > &d)
 Loads one row of a text file as a numerical std::vector. More...
 
bool BASE_IMPEXP mrpt::math::isNaN (float f) MRPT_NO_THROWS
 Returns true if the number is NaN. More...
 
bool BASE_IMPEXP mrpt::math::isNaN (double f) MRPT_NO_THROWS
 Returns true if the number is NaN. More...
 
bool BASE_IMPEXP mrpt::math::isFinite (float f) MRPT_NO_THROWS
 Returns true if the number is non infinity. More...
 
bool BASE_IMPEXP mrpt::math::isFinite (double f) MRPT_NO_THROWS
 Returns true if the number is non infinity. More...
 
void BASE_IMPEXP mrpt::math::medianFilter (const std::vector< double > &inV, std::vector< double > &outV, const int &winSize, const int &numberOfSigmas=2)
 
template<typename T , typename VECTOR >
void mrpt::math::linspace (T first, T last, size_t count, VECTOR &out_vector)
 Generates an equidistant sequence of numbers given the first one, the last one and the desired number of points. More...
 
template<class T >
Eigen::Matrix< T, Eigen::Dynamic, 1 > mrpt::math::linspace (T first, T last, size_t count)
 Generates an equidistant sequence of numbers given the first one, the last one and the desired number of points. More...
 
template<class T , T STEP>
Eigen::Matrix< T, Eigen::Dynamic, 1 > mrpt::math::sequence (T first, size_t length)
 Generates a sequence of values [first,first+STEP,first+2*STEP,...]. More...
 
template<class T , T STEP>
std::vector< T > mrpt::math::sequenceStdVec (T first, size_t length)
 Generates a sequence of values [first,first+STEP,first+2*STEP,...]. More...
 
template<class T >
Eigen::Matrix< T, Eigen::Dynamic, 1 > mrpt::math::ones (size_t count)
 Generates a vector of all ones of the given length. More...
 
template<class T >
Eigen::Matrix< T, Eigen::Dynamic, 1 > mrpt::math::zeros (size_t count)
 Generates a vector of all zeros of the given length. More...
 
template<class T >
void mrpt::math::wrapTo2PiInPlace (T &a)
 Modifies the given angle to translate it into the [0,2pi[ range. More...
 
template<class T >
mrpt::math::wrapTo2Pi (T a)
 Modifies the given angle to translate it into the [0,2pi[ range. More...
 
template<class T >
mrpt::math::wrapToPi (T a)
 Modifies the given angle to translate it into the ]-pi,pi] range. More...
 
template<class T >
void mrpt::math::wrapToPiInPlace (T &a)
 Modifies the given angle to translate it into the ]-pi,pi] range. More...
 
template<class VEC1 , class VEC2 >
void mrpt::math::normalize (const VEC1 &v, VEC2 &out_v)
 Normalize a vector, such as its norm is the unity. More...
 
template<class VECTOR_OF_VECTORS , class MATRIXLIKE , class VECTORLIKE , class VECTORLIKE2 , class VECTORLIKE3 >
void mrpt::math::covariancesAndMeanWeighted (const VECTOR_OF_VECTORS &elements, MATRIXLIKE &covariances, VECTORLIKE &means, const VECTORLIKE2 *weights_mean, const VECTORLIKE3 *weights_cov, const bool *elem_do_wrap2pi=NULL)
 Computes covariances and mean of any vector of containers, given optional weights for the different samples. More...
 
template<class VECTOR_OF_VECTORS , class MATRIXLIKE , class VECTORLIKE >
void mrpt::math::covariancesAndMean (const VECTOR_OF_VECTORS &elements, MATRIXLIKE &covariances, VECTORLIKE &means, const bool *elem_do_wrap2pi=NULL)
 Computes covariances and mean of any vector of containers. More...
 
template<class VECTORLIKE1 , class VECTORLIKE2 >
void mrpt::math::weightedHistogram (const VECTORLIKE1 &values, const VECTORLIKE1 &weights, float binWidth, VECTORLIKE2 &out_binCenters, VECTORLIKE2 &out_binValues)
 Computes the weighted histogram for a vector of values and their corresponding weights. More...
 
template<class VECTORLIKE1 , class VECTORLIKE2 >
void mrpt::math::weightedHistogramLog (const VECTORLIKE1 &values, const VECTORLIKE1 &log_weights, float binWidth, VECTORLIKE2 &out_binCenters, VECTORLIKE2 &out_binValues)
 Computes the weighted histogram for a vector of values and their corresponding log-weights. More...
 
template<class VECTOR_OF_VECTORS , class VECTORLIKE >
void mrpt::math::extractColumnFromVectorOfVectors (const size_t colIndex, const VECTOR_OF_VECTORS &data, VECTORLIKE &out_column)
 Extract a column from a vector of vectors, and store it in another vector. More...
 
uint64_t BASE_IMPEXP mrpt::math::factorial64 (unsigned int n)
 Computes the factorial of an integer number and returns it as a 64-bit integer number. More...
 
double BASE_IMPEXP mrpt::math::factorial (unsigned int n)
 Computes the factorial of an integer number and returns it as a double value (internally it uses logarithms for avoiding overflow). More...
 
template<class T >
mrpt::math::round2up (T val)
 Round up to the nearest power of two of a given number. More...
 
template<class T >
mrpt::math::round_10power (T val, int power10)
 Round a decimal number up to the given 10'th power (eg, to 1000,100,10, and also fractions) power10 means round up to: 1 -> 10, 2 -> 100, 3 -> 1000, ... More...
 
template<class T >
double mrpt::math::correlate_matrix (const CMatrixTemplateNumeric< T > &a1, const CMatrixTemplateNumeric< T > &a2)
 Calculate the correlation between two matrices (by AJOGD @ JAN-2007) More...
 
double BASE_IMPEXP mrpt::math::averageLogLikelihood (const vector_double &logLikelihoods)
 A numerically-stable method to compute average likelihood values with strongly different ranges (unweighted likelihoods: compute the arithmetic mean). More...
 
double BASE_IMPEXP mrpt::math::averageWrap2Pi (const vector_double &angles)
 Computes the average of a sequence of angles in radians taking into account the correct wrapping in the range $ ]-\pi,\pi [ $, for example, the mean of (2,-2) is $ \pi $, not 0. More...
 
double BASE_IMPEXP mrpt::math::averageLogLikelihood (const vector_double &logWeights, const vector_double &logLikelihoods)
 A numerically-stable method to average likelihood values with strongly different ranges (weighted likelihoods). More...
 
std::string BASE_IMPEXP mrpt::math::MATLAB_plotCovariance2D (const CMatrixFloat &cov22, const vector_float &mean, const float &stdCount, const std::string &style=std::string("b"), const size_t &nEllipsePoints=30)
 Generates a string with the MATLAB commands required to plot an confidence interval (ellipse) for a 2D Gaussian ('float' version). More...
 
std::string BASE_IMPEXP mrpt::math::MATLAB_plotCovariance2D (const CMatrixDouble &cov22, const vector_double &mean, const float &stdCount, const std::string &style=std::string("b"), const size_t &nEllipsePoints=30)
 Generates a string with the MATLAB commands required to plot an confidence interval (ellipse) for a 2D Gaussian ('double' version). More...
 
template<class MATRIXLIKE1 , class MATRIXLIKE2 >
void mrpt::math::homogeneousMatrixInverse (const MATRIXLIKE1 &M, MATRIXLIKE2 &out_inverse_M)
 Efficiently compute the inverse of a 4x4 homogeneous matrix by only transposing the rotation 3x3 part and solving the translation with dot products. More...
 
template<class IN_ROTMATRIX , class IN_XYZ , class OUT_ROTMATRIX , class OUT_XYZ >
void mrpt::math::homogeneousMatrixInverse (const IN_ROTMATRIX &in_R, const IN_XYZ &in_xyz, OUT_ROTMATRIX &out_R, OUT_XYZ &out_xyz)
 
template<class MATRIXLIKE >
void mrpt::math::homogeneousMatrixInverse (MATRIXLIKE &M)
 
template<class VECTORLIKE , class VECTORLIKE2 , class VECTORLIKE3 , class MATRIXLIKE , class USERPARAM >
void mrpt::math::estimateJacobian (const VECTORLIKE &x, void(*functor)(const VECTORLIKE &x, const USERPARAM &y, VECTORLIKE3 &out), 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. More...
 
template<typename T , typename At , size_t N>
std::vector< T > & mrpt::math::loadVector (std::vector< T > &v, At(&theArray)[N])
 Assignment operator for initializing a std::vector from a C array (The vector will be automatically set to the correct size). More...
 
template<typename Derived , typename At , size_t N>
Eigen::EigenBase< Derived > & mrpt::math::loadVector (Eigen::EigenBase< Derived > &v, At(&theArray)[N])
 
void mrpt::math::unwrap2PiSequence (vector_double &x)
 Modify a sequence of angle values such as no consecutive values have a jump larger than PI in absolute value. More...
 
template<size_t N, typename T >
std::vector< T > mrpt::math::make_vector (const T val1,...)
 A versatile template to build vectors on-the-fly in a style close to MATLAB's v=[a b c d ...] The first argument of the template is the vector length, and the second the type of the numbers. More...
 
template<class T , class VECTOR >
mrpt::math::interpolate (const T &x, const VECTOR &ys, const T &x0, const T &x1)
 Interpolate a data sequence "ys" ranging from "x0" to "x1" (equally spaced), to obtain the approximation of the sequence at the point "x". More...
 
double BASE_IMPEXP mrpt::math::interpolate2points (const double x, const double x0, const double y0, const double x1, const double y1, bool wrap2pi=false)
 Linear interpolation/extrapolation: evaluates at "x" the line (x0,y0)-(x1,y1). More...
 
double BASE_IMPEXP mrpt::math::spline (const double t, const vector_double &x, const vector_double &y, bool wrap2pi=false)
 Interpolates the value of a function in a point "t" given 4 SORTED points where "t" is between the two middle points If wrap2pi is true, output "y" values are wrapped to ]-pi,pi] (It is assumed that input "y" values already are in the correct range). More...
 
template<typename NUMTYPE , class VECTORLIKE >
NUMTYPE mrpt::math::leastSquareLinearFit (const NUMTYPE t, const VECTORLIKE &x, const VECTORLIKE &y, bool wrap2pi=false)
 Interpolates or extrapolates using a least-square linear fit of the set of values "x" and "y", evaluated at a single point "t". More...
 
template<class VECTORLIKE1 , class VECTORLIKE2 , class VECTORLIKE3 >
void mrpt::math::leastSquareLinearFit (const VECTORLIKE1 &ts, VECTORLIKE2 &outs, const VECTORLIKE3 &x, const VECTORLIKE3 &y, bool wrap2pi=false)
 Interpolates or extrapolates using a least-square linear fit of the set of values "x" and "y", evaluated at a sequence of points "ts" and returned at "outs". More...
 
template<class TRIPLET >
bool mrpt::math::saveEigenSparseTripletsToFile (const std::string &sFile, std::vector< TRIPLET > &tri)
 Saves to a plain-text file the nonzero entries of a Eigen sparse matrix, represented as a vector of triplets. More...
 
Probability density distributions (pdf) distance metrics
template<class VECTORLIKE1 , class VECTORLIKE2 , class MAT >
MAT::Scalar mrpt::math::mahalanobisDistance2 (const VECTORLIKE1 &X, const VECTORLIKE2 &MU, const MAT &COV)
 Computes the squared mahalanobis distance of a vector X given the mean MU and the covariance inverse COV_inv

\[ d^2 = (X-MU)^\top \Sigma^{-1} (X-MU) \]

. More...

 
template<class VECTORLIKE1 , class VECTORLIKE2 , class MAT >
VECTORLIKE1::Scalar mrpt::math::mahalanobisDistance (const VECTORLIKE1 &X, const VECTORLIKE2 &MU, const MAT &COV)
 Computes the mahalanobis distance of a vector X given the mean MU and the covariance inverse COV_inv

\[ d = \sqrt{ (X-MU)^\top \Sigma^{-1} (X-MU) } \]

. More...

 
template<class VECTORLIKE , class MAT1 , class MAT2 , class MAT3 >
MAT1::Scalar mrpt::math::mahalanobisDistance2 (const VECTORLIKE &mean_diffs, const MAT1 &COV1, const MAT2 &COV2, const MAT3 &CROSS_COV12)
 Computes the squared mahalanobis distance between two non-independent Gaussians, given the two covariance matrices and the vector with the difference of their means. More...
 
template<class VECTORLIKE , class MAT1 , class MAT2 , class MAT3 >
VECTORLIKE::Scalar mrpt::math::mahalanobisDistance (const VECTORLIKE &mean_diffs, const MAT1 &COV1, const MAT2 &COV2, const MAT3 &CROSS_COV12)
 Computes the mahalanobis distance between two non-independent Gaussians (or independent if CROSS_COV12=NULL), given the two covariance matrices and the vector with the difference of their means. More...
 
template<class VECTORLIKE , class MATRIXLIKE >
MATRIXLIKE::Scalar mrpt::math::mahalanobisDistance2 (const VECTORLIKE &delta_mu, const MATRIXLIKE &cov)
 Computes the squared mahalanobis distance between a point and a Gaussian, given the covariance matrix and the vector with the difference between the mean and the point. More...
 
template<class VECTORLIKE , class MATRIXLIKE >
MATRIXLIKE::Scalar mrpt::math::mahalanobisDistance (const VECTORLIKE &delta_mu, const MATRIXLIKE &cov)
 Computes the mahalanobis distance between a point and a Gaussian, given the covariance matrix and the vector with the difference between the mean and the point. More...
 
template<typename T >
mrpt::math::productIntegralTwoGaussians (const std::vector< T > &mean_diffs, const CMatrixTemplateNumeric< T > &COV1, const CMatrixTemplateNumeric< T > &COV2)
 Computes the integral of the product of two Gaussians, with means separated by "mean_diffs" and covariances "COV1" and "COV2". More...
 
template<typename T , size_t DIM>
mrpt::math::productIntegralTwoGaussians (const std::vector< T > &mean_diffs, const CMatrixFixedNumeric< T, DIM, DIM > &COV1, const CMatrixFixedNumeric< T, DIM, DIM > &COV2)
 Computes the integral of the product of two Gaussians, with means separated by "mean_diffs" and covariances "COV1" and "COV2". More...
 
template<typename T , class VECLIKE , class MATLIKE1 , class MATLIKE2 >
void mrpt::math::productIntegralAndMahalanobisTwoGaussians (const VECLIKE &mean_diffs, const MATLIKE1 &COV1, const MATLIKE2 &COV2, T &maha2_out, T &intprod_out, const MATLIKE1 *CROSS_COV12=NULL)
 Computes both, the integral of the product of two Gaussians and their square Mahalanobis distance. More...
 
template<typename T , class VECLIKE , class MATRIXLIKE >
void mrpt::math::mahalanobisDistance2AndLogPDF (const VECLIKE &diff_mean, const MATRIXLIKE &cov, T &maha2_out, T &log_pdf_out)
 Computes both, the logarithm of the PDF and the square Mahalanobis distance between a point (given by its difference wrt the mean) and a Gaussian. More...
 
template<typename T , class VECLIKE , class MATRIXLIKE >
void mrpt::math::mahalanobisDistance2AndPDF (const VECLIKE &diff_mean, const MATRIXLIKE &cov, T &maha2_out, T &pdf_out)
 Computes both, the PDF and the square Mahalanobis distance between a point (given by its difference wrt the mean) and a Gaussian. More...
 



Page generated by Doxygen 1.8.14 for MRPT 1.0.2 SVN: at lun oct 28 00:52:41 CET 2019 Hosted on:
SourceForge.net Logo