MRPT logo

mrpt::math Namespace Reference

This base provides a set of functions for maths stuff. More...


Classes

class  CGraphPartitioner
 Algorithms for finding the min-normalized-cut of a weighted undirected graph. More...
class  CHistogram
 This class provides an easy way of computing histograms for unidimensional real valued variables. More...
class  CLevenbergMarquardtTempl
 An implementation of the Levenberg-Marquardt algorithm for least-square minimization. More...
class  CMatrix
 This class is a "CSerializable" wrapper for "CMatrixFloat". More...
class  CMatrixB
 This class is a "CSerializable" wrapper for "CMatrixBool". More...
class  CMatrixD
 This class is a "CSerializable" wrapper for "CMatrixTemplateNumeric<double>". More...
class  CMatrixTemplate
 This template class provides the basic functionality for a general 2D any-size, resizable container of numerical or non-numerical elements. More...
class  CMatrixTemplateNumeric
 This template class extends the class "CMatrixTemplate" with many common operations with numerical matrixes. More...
class  CMatrixTemplateObjects
 This template class extends the class "CMatrixTemplate" for storing "objects" at each matrix entry. More...
class  CPolygon
 A simple 2D polygon class, mainly for checking points falling inside it. More...
class  CQuaternion
class  CSplineInterpolator1D
 A (persistent) sequence of (x,y) coordinates, allowing queries of intermediate points through spline interpolation, where possible. More...
class  CVectorTemplate
 This template class provides the basic functionality for a general 1D any-size, resizable container of numerical or non-numerical elements. More...

Typedefs

typedef
CLevenbergMarquardtTempl
< double > 
CLevenbergMarquardt
 The default name for the LM class is an instantiation for "double".
typedef CMatrixTemplateNumeric
< float > 
CMatrixFloat
 Declares a matrix of float numbers (non serializable).
typedef CMatrixTemplateNumeric
< double > 
CMatrixDouble
 Declares a matrix of double numbers (non serializable).
typedef CMatrixTemplateNumeric
< unsigned int > 
CMatrixUInt
 Declares a matrix of unsigned ints (non serializable).
typedef CMatrixTemplate< bool > CMatrixBool
 Declares a matrix of booleans (non serializable).
typedef CMatrixTemplateNumeric
< double > 
CMatrixLongDouble
 Declares a matrix of "long doubles" (non serializable), or of "doubles" if the compiler does not support "long double".
typedef CVectorTemplate< float > CVectorFloat
 Declares a vector of float elements.
typedef CVectorTemplate< double > CVectorDouble
 Declares a vector of double elements.

Enumerations

enum  TMatrixTextFileFormat { MATRIX_FORMAT_ENG = 0, MATRIX_FORMAT_FIXED = 1, MATRIX_FORMAT_INT = 2 }
 Selection of the number format in CMatrixTemplateNumeric::saveToTextFile. More...

Functions

bool MRPTDLLIMPEXP isNan (float v)
 Returns true if value is Not-a-number (NAN).
bool MRPTDLLIMPEXP isNan (double v)
 Returns true if value is Not-a-number (NAN).
bool MRPTDLLIMPEXP isFinite (float v)
 Returns true if value is finite.
bool MRPTDLLIMPEXP isFinite (double v)
 Returns true if value is finite.
template<class T >
std::ostream & operator<< (std::ostream &ostrm, const CMatrixTemplate< T > &m)
 Textual output stream function.
template<class T >
size_t size (const CMatrixTemplate< T > &m, int dim)
 Returns the size of the matrix in the i'th dimension: 1=rows, 2=columns (MATLAB-compatible function).
template<class T >
bool operator== (const CMatrixTemplateNumeric< T > &m1, const CMatrixTemplateNumeric< T > &m2)
 Logical equal-to operator.
template<class T >
bool operator!= (const CMatrixTemplateNumeric< T > &m1, const CMatrixTemplateNumeric< T > &m2)
 logical no-equal-to operator
template<class T >
CMatrixTemplateNumeric< T > operator+ (const CMatrixTemplateNumeric< T > &m1, const CMatrixTemplateNumeric< T > &m2)
 binary addition operator
template<class T >
CMatrixTemplateNumeric< T > operator- (const CMatrixTemplateNumeric< T > &m1, const CMatrixTemplateNumeric< T > &m2)
 binary subtraction operator
template<class T >
CMatrixTemplateNumeric< T > operator* (const CMatrixTemplateNumeric< T > &m, const T &no)
 binary scalar multiplication operator
template<class T >
CMatrixTemplateNumeric< T > operator* (const T &no, const CMatrixTemplateNumeric< T > &m)
 binary scalar multiplication operator
template<class T >
CMatrixTemplateNumeric< T > operator* (const CMatrixTemplateNumeric< T > &m1, const CMatrixTemplateNumeric< T > &m2)
 binary matrix multiplication operator
template<class T >
CMatrixTemplateNumeric< T > operator* (const CMatrixTemplateNumeric< T > &m1, const CVectorTemplate< T > &m2)
 Binary matrix multiplication operator, with one matrix being NxM and the second being a column matrix Mx1.
template<class T >
CMatrixTemplateNumeric< T > operator/ (const CMatrixTemplateNumeric< T > &m, const T &no)
 binary scalar division operator
template<class T >
CMatrixTemplateNumeric< T > operator/ (const T &no, const CMatrixTemplateNumeric< T > &m)
 binary scalar division operator
template<class T >
CMatrixTemplateNumeric< T > operator/ (const CMatrixTemplateNumeric< T > &m1, const CMatrixTemplateNumeric< T > &m2)
 binary matrix division operator
template<class T >
CMatrixTemplateNumeric< T > operator^ (const CMatrixTemplateNumeric< T > &m, const unsigned int &pow)
 binary power operator
template<class T >
CMatrixTemplateNumeric< T > operator~ (const CMatrixTemplateNumeric< T > &m)
 unary transpose operator
template<class T >
CMatrixTemplateNumeric< T > operator! (const CMatrixTemplateNumeric< T > &m)
 Unary inversion operator.
double MRPTDLLIMPEXP normalPDF (double x, double mu, double std)
 Evaluates the univariate normal (Gaussian) distribution at a given point "x".
template<class T >
normalPDF (const CMatrixTemplateNumeric< T > &x, const CMatrixTemplateNumeric< T > &mu, const CMatrixTemplateNumeric< T > &cov)
 Evaluates the multivariate normal (Gaussian) distribution at a given point "x" ("x" and "mu" can be 1xN or Nx1 matrixes).
double MRPTDLLIMPEXP erfc (double x)
 The complementary error function of a Normal distribution.
double MRPTDLLIMPEXP erf (double x)
 The error function of a Normal distribution.
double MRPTDLLIMPEXP normalQuantile (double p)
 Evaluates the Gaussian distribution quantile for the probability value p=[0,1].
double MRPTDLLIMPEXP normalCDF (double p)
 Evaluates the Gaussian cumulative density function.
double MRPTDLLIMPEXP chiSquareQuantile (double P, unsigned int dim=1)
 The "quantile" of the Chi-Square distribution, for dimension "dim" and probability 0<P<1 An aproximation from the Wilson-Hilferty transformation is used.
void MRPTDLLIMPEXP fft_real (vector_float &in_realData, vector_float &out_FFT_Re, vector_float &out_FFT_Im, vector_float &out_FFT_Mag)
 Computes the FFT of a 2^N-size vector of real numbers, and returns the Re+Im+Magnitude parts.
void MRPTDLLIMPEXP dft2_real (const CMatrixFloat &in_data, CMatrixFloat &out_real, CMatrixFloat &out_imag)
 Compute the 2D Discrete Fourier Transform (DFT) of a real matrix, returning the real and imaginary parts separately.
void MRPTDLLIMPEXP idft2_real (const CMatrixFloat &in_real, const CMatrixFloat &in_imag, CMatrixFloat &out_data)
 Compute the 2D inverse Discrete Fourier Transform (DFT).
void MRPTDLLIMPEXP dft2_complex (const CMatrixFloat &in_real, const CMatrixFloat &in_imag, CMatrixFloat &out_real, CMatrixFloat &out_imag)
 Compute the 2D Discrete Fourier Transform (DFT) of a complex matrix, returning the real and imaginary parts separately.
void MRPTDLLIMPEXP idft2_complex (const CMatrixFloat &in_real, const CMatrixFloat &in_imag, CMatrixFloat &out_real, CMatrixFloat &out_imag)
 Compute the 2D inverse Discrete Fourier Transform (DFT).
void MRPTDLLIMPEXP cross_correlation_FFT (const CMatrixFloat &A, const CMatrixFloat &B, CMatrixFloat &out_corr)
 Correlation of two matrixes using 2D FFT.
double MRPTDLLIMPEXP minimumDistanceFromPointToSegment (const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2, double &out_x, double &out_y)
 Computes the closest point from a given point to a segment, and returns that minimum distance.
double MRPTDLLIMPEXP minimumDistanceFromPointToSegment (const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2, float &out_x, float &out_y)
 Computes the closest point from a given point to a segment, and returns that minimum distance.
void MRPTDLLIMPEXP closestFromPointToSegment (const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2, double &out_x, double &out_y)
 Computes the closest point from a given point to a segment.
void MRPTDLLIMPEXP closestFromPointToLine (const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2, double &out_x, double &out_y)
 Computes the closest point from a given point to a (infinite) line.
double MRPTDLLIMPEXP closestSquareDistanceFromPointToLine (const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2)
 Returns the square distance from a point to a line.
double MRPTDLLIMPEXP distanceBetweenPoints (const double x1, const double y1, const double x2, const double y2)
 Returns the distance between 2 points in 2D.
double MRPTDLLIMPEXP distanceBetweenPoints (const double x1, const double y1, const double z1, const double x2, const double y2, const double z2)
 Returns the distance between 3 points in 3D.
double MRPTDLLIMPEXP distanceSqrBetweenPoints (const double x1, const double y1, const double x2, const double y2)
 Returns the square distance between 2 points in 2D.
double MRPTDLLIMPEXP distanceSqrBetweenPoints (const double x1, const double y1, const double z1, const double x2, const double y2, const double z2)
 Returns the square distance between 3 points in 3D.
bool MRPTDLLIMPEXP SegmentsIntersection (const double &x1, const double &y1, const double &x2, const double &y2, const double &x3, const double &y3, const double &x4, const double &y4, double &ix, double &iy)
 Returns the intersection point, and if it exists, between two segments.
bool MRPTDLLIMPEXP SegmentsIntersection (const double &x1, const double &y1, const double &x2, const double &y2, const double &x3, const double &y3, const double &x4, const double &y4, float &ix, float &iy)
 Returns the intersection point, and if it exists, between two segments.
bool MRPTDLLIMPEXP pointIntoPolygon2D (const double &px, const double &py, unsigned int polyEdges, const double *poly_xs, const double *poly_ys)
 Returns true if the 2D point (px,py) falls INTO the given polygon.
double MRPTDLLIMPEXP distancePointToPolygon2D (const double &px, const double &py, unsigned int polyEdges, const double *poly_xs, const double *poly_ys)
 Returns the closest distance of a given 2D point to a polygon, or "0" if the point is INTO the polygon or its perimeter.
bool MRPTDLLIMPEXP minDistBetweenLines (const double &p1_x, const double &p1_y, const double &p1_z, const double &p2_x, const double &p2_y, const double &p2_z, const double &p3_x, const double &p3_y, const double &p3_z, const double &p4_x, const double &p4_y, const double &p4_z, double &x, double &y, double &z, double &dist)
 Calculates the minimum distance between a pair of lines.
bool MRPTDLLIMPEXP RectanglesIntersection (const double &R1_x_min, const double &R1_x_max, const double &R1_y_min, const double &R1_y_max, const double &R2_x_min, const double &R2_x_max, const double &R2_y_min, const double &R2_y_max, const double &R2_pose_x, const double &R2_pose_y, const double &R2_pose_phi)
 Returns wether two rotated rectangles intersect.
template<class T >
CMatrixTemplateNumeric< T > generateAxisBaseFromDirection (T dx, T dy, T dz)
 Computes an axis base (a set of three 3D normal vectors) with the given vector being the first of them.
template<class T >
void crossProduct3D (T x0, T y0, T z0, T x1, T y1, T z1, T &x_out, T &y_out, T &z_out)
 Computes the cross product of two 3D vectors, returning a vector normal to both.
template<class T >
void crossProduct3D (const std::vector< T > &v0, const std::vector< T > &v1, std::vector< T > &v_out)
 Computes the cross product of two 3D vectors, returning a vector normal to both.
bool MRPTDLLIMPEXP loadVector (utils::CFileStream &f, std::vector< int > &d)
 Loads one row of a text file as a numerical std::vector.
bool MRPTDLLIMPEXP loadVector (utils::CFileStream &f, std::vector< double > &d)
 Loads one row of a text file as a numerical std::vector.
template<class T >
size_t countNonZero (const std::vector< T > &a)
 A template for counting how many elements in an array are non-Zero.
template<class T >
maximum (const std::vector< T > &v, unsigned int *maxIndex=NULL)
 Finds the maximum value (and the corresponding zero-based index) from a given vector.
template<class T >
norm_inf (const std::vector< T > &v, unsigned int *maxIndex=NULL)
 Compute the norm-infinite of a vector ($f[ ||{v}||_ $f]), ie the maximum absolute value of the elements.
template<class T >
norm (const std::vector< T > &v)
 Compute the 2-norm of the vector (the Euclidean distance to the origin).
template<class T >
minimum (const std::vector< T > &v, unsigned int *minIndex=NULL)
 Finds the maximum value (and the corresponding zero-based index) from a given vector.
template<class T >
void minimum_maximum (const std::vector< T > &v, T &out_min, T &out_max, unsigned int *minIndex=NULL, unsigned int *maxIndex=NULL)
 Compute the minimum and maximum of a vector at once.
template<class T >
double mean (const std::vector< T > &v)
 Computes the mean value of a vector.
template<class T >
sum (const std::vector< T > &v)
 Computes the sum of all the elements of a vector.
template<typename T , typename K >
void linspace (T first, T last, size_t count, std::vector< K > &out_vector)
 Generates an equidistant sequence of numbers given the first one, the last one and the desired number of points.
template<class T >
std::vector< T > 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.
template<class T >
std::vector< T > ones (size_t count)
 Generates a vector of all ones of the given length.
template<class T >
std::vector< T > zeros (size_t count)
 Generates a vector of all zeros of the given length.
template<class T >
void normalize (const std::vector< T > &v, std::vector< T > &out_v)
 Normalize a vector, such as its norm is the unity.
template<class T >
std::vector< T > cumsum (const std::vector< T > &v)
 Computes the cumulative sum of all the elements of a vector.
template<class T >
void cumsum (const std::vector< T > &v, std::vector< T > &out_cumsum)
 Computes the cumulative sum of all the elements of a vector, saving the result in a given vector.
template<class T >
double stddev (const std::vector< T > &v, bool unbiased=true)
 Computes the standard deviation of a vector.
template<class T >
void meanAndStd (const std::vector< T > &v, double &out_mean, double &out_std, bool unbiased=true)
 Computes the standard deviation of a vector.
template<class T >
void weightedHistogram (const std::vector< T > &values, const std::vector< T > &weights, float binWidth, std::vector< float > &out_binCenters, std::vector< float > &out_binValues)
 Computes the weighted histogram for a vector of values and their corresponding weights.
uint64_t MRPTDLLIMPEXP factorial64 (unsigned int n)
 Computes the factorial of an integer number and returns it as a 64-bit integer number.
double MRPTDLLIMPEXP 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).
template<class T >
void wrapTo2PiInPlace (T &a)
 Modifies the given angle to translate it into the [0,2pi[ range.
template<class T >
wrapTo2Pi (T a)
 Modifies the given angle to translate it into the [0,2pi[ range.
template<class T >
wrapToPi (T a)
 Modifies the given angle to translate it into the ]-pi,pi] range.
template<class T >
void wrapToPiInPlace (T &a)
 Modifies the given angle to translate it into the ]-pi,pi] range.
template<class T >
round2up (T val)
 Round up to the nearest power of two of a given number.
template<class T >
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, .
template<class T >
void chol (const CMatrixTemplateNumeric< T > &in, CMatrixTemplateNumeric< T > &out)
 Cholesky factorization: in = out' ยท out Given a positive-definite symmetric matrix, this routine constructs its Cholesky decomposition.
template<class T >
double correlate_matrix (const CMatrixTemplateNumeric< T > &a1, const CMatrixTemplateNumeric< T > &a2)
 Calculate the correlation between two matrices (by AJOGD @ JAN-2007).
template<class T >
void MRPTDLLIMPEXP qr_decomposition (CMatrixTemplateNumeric< T > &A, CMatrixTemplateNumeric< T > &R, CMatrixTemplateNumeric< T > &Q, CVectorTemplate< T > &c, int &sing)
 Matrix QR decomposition.
template<class T >
void MRPTDLLIMPEXP UpdateCholesky (CMatrixTemplateNumeric< T > &chol, CVectorTemplate< T > &r1Modification)
 If R = CHOL(A) is the original Cholesky factorization of A, then R1 = CHOLUPDATE(R,X) returns the upper triangular Cholesky factor of A + X*X', where X is a column vector of appropriate length.
void MRPTDLLIMPEXP computeEigenValues2x2 (const CMatrixFloat &in_matrix, float &min_eigenvalue, float &max_eigenvalue)
 Compute the two eigenvalues of a 2x2 matrix.
template<class T >
std::vector< T > Exp (const std::vector< T > &v)
 Computes the 'exp' of all the elements of a vector.
template<class T >
std::vector< T > Log (const std::vector< T > &v)
 Computes the 'log' of all the elements of a vector.
double MRPTDLLIMPEXP averageLogLikelihood (const vector_double &logLikelihoods)
 A numerically-stable method to compute average likelihood values with strongly different ranges (unweighted likelihoods: compute the arithmetic mean).
double MRPTDLLIMPEXP 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.
double MRPTDLLIMPEXP averageLogLikelihood (const vector_double &logWeights, const vector_double &logLikelihoods)
 A numerically-stable method to average likelihood values with strongly different ranges (weighted likelihoods).
std::string MRPTDLLIMPEXP MATLAB_plotCovariance2D (const CMatrixFloat &cov22, const CVectorFloat &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).
void MRPTDLLIMPEXP homogeneousMatrixInverse (const CMatrixDouble &M, CMatrixDouble &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.
template<class T >
size_t countCommonElements (const std::vector< T > &a, const std::vector< T > &b)
 Counts the number of elements that appear in both vectors (comparison through the == operator) It is assumed that no repeated elements appear within each of the vectors.
template<typename T >
void MRPTDLLIMPEXP estimateJacobian (const std::vector< T > &x, void(*functor)(const std::vector< T > &x, const std::vector< T > &y, std::vector< T > &out), const std::vector< T > &increments, const std::vector< T > &userParam, CMatrixTemplateNumeric< T > &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.
template<class T >
vector_double histogram (const std::vector< T > &v, double limit_min, double limit_max, size_t number_bins, bool do_normalization=false)
 Computes the normalized or normal histogram of a sequence of numbers given the number of bins and the limits.
template<typename T , typename At , size_t N>
std::vector< T > & 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).
template<class T >
std::vector< T > Abs (const std::vector< T > &a)
 Absolute value of a vector.
void unwrap2PiSequence (vector_double &x)
 Modify a sequence of angle values such as no consecutive values have a jump larger than PI in absolute value.
template<class T >
T MRPTDLLIMPEXP mahalanobisDistance (const std::vector< T > &X, const std::vector< T > &MU, const CMatrixTemplateNumeric< T > &COV_inv)
 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) } \]

.

template<class T >
std::ostream & operator<< (std::ostream &out, const std::vector< T > &d)
 A template function for printing out the contents of a std::vector variable.
template<class T >
std::ostream & operator<< (std::ostream &out, std::vector< T > *d)
 A template function for printing out the contents of a std::vector variable.
template<class T >
std::vector< T > operator+ (const std::vector< T > &a, T b)
 A template function for the operator + between a scalar and a std::vector.
template<class T >
std::vector< T > operator- (const std::vector< T > &a, T b)
 A template function for the operator - between a scalar and a std::vector.
template<class T >
std::vector< T > operator* (const std::vector< T > &a, T b)
 A template function for the operator * between a scalar and a std::vector.
template<class T >
std::vector< T > operator/ (const std::vector< T > &a, T b)
 A template function for dividing a std::vector by a scalar number.
template<class T >
std::vector< T > operator+ (const std::vector< T > &a, const std::vector< T > &b)
 A template function for adding std::vector's having the same number of elements.
template<class T >
std::vector< T > operator- (const std::vector< T > &a, const std::vector< T > &b)
 A template function for substracting std::vector's having the same number of elements.
template<class T >
std::vector< T > operator* (const std::vector< T > &a, const std::vector< T > &b)
 A template function for scalar product (element by element, like .
template<class T >
std::vector< T > operator/ (const std::vector< T > &a, const std::vector< T > &b)
 A template function for scalar division (element by element, like .
template<class T >
void operator+= (std::vector< T > &a, const std::vector< T > &b)
 A template for the operator += applied to std::vector's having the same number of elements.
template<class T >
void operator-= (std::vector< T > &a, const std::vector< T > &b)
 A template for the operator -= applied to std::vector's having the same number of elements.
template<class T >
void operator*= (std::vector< T > &a, const std::vector< T > &b)
 A template for the operator *= applied to std::vector's having the same number of elements.
template<class T >
void operator/= (std::vector< T > &a, const std::vector< T > &b)
 A template for the operator /= applied to std::vector's having the same number of elements.
template<class T >
void operator+= (std::vector< T > &a, T b)
 A template for the operator += applied to a std::vector and a scalar.
template<class T >
void operator-= (std::vector< T > &a, T b)
 A template for the operator -= applied to a std::vector and a scalar.
template<class T >
void operator*= (std::vector< T > &a, T b)
 A template for the operator *= applied to a std::vector and a scalar.
template<class T >
void operator/= (std::vector< T > &a, T b)
 A template for the operator /= applied to a std::vector and a scalar.
Interpolation functions
template<class T >
interpolate (const T &x, const std::vector< T > &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".
double MRPTDLLIMPEXP 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).
double MRPTDLLIMPEXP spline (const double t, const std::vector< double > &x, const std::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).
double MRPTDLLIMPEXP leastSquareLinearFit (const double t, const std::vector< double > &x, const std::vector< double > &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".
void MRPTDLLIMPEXP leastSquareLinearFit (const std::vector< double > &ts, std::vector< double > &outs, const std::vector< double > &x, const std::vector< double > &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".


Detailed Description

This base provides a set of functions for maths stuff.


Typedef Documentation

The default name for the LM class is an instantiation for "double".

Definition at line 84 of file CLevenbergMarquardt.h.

Declares a matrix of booleans (non serializable).

See also:
CMatrixDouble, CMatrixFloat, CMatrixB

Definition at line 819 of file CMatrixTemplateNumeric.h.

Declares a matrix of double numbers (non serializable).

For a serializable version, use math::CMatrixD

See also:
CMatrixFloat, CMatrix, CMatrixD

Definition at line 809 of file CMatrixTemplateNumeric.h.

Declares a matrix of float numbers (non serializable).

For a serializable version, use math::CMatrix

See also:
CMatrixDouble, CMatrix, CMatrixD

Definition at line 803 of file CMatrixTemplateNumeric.h.

Declares a matrix of "long doubles" (non serializable), or of "doubles" if the compiler does not support "long double".

See also:
CMatrixDouble, CMatrixFloat

Definition at line 830 of file CMatrixTemplateNumeric.h.

Declares a matrix of unsigned ints (non serializable).

See also:
CMatrixDouble, CMatrixFloat

Definition at line 814 of file CMatrixTemplateNumeric.h.

Declares a vector of double elements.

See also:
CVectorFloat

Definition at line 458 of file CVectorTemplate.h.

Declares a vector of float elements.

See also:
CVectorDouble

Definition at line 453 of file CVectorTemplate.h.


Enumeration Type Documentation

Selection of the number format in CMatrixTemplateNumeric::saveToTextFile.

Enumerator:
MATRIX_FORMAT_ENG  engineering format 'e'
MATRIX_FORMAT_FIXED  fixed floating point 'f'
MATRIX_FORMAT_INT  intergers 'i'

Definition at line 45 of file CMatrixTemplateNumeric.h.


Function Documentation

template<class T >
std::vector<T> mrpt::math::Abs ( const std::vector< T > &  a  )  [inline]

Absolute value of a vector.

Definition at line 796 of file math/utils.h.

double MRPTDLLIMPEXP 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).

This method implements this equation:

\[ return = \log \left( \frac{1}{\sum_i e^{lw_i}} \sum_i e^{lw_i} e^{ll_i} \right) \]

See also the tutorial page.

double MRPTDLLIMPEXP 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).

This method implements this equation:

\[ return = - \log N + \log \sum_{i=1}^N e^{ll_i-ll_{max}} + ll_{max} \]

See also the tutorial page.

double MRPTDLLIMPEXP 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.

double MRPTDLLIMPEXP mrpt::math::chiSquareQuantile ( double  P,
unsigned int  dim = 1 
)

The "quantile" of the Chi-Square distribution, for dimension "dim" and probability 0<P<1 An aproximation from the Wilson-Hilferty transformation is used.

template<class T >
void mrpt::math::chol ( const CMatrixTemplateNumeric< T > &  in,
CMatrixTemplateNumeric< T > &  out 
) [inline]

Cholesky factorization: in = out' ยท out Given a positive-definite symmetric matrix, this routine constructs its Cholesky decomposition.

On input, only the upper triangle of "IN" need be given; it is not modified. The Cholesky factorization is returned in "out" in the upper triangle. (by AJOGD @ JAN-2007)

Definition at line 482 of file math/utils.h.

References mrpt::math::CMatrixTemplate< T >::getColCount(), mrpt::math::CMatrixTemplate< T >::getRowCount(), mrpt::math::CMatrixTemplateNumeric< T >::setSize(), sum(), and THROW_EXCEPTION.

void MRPTDLLIMPEXP mrpt::math::closestFromPointToLine ( const double &  Px,
const double &  Py,
const double &  x1,
const double &  y1,
const double &  x2,
const double &  y2,
double &  out_x,
double &  out_y 
)

Computes the closest point from a given point to a (infinite) line.

See also:
closestFromPointToSegment

void MRPTDLLIMPEXP mrpt::math::closestFromPointToSegment ( const double &  Px,
const double &  Py,
const double &  x1,
const double &  y1,
const double &  x2,
const double &  y2,
double &  out_x,
double &  out_y 
)

Computes the closest point from a given point to a segment.

See also:
closestFromPointToLine

double MRPTDLLIMPEXP mrpt::math::closestSquareDistanceFromPointToLine ( const double &  Px,
const double &  Py,
const double &  x1,
const double &  y1,
const double &  x2,
const double &  y2 
)

Returns the square distance from a point to a line.

void MRPTDLLIMPEXP mrpt::math::computeEigenValues2x2 ( const CMatrixFloat &  in_matrix,
float &  min_eigenvalue,
float &  max_eigenvalue 
)

Compute the two eigenvalues of a 2x2 matrix.

Parameters:
in_matrx The 2x2 input matrix.
min_eigenvalue (out) The minimum eigenvalue of the matrix.
max_eigenvalue (out) The maximum eigenvalue of the matrix. by FAMD, MAR-2007

template<class T >
double mrpt::math::correlate_matrix ( const CMatrixTemplateNumeric< T > &  a1,
const CMatrixTemplateNumeric< T > &  a2 
) [inline]

Calculate the correlation between two matrices (by AJOGD @ JAN-2007).

Definition at line 518 of file math/utils.h.

References mrpt::math::CMatrixTemplate< T >::getColCount(), mrpt::math::CMatrixTemplate< T >::getRowCount(), and THROW_EXCEPTION.

template<class T >
size_t mrpt::math::countCommonElements ( const std::vector< T > &  a,
const std::vector< T > &  b 
) [inline]

Counts the number of elements that appear in both vectors (comparison through the == operator) It is assumed that no repeated elements appear within each of the vectors.

Definition at line 684 of file math/utils.h.

template<class T >
size_t mrpt::math::countNonZero ( const std::vector< T > &  a  )  [inline]

A template for counting how many elements in an array are non-Zero.

Definition at line 82 of file math/utils.h.

void MRPTDLLIMPEXP mrpt::math::cross_correlation_FFT ( const CMatrixFloat &  A,
const CMatrixFloat &  B,
CMatrixFloat &  out_corr 
)

Correlation of two matrixes using 2D FFT.

template<class T >
void mrpt::math::crossProduct3D ( const std::vector< T > &  v0,
const std::vector< T > &  v1,
std::vector< T > &  v_out 
) [inline]

Computes the cross product of two 3D vectors, returning a vector normal to both.

It uses the simple implementation:

\[ v_out = \left( \begin{array}{c c c} \hat{i} ~ \hat{j} ~ \hat{k} \\ x0 ~ y0 ~ z0 \\ x1 ~ y1 ~ z1 \\ \end{array} \right) \]

Definition at line 282 of file geometry.h.

References ASSERT_.

template<class T >
void mrpt::math::crossProduct3D ( x0,
y0,
z0,
x1,
y1,
z1,
T &  x_out,
T &  y_out,
T &  z_out 
) [inline]

Computes the cross product of two 3D vectors, returning a vector normal to both.

It uses the simple implementation:

\[ v_out = \left( \begin{array}{c c c} \hat{i} ~ \hat{j} ~ \hat{k} \\ x0 ~ y0 ~ z0 \\ x1 ~ y1 ~ z1 \\ \end{array} \right) \]

Definition at line 260 of file geometry.h.

Referenced by generateAxisBaseFromDirection().

template<class T >
void mrpt::math::cumsum ( const std::vector< T > &  v,
std::vector< T > &  out_cumsum 
) [inline]

Computes the cumulative sum of all the elements of a vector, saving the result in a given vector.

See also:
sum

Definition at line 276 of file math/utils.h.

template<class T >
std::vector<T> mrpt::math::cumsum ( const std::vector< T > &  v  )  [inline]

Computes the cumulative sum of all the elements of a vector.

See also:
sum

Definition at line 261 of file math/utils.h.

void MRPTDLLIMPEXP mrpt::math::dft2_complex ( const CMatrixFloat &  in_real,
const CMatrixFloat &  in_imag,
CMatrixFloat &  out_real,
CMatrixFloat &  out_imag 
)

Compute the 2D Discrete Fourier Transform (DFT) of a complex matrix, returning the real and imaginary parts separately.

Parameters:
in_real The N_1xN_2 matrix with the real part.
in_imag The N_1xN_2 matrix with the imaginary part.
out_real The N_1xN_2 output matrix which will store the real values (user has not to initialize the size of this matrix).
out_imag The N_1xN_2 output matrix which will store the imaginary values (user has not to initialize the size of this matrix). If the dimensions of the matrix are powers of two, the fast fourier transform (FFT) is used instead of the general algorithm.
See also:
fft_real, idft2_complex,dft2_real

void MRPTDLLIMPEXP mrpt::math::dft2_real ( const CMatrixFloat &  in_data,
CMatrixFloat &  out_real,
CMatrixFloat &  out_imag 
)

Compute the 2D Discrete Fourier Transform (DFT) of a real matrix, returning the real and imaginary parts separately.

Parameters:
in_data The N_1xN_2 matrix.
out_real The N_1xN_2 output matrix which will store the real values (user has not to initialize the size of this matrix).
out_imag The N_1xN_2 output matrix which will store the imaginary values (user has not to initialize the size of this matrix).
See also:
fft_real, ifft2_read, fft2_complex If the dimensions of the matrix are powers of two, the fast fourier transform (FFT) is used instead of the general algorithm.

double MRPTDLLIMPEXP mrpt::math::distanceBetweenPoints ( const double  x1,
const double  y1,
const double  z1,
const double  x2,
const double  y2,
const double  z2 
)

Returns the distance between 3 points in 3D.

double MRPTDLLIMPEXP mrpt::math::distanceBetweenPoints ( const double  x1,
const double  y1,
const double  x2,
const double  y2 
)

Returns the distance between 2 points in 2D.

double MRPTDLLIMPEXP mrpt::math::distancePointToPolygon2D ( const double &  px,
const double &  py,
unsigned int  polyEdges,
const double *  poly_xs,
const double *  poly_ys 
)

Returns the closest distance of a given 2D point to a polygon, or "0" if the point is INTO the polygon or its perimeter.

double MRPTDLLIMPEXP mrpt::math::distanceSqrBetweenPoints ( const double  x1,
const double  y1,
const double  z1,
const double  x2,
const double  y2,
const double  z2 
)

Returns the square distance between 3 points in 3D.

double MRPTDLLIMPEXP mrpt::math::distanceSqrBetweenPoints ( const double  x1,
const double  y1,
const double  x2,
const double  y2 
)

Returns the square distance between 2 points in 2D.

double MRPTDLLIMPEXP mrpt::math::erf ( double  x  ) 

The error function of a Normal distribution.

double MRPTDLLIMPEXP mrpt::math::erfc ( double  x  ) 

The complementary error function of a Normal distribution.

template<typename T >
void MRPTDLLIMPEXP mrpt::math::estimateJacobian ( const std::vector< T > &  x,
void(*)(const std::vector< T > &x, const std::vector< T > &y, std::vector< T > &out)  functor,
const std::vector< T > &  increments,
const std::vector< T > &  userParam,
CMatrixTemplateNumeric< T > &  out_Jacobian 
) [inline]

Estimate the Jacobian of a multi-dimensional function around a point "x", using finite differences of a given size in each input dimension.

template<class T >
std::vector<T> mrpt::math::Exp ( const std::vector< T > &  v  )  [inline]

Computes the 'exp' of all the elements of a vector.

See also:
math::Log

Definition at line 599 of file math/utils.h.

double MRPTDLLIMPEXP 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).

uint64_t MRPTDLLIMPEXP mrpt::math::factorial64 ( unsigned int  n  ) 

Computes the factorial of an integer number and returns it as a 64-bit integer number.

void MRPTDLLIMPEXP mrpt::math::fft_real ( vector_float &  in_realData,
vector_float &  out_FFT_Re,
vector_float &  out_FFT_Im,
vector_float &  out_FFT_Mag 
)

Computes the FFT of a 2^N-size vector of real numbers, and returns the Re+Im+Magnitude parts.

See also:
fft2_real

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::generateAxisBaseFromDirection ( dx,
dy,
dz 
) [inline]

Computes an axis base (a set of three 3D normal vectors) with the given vector being the first of them.

NOTE: Make sure of passing all floats or doubles and that the template of the receiving matrix is of the same type!

If $ d = [ dx ~ dy ~ dz ] $ is the input vector, then this function returns a matrix $ M $ such as:

\[ M = \left( \begin{array}{c c c} v^1_x ~ v^2_x ~ v^3_x \\ v^1_y ~ v^2_y ~ v^3_y \\ v^1_z ~ v^2_z ~ v^3_z \end{array} \right) \]

And the three normal vectors are computed as:

\[ v^1 = \frac{d}{|d|} \]

If (dx!=0 or dy!=0):

\[ v^2 = \frac{[-dy ~ dx ~ 0 ]}{\sqrt{dx^2+dy^2}} \]

otherwise (the direction vector is vertical):

\[ v^2 = [1 ~ 0 ~ 0] \]

And finally, the third vector is the cross product of the others:

\[ v^3 = v^1 \times v^2 \]

Returns:
The 3x3 matrix (CMatrixTemplateNumeric<T>), containing one vector per column. Throws an std::exception on invalid input (i.e. null direction vector)
(JLB @ 18-SEP-2007)

Definition at line 205 of file geometry.h.

References crossProduct3D(), MRPT_TRY_END, MRPT_TRY_START, mrpt::utils::square(), and THROW_EXCEPTION.

template<class T >
vector_double mrpt::math::histogram ( const std::vector< T > &  v,
double  limit_min,
double  limit_max,
size_t  number_bins,
bool  do_normalization = false 
) [inline]

Computes the normalized or normal histogram of a sequence of numbers given the number of bins and the limits.

Definition at line 766 of file math/utils.h.

References mrpt::math::CHistogram::add(), mrpt::math::CHistogram::getBinCount(), and mrpt::math::CHistogram::getBinRatio().

void MRPTDLLIMPEXP mrpt::math::homogeneousMatrixInverse ( const CMatrixDouble &  M,
CMatrixDouble &  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.

void MRPTDLLIMPEXP mrpt::math::idft2_complex ( const CMatrixFloat &  in_real,
const CMatrixFloat &  in_imag,
CMatrixFloat &  out_real,
CMatrixFloat &  out_imag 
)

Compute the 2D inverse Discrete Fourier Transform (DFT).

Parameters:
in_real The N_1xN_2 input matrix with real values, where both dimensions MUST BE powers of 2.
in_imag The N_1xN_2 input matrix with imaginary values, where both dimensions MUST BE powers of 2.
out_real The N_1xN_2 output matrix for real part (user has not to initialize the size of this matrix).
out_imag The N_1xN_2 output matrix for imaginary part (user has not to initialize the size of this matrix).
See also:
fft_real, dft2_real,dft2_complex If the dimensions of the matrix are powers of two, the fast fourier transform (FFT) is used instead of the general algorithm.

void MRPTDLLIMPEXP mrpt::math::idft2_real ( const CMatrixFloat &  in_real,
const CMatrixFloat &  in_imag,
CMatrixFloat &  out_data 
)

Compute the 2D inverse Discrete Fourier Transform (DFT).

Parameters:
in_real The N_1xN_2 input matrix with real values.
in_imag The N_1xN_2 input matrix with imaginary values.
out_data The N_1xN_2 output matrix (user has not to initialize the size of this matrix). Note that the real and imaginary parts of the FFT will NOT be checked to assure that they represent the transformation of purely real data. If the dimensions of the matrix are powers of two, the fast fourier transform (FFT) is used instead of the general algorithm.
See also:
fft_real, fft2_real

template<class T >
T mrpt::math::interpolate ( const T &  x,
const std::vector< T > &  ys,
const T &  x0,
const T &  x1 
) [inline]

Interpolate a data sequence "ys" ranging from "x0" to "x1" (equally spaced), to obtain the approximation of the sequence at the point "x".

If the point "x" is out of the range [x0,x1], the closest extreme "ys" value is returned.

See also:
spline, interpolate2points

Definition at line 718 of file math/utils.h.

References ASSERT_, MRPT_TRY_END, and MRPT_TRY_START.

double MRPTDLLIMPEXP 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).

If wrap2pi is true, output is wrapped to ]-pi,pi] (It is assumed that input "y" values already are in the correct range).

See also:
spline, interpolate, leastSquareLinearFit

bool MRPTDLLIMPEXP mrpt::math::isFinite ( double  v  ) 

Returns true if value is finite.

bool MRPTDLLIMPEXP mrpt::math::isFinite ( float  v  ) 

Returns true if value is finite.

bool MRPTDLLIMPEXP mrpt::math::isNan ( double  v  ) 

Returns true if value is Not-a-number (NAN).

bool MRPTDLLIMPEXP mrpt::math::isNan ( float  v  ) 

Returns true if value is Not-a-number (NAN).

void MRPTDLLIMPEXP mrpt::math::leastSquareLinearFit ( const std::vector< double > &  ts,
std::vector< double > &  outs,
const std::vector< double > &  x,
const std::vector< double > &  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".

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).

double MRPTDLLIMPEXP mrpt::math::leastSquareLinearFit ( const double  t,
const std::vector< double > &  x,
const std::vector< double > &  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".

The vectors x and y must have size >=2, and all values of "x" must be different. 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).

See also:
spline

template<class T >
std::vector<T> mrpt::math::linspace ( first,
last,
size_t  count 
) [inline]

Generates an equidistant sequence of numbers given the first one, the last one and the desired number of points.

Definition at line 215 of file math/utils.h.

References linspace().

template<typename T , typename K >
void mrpt::math::linspace ( first,
last,
size_t  count,
std::vector< K > &  out_vector 
) [inline]

Generates an equidistant sequence of numbers given the first one, the last one and the desired number of points.

Definition at line 196 of file math/utils.h.

Referenced by linspace().

template<typename T , typename At , size_t N>
std::vector<T>& mrpt::math::loadVector ( std::vector< T > &  v,
At(&)  theArray[N] 
) [inline]

Assignment operator for initializing a std::vector from a C array (The vector will be automatically set to the correct size).

         vector_double  v;
  const double numbers[] = { 1,2,3,5,6,7,8,9,10 };
  loadVector( v, numbers );
Note:
This operator performs the appropiate type castings, if required.

Definition at line 785 of file math/utils.h.

References MRPT_COMPILE_TIME_ASSERT.

bool MRPTDLLIMPEXP mrpt::math::loadVector ( utils::CFileStream &  f,
std::vector< double > &  d 
)

Loads one row of a text file as a numerical std::vector.

Returns:
false on EOF or invalid format. The body of the function is implemented in MATH.cpp

bool MRPTDLLIMPEXP mrpt::math::loadVector ( utils::CFileStream &  f,
std::vector< int > &  d 
)

Loads one row of a text file as a numerical std::vector.

Returns:
false on EOF or invalid format. The body of the function is implemented in MATH.cpp

template<class T >
std::vector<T> mrpt::math::Log ( const std::vector< T > &  v  )  [inline]

Computes the 'log' of all the elements of a vector.

See also:
math::Exp

Definition at line 612 of file math/utils.h.

template<class T >
T MRPTDLLIMPEXP mrpt::math::mahalanobisDistance ( const std::vector< T > &  X,
const std::vector< T > &  MU,
const CMatrixTemplateNumeric< T > &  COV_inv 
) [inline]

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) } \]

.

std::string MRPTDLLIMPEXP mrpt::math::MATLAB_plotCovariance2D ( const CMatrixFloat &  cov22,
const CVectorFloat &  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).

Generates a string with the MATLAB commands required to plot an confidence interval (ellipse) for a 2D Gaussian ('double' version).

Parameters:
cov22 The 2x2 covariance matrix
mean The 2-length vector with the mean
stdCount How many "quantiles" to get into the area of the ellipse: 2: 95%, 3:99.97%,...
style A matlab style string, for colors, line styles,...
nEllipsePoints The number of points in the ellipse to generate
cov22 The 2x2 covariance matrix
mean The 2-length vector with the mean
stdCount How many "quantiles" to get into the area of the ellipse: 2: 95%, 3:99.97%,...
style A matlab style string, for colors, line styles,...
nEllipsePoints The number of points in the ellipse to generate

template<class T >
T mrpt::math::maximum ( const std::vector< T > &  v,
unsigned int *  maxIndex = NULL 
) [inline]

Finds the maximum value (and the corresponding zero-based index) from a given vector.

Definition at line 93 of file math/utils.h.

Referenced by weightedHistogram().

template<class T >
double mrpt::math::mean ( const std::vector< T > &  v  )  [inline]

Computes the mean value of a vector.

See also:
math::stddev,math::meanAndStd

Definition at line 178 of file math/utils.h.

Referenced by mrpt::random::matrixRandomNormal(), and mrpt::random::vectorRandomNormal().

template<class T >
void mrpt::math::meanAndStd ( const std::vector< T > &  v,
double &  out_mean,
double &  out_std,
bool  unbiased = true 
) [inline]

Computes the standard deviation of a vector.

Parameters:
v The set of data
out_mean The output for the estimated mean
out_std The output for the estimated standard deviation
unbiased If set to true or false the std is normalized by "N-1" or "N", respectively.
See also:
math::mean,math::stddev

Definition at line 319 of file math/utils.h.

References mrpt::utils::square().

bool MRPTDLLIMPEXP mrpt::math::minDistBetweenLines ( const double &  p1_x,
const double &  p1_y,
const double &  p1_z,
const double &  p2_x,
const double &  p2_y,
const double &  p2_z,
const double &  p3_x,
const double &  p3_y,
const double &  p3_z,
const double &  p4_x,
const double &  p4_y,
const double &  p4_z,
double &  x,
double &  y,
double &  z,
double &  dist 
)

Calculates the minimum distance between a pair of lines.

The lines are given by:

  • Line 1 = P1 + f (P2-P1)
  • Line 2 = P3 + f (P4-P3) The Euclidean distance is returned in "dist", and the mid point between the lines in (x,y,z)
    Returns:
    It returns false if there is no solution, i.e. lines are (almost, up to EPS) paralel.

template<class T >
T mrpt::math::minimum ( const std::vector< T > &  v,
unsigned int *  minIndex = NULL 
) [inline]

Finds the maximum value (and the corresponding zero-based index) from a given vector.

See also:
maximum, minimum_maximum

Definition at line 138 of file math/utils.h.

Referenced by weightedHistogram().

template<class T >
void mrpt::math::minimum_maximum ( const std::vector< T > &  v,
T &  out_min,
T &  out_max,
unsigned int *  minIndex = NULL,
unsigned int *  maxIndex = NULL 
) [inline]

Compute the minimum and maximum of a vector at once.

See also:
maximum, minimum

Definition at line 149 of file math/utils.h.

double MRPTDLLIMPEXP mrpt::math::minimumDistanceFromPointToSegment ( const double &  Px,
const double &  Py,
const double &  x1,
const double &  y1,
const double &  x2,
const double &  y2,
float &  out_x,
float &  out_y 
)

Computes the closest point from a given point to a segment, and returns that minimum distance.

double MRPTDLLIMPEXP mrpt::math::minimumDistanceFromPointToSegment ( const double &  Px,
const double &  Py,
const double &  x1,
const double &  y1,
const double &  x2,
const double &  y2,
double &  out_x,
double &  out_y 
)

Computes the closest point from a given point to a segment, and returns that minimum distance.

template<class T >
T mrpt::math::norm ( const std::vector< T > &  v  )  [inline]

Compute the 2-norm of the vector (the Euclidean distance to the origin).

Definition at line 125 of file math/utils.h.

References mrpt::utils::square().

template<class T >
T mrpt::math::norm_inf ( const std::vector< T > &  v,
unsigned int *  maxIndex = NULL 
) [inline]

Compute the norm-infinite of a vector ($f[ ||{v}||_ $f]), ie the maximum absolute value of the elements.

Definition at line 103 of file math/utils.h.

double MRPTDLLIMPEXP mrpt::math::normalCDF ( double  p  ) 

Evaluates the Gaussian cumulative density function.

The employed approximation is that from W. J. Cody freely available in http://www.netlib.org/specfun/erf

template<class T >
void mrpt::math::normalize ( const std::vector< T > &  v,
std::vector< T > &  out_v 
) [inline]

Normalize a vector, such as its norm is the unity.

If the vector has a null norm, the output is a null vector.

Definition at line 240 of file math/utils.h.

References mrpt::utils::square().

template<class T >
T mrpt::math::normalPDF ( const CMatrixTemplateNumeric< T > &  x,
const CMatrixTemplateNumeric< T > &  mu,
const CMatrixTemplateNumeric< T > &  cov 
) [inline]

Evaluates the multivariate normal (Gaussian) distribution at a given point "x" ("x" and "mu" can be 1xN or Nx1 matrixes).

Definition at line 49 of file distributions.h.

References mrpt::math::CMatrixTemplateNumeric< T >::det(), mrpt::math::CMatrixTemplate< T >::getRowCount(), mrpt::math::CMatrixTemplateNumeric< T >::inv(), M_2PI, MRPT_TRY_END, and MRPT_TRY_START.

double MRPTDLLIMPEXP mrpt::math::normalPDF ( double  x,
double  mu,
double  std 
)

Evaluates the univariate normal (Gaussian) distribution at a given point "x".

double MRPTDLLIMPEXP mrpt::math::normalQuantile ( double  p  ) 

Evaluates the Gaussian distribution quantile for the probability value p=[0,1].

The employed approximation is that from Peter J. Acklam (pjacklam@online.no), freely available in http://home.online.no/~pjacklam.

template<class T >
std::vector<T> mrpt::math::ones ( size_t  count  )  [inline]

Generates a vector of all ones of the given length.

Definition at line 224 of file math/utils.h.

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::operator! ( const CMatrixTemplateNumeric< T > &  m  )  [inline]

Unary inversion operator.

Definition at line 784 of file CMatrixTemplateNumeric.h.

References mrpt::math::CMatrixTemplateNumeric< T >::inv().

template<class T >
bool mrpt::math::operator!= ( const CMatrixTemplateNumeric< T > &  m1,
const CMatrixTemplateNumeric< T > &  m2 
) [inline]

logical no-equal-to operator

Definition at line 666 of file CMatrixTemplateNumeric.h.

template<class T >
std::vector<T> mrpt::math::operator* ( const std::vector< T > &  a,
const std::vector< T > &  b 
) [inline]

A template function for scalar product (element by element, like .

* in MATLAB) of std::vector's having the same number of elements.

Definition at line 166 of file vector_ops.h.

References ASSERT_.

Referenced by mrpt::slam::CRawlogXXL::const_iterator::getType(), and mrpt::slam::CRawlogXXL::iterator::getType().

template<class T >
std::vector<T> mrpt::math::operator* ( const std::vector< T > &  a,
b 
) [inline]

A template function for the operator * between a scalar and a std::vector.

Definition at line 99 of file vector_ops.h.

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::operator* ( const CMatrixTemplateNumeric< T > &  m1,
const CVectorTemplate< T > &  m2 
) [inline]

Binary matrix multiplication operator, with one matrix being NxM and the second being a column matrix Mx1.

Definition at line 724 of file CMatrixTemplateNumeric.h.

References mrpt::math::CMatrixTemplate< T >::getRowCount().

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::operator* ( const CMatrixTemplateNumeric< T > &  m1,
const CMatrixTemplateNumeric< T > &  m2 
) [inline]

binary matrix multiplication operator

Definition at line 714 of file CMatrixTemplateNumeric.h.

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::operator* ( const T &  no,
const CMatrixTemplateNumeric< T > &  m 
) [inline]

binary scalar multiplication operator

Definition at line 704 of file CMatrixTemplateNumeric.h.

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::operator* ( const CMatrixTemplateNumeric< T > &  m,
const T &  no 
) [inline]

binary scalar multiplication operator

Definition at line 694 of file CMatrixTemplateNumeric.h.

template<class T >
void mrpt::math::operator*= ( std::vector< T > &  a,
b 
) [inline]

A template for the operator *= applied to a std::vector and a scalar.

Definition at line 264 of file vector_ops.h.

template<class T >
void mrpt::math::operator*= ( std::vector< T > &  a,
const std::vector< T > &  b 
) [inline]

A template for the operator *= applied to std::vector's having the same number of elements.

Definition at line 216 of file vector_ops.h.

References ASSERT_.

template<class T >
std::vector<T> mrpt::math::operator+ ( const std::vector< T > &  a,
const std::vector< T > &  b 
) [inline]

A template function for adding std::vector's having the same number of elements.

Definition at line 132 of file vector_ops.h.

References ASSERT_.

template<class T >
std::vector<T> mrpt::math::operator+ ( const std::vector< T > &  a,
b 
) [inline]

A template function for the operator + between a scalar and a std::vector.

Definition at line 69 of file vector_ops.h.

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::operator+ ( const CMatrixTemplateNumeric< T > &  m1,
const CMatrixTemplateNumeric< T > &  m2 
) [inline]

binary addition operator

Definition at line 674 of file CMatrixTemplateNumeric.h.

template<class T >
void mrpt::math::operator+= ( std::vector< T > &  a,
b 
) [inline]

A template for the operator += applied to a std::vector and a scalar.

Definition at line 248 of file vector_ops.h.

template<class T >
void mrpt::math::operator+= ( std::vector< T > &  a,
const std::vector< T > &  b 
) [inline]

A template for the operator += applied to std::vector's having the same number of elements.

Definition at line 188 of file vector_ops.h.

References ASSERT_.

template<class T >
std::vector<T> mrpt::math::operator- ( const std::vector< T > &  a,
const std::vector< T > &  b 
) [inline]

A template function for substracting std::vector's having the same number of elements.

Definition at line 149 of file vector_ops.h.

References ASSERT_.

template<class T >
std::vector<T> mrpt::math::operator- ( const std::vector< T > &  a,
b 
) [inline]

A template function for the operator - between a scalar and a std::vector.

Definition at line 84 of file vector_ops.h.

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::operator- ( const CMatrixTemplateNumeric< T > &  m1,
const CMatrixTemplateNumeric< T > &  m2 
) [inline]

binary subtraction operator

Definition at line 684 of file CMatrixTemplateNumeric.h.

template<class T >
void mrpt::math::operator-= ( std::vector< T > &  a,
b 
) [inline]

A template for the operator -= applied to a std::vector and a scalar.

Definition at line 256 of file vector_ops.h.

template<class T >
void mrpt::math::operator-= ( std::vector< T > &  a,
const std::vector< T > &  b 
) [inline]

A template for the operator -= applied to std::vector's having the same number of elements.

Definition at line 202 of file vector_ops.h.

References ASSERT_.

template<class T >
std::vector<T> mrpt::math::operator/ ( const std::vector< T > &  a,
const std::vector< T > &  b 
) [inline]

A template function for scalar division (element by element, like .

/ in MATLAB) of std::vector's having the same number of elements.

Definition at line 177 of file vector_ops.h.

References ASSERT_.

template<class T >
std::vector<T> mrpt::math::operator/ ( const std::vector< T > &  a,
b 
) [inline]

A template function for dividing a std::vector by a scalar number.

Definition at line 114 of file vector_ops.h.

References THROW_EXCEPTION.

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::operator/ ( const CMatrixTemplateNumeric< T > &  m1,
const CMatrixTemplateNumeric< T > &  m2 
) [inline]

binary matrix division operator

Definition at line 750 of file CMatrixTemplateNumeric.h.

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::operator/ ( const T &  no,
const CMatrixTemplateNumeric< T > &  m 
) [inline]

binary scalar division operator

Definition at line 742 of file CMatrixTemplateNumeric.h.

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::operator/ ( const CMatrixTemplateNumeric< T > &  m,
const T &  no 
) [inline]

binary scalar division operator

Definition at line 734 of file CMatrixTemplateNumeric.h.

template<class T >
void mrpt::math::operator/= ( std::vector< T > &  a,
b 
) [inline]

A template for the operator /= applied to a std::vector and a scalar.

Definition at line 272 of file vector_ops.h.

References THROW_EXCEPTION.

template<class T >
void mrpt::math::operator/= ( std::vector< T > &  a,
const std::vector< T > &  b 
) [inline]

A template for the operator /= applied to std::vector's having the same number of elements.

Definition at line 230 of file vector_ops.h.

References ASSERT_, and THROW_EXCEPTION.

template<class T >
std::ostream& mrpt::math::operator<< ( std::ostream &  out,
std::vector< T > *  d 
) [inline]

A template function for printing out the contents of a std::vector variable.

Definition at line 57 of file vector_ops.h.

template<class T >
std::ostream& mrpt::math::operator<< ( std::ostream &  out,
const std::vector< T > &  d 
) [inline]

A template function for printing out the contents of a std::vector variable.

Definition at line 46 of file vector_ops.h.

template<class T >
std::ostream& mrpt::math::operator<< ( std::ostream &  ostrm,
const CMatrixTemplate< T > &  m 
) [inline]

Textual output stream function.

Use only for text output, for example: "std::cout << mat;"

Definition at line 823 of file CMatrixTemplate.h.

template<class T >
bool mrpt::math::operator== ( const CMatrixTemplateNumeric< T > &  m1,
const CMatrixTemplateNumeric< T > &  m2 
) [inline]

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::operator^ ( const CMatrixTemplateNumeric< T > &  m,
const unsigned int &  pow 
) [inline]

binary power operator

Definition at line 758 of file CMatrixTemplateNumeric.h.

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::operator~ ( const CMatrixTemplateNumeric< T > &  m  )  [inline]

bool MRPTDLLIMPEXP mrpt::math::pointIntoPolygon2D ( const double &  px,
const double &  py,
unsigned int  polyEdges,
const double *  poly_xs,
const double *  poly_ys 
)

Returns true if the 2D point (px,py) falls INTO the given polygon.

template<class T >
void MRPTDLLIMPEXP mrpt::math::qr_decomposition ( CMatrixTemplateNumeric< T > &  A,
CMatrixTemplateNumeric< T > &  R,
CMatrixTemplateNumeric< T > &  Q,
CVectorTemplate< T > &  c,
int &  sing 
) [inline]

Matrix QR decomposition.

A = QR, where R is upper triangular and Q is orthogonal, that is, ~QQ = 1 If A is a LxM dimension matrix, this function only return the LxL upper triangular matrix R instead of LxM pseudo-upper triangular matrix (been L<=M) This function has been extracted from "Numerical Recipes in C". /param A is the original matrix to decompose /param c,Q. The orthogonal matrix Q is represented as a product of n-1 Householder matrices Q1,...Qn-1, where Qj = 1 - u[j] x u[j]/c[j] The i'th component of u[j] is zero for i = 1,...,j-1 while the nonzero components are returned in Q(i,j) for i=j,...,n /param R is the upper triangular matrix /param sign returns as true (1) is singularity is encountered during the decomposition, but the decomposition is still complete in this case; otherwise it returns false (0)

bool MRPTDLLIMPEXP mrpt::math::RectanglesIntersection ( const double &  R1_x_min,
const double &  R1_x_max,
const double &  R1_y_min,
const double &  R1_y_max,
const double &  R2_x_min,
const double &  R2_x_max,
const double &  R2_y_min,
const double &  R2_y_max,
const double &  R2_pose_x,
const double &  R2_pose_y,
const double &  R2_pose_phi 
)

Returns wether two rotated rectangles intersect.

The first rectangle is not rotated and given by (R1_x_min,R1_x_max)-(R1_y_min,R1_y_max). The second rectangle is given is a similar way, but it is internally rotated according to the given coordinates translation (R2_pose_x,R2_pose_y,R2_pose_phi(radians)), relative to the coordinates system of rectangle 1.

template<class T >
T mrpt::math::round2up ( val  )  [inline]

Round up to the nearest power of two of a given number.

Definition at line 452 of file math/utils.h.

References THROW_EXCEPTION.

template<class T >
T mrpt::math::round_10power ( val,
int  power10 
) [inline]

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, .

.. -1 -> 0.1, -2 -> 0.01, ...

Definition at line 468 of file math/utils.h.

References mrpt::utils::round_long().

bool MRPTDLLIMPEXP mrpt::math::SegmentsIntersection ( const double &  x1,
const double &  y1,
const double &  x2,
const double &  y2,
const double &  x3,
const double &  y3,
const double &  x4,
const double &  y4,
float &  ix,
float &  iy 
)

Returns the intersection point, and if it exists, between two segments.

bool MRPTDLLIMPEXP mrpt::math::SegmentsIntersection ( const double &  x1,
const double &  y1,
const double &  x2,
const double &  y2,
const double &  x3,
const double &  y3,
const double &  x4,
const double &  y4,
double &  ix,
double &  iy 
)

Returns the intersection point, and if it exists, between two segments.

template<class T >
size_t mrpt::math::size ( const CMatrixTemplate< T > &  m,
int  dim 
) [inline]

Returns the size of the matrix in the i'th dimension: 1=rows, 2=columns (MATLAB-compatible function).

Definition at line 840 of file CMatrixTemplate.h.

References mrpt::math::CMatrixTemplate< T >::getColCount(), mrpt::math::CMatrixTemplate< T >::getRowCount(), and THROW_EXCEPTION_CUSTOM_MSG1.

Referenced by mrpt::math::CVectorTemplate< double >::abs(), mrpt::math::CVectorTemplate< double >::deconcatenate(), mrpt::math::CVectorTemplate< double >::extract_vector(), mrpt::math::CVectorTemplate< double >::find_max(), mrpt::math::CVectorTemplate< double >::find_min(), mrpt::math::CVectorTemplate< double >::find_min_max(), mrpt::vision::CMatchedFeatureList::get_type(), mrpt::vision::CFeatureList::get_type(), mrpt::math::CVectorTemplate< double >::insert_vector(), mrpt::math::CVectorTemplate< double >::likeMatrix(), mrpt::math::CVectorTemplate< double >::mean(), mrpt::math::CVectorTemplate< double >::operator*(), mrpt::math::CVectorTemplate< double >::operator+(), mrpt::math::CVectorTemplate< double >::operator+=(), mrpt::math::CVectorTemplate< double >::operator-(), mrpt::math::CVectorTemplate< double >::operator/(), mrpt::math::CVectorTemplate< double >::operator~(), mrpt::math::CVectorTemplate< double >::saveToTextFile(), mrpt::utils::multimap_serializable< uint64_t, float >::write(), mrpt::utils::map_serializable< double, double >::write(), mrpt::utils::list_searchable_serializable< T >::write(), mrpt::utils::deque_serializable< mrpt::slam::CMultiMetricMap >::write(), and mrpt::utils::vector_serializable< mrpt::opengl::CPointCloudColoured::TPointColour >::write().

double MRPTDLLIMPEXP mrpt::math::spline ( const double  t,
const std::vector< double > &  x,
const std::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).

See also:
leastSquareLinearFit

template<class T >
double mrpt::math::stddev ( const std::vector< T > &  v,
bool  unbiased = true 
) [inline]

Computes the standard deviation of a vector.

Parameters:
v The set of data
unbiased If set to true or false the std is normalized by "N-1" or "N", respectively.
See also:
math::mean,math::meanAndStd

Definition at line 292 of file math/utils.h.

References mrpt::utils::square().

template<class T >
T mrpt::math::sum ( const std::vector< T > &  v  )  [inline]

Computes the sum of all the elements of a vector.

See also:
cumsum

Definition at line 189 of file math/utils.h.

Referenced by chol(), and mrpt::math::CVectorTemplate< double >::mean().

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.

See also:
wrapToPi

template<class T >
void MRPTDLLIMPEXP mrpt::math::UpdateCholesky ( CMatrixTemplateNumeric< T > &  chol,
CVectorTemplate< T > &  r1Modification 
) [inline]

If R = CHOL(A) is the original Cholesky factorization of A, then R1 = CHOLUPDATE(R,X) returns the upper triangular Cholesky factor of A + X*X', where X is a column vector of appropriate length.

template<class T >
void mrpt::math::weightedHistogram ( const std::vector< T > &  values,
const std::vector< T > &  weights,
float  binWidth,
std::vector< float > &  out_binCenters,
std::vector< float > &  out_binValues 
) [inline]

Computes the weighted histogram for a vector of values and their corresponding weights.

Parameters:
values [IN] The N values
weights [IN] The weights for the corresponding N values
binWidth [IN] The desired width of the bins
out_binCenters [OUT] The centers of the M bins generated to cover from the minimum to the maximum value of "values" with the given "binWidth"
out_binValues [OUT] The ratio of values at each given bin, such as the whole vector sums up the unity.

Definition at line 353 of file math/utils.h.

References ASSERT_, maximum(), minimum(), MRPT_TRY_END, MRPT_TRY_START, and mrpt::utils::round().

template<class T >
T mrpt::math::wrapTo2Pi ( a  )  [inline]

Modifies the given angle to translate it into the [0,2pi[ range.

Note:
Take care of not instancing this template for integer numbers, since it only works for float, double and long double.
See also:
wrapToPi, wrapTo2Pi, unwrap2PiSequence

Definition at line 423 of file math/utils.h.

References wrapTo2PiInPlace().

Referenced by wrapToPi().

template<class T >
void mrpt::math::wrapTo2PiInPlace ( T &  a  )  [inline]

Modifies the given angle to translate it into the [0,2pi[ range.

Note:
Take care of not instancing this template for integer numbers, since it only works for float, double and long double.
See also:
wrapToPi, wrapTo2Pi, unwrap2PiSequence

Definition at line 411 of file math/utils.h.

References M_2PI.

Referenced by wrapTo2Pi().

template<class T >
T mrpt::math::wrapToPi ( a  )  [inline]

Modifies the given angle to translate it into the ]-pi,pi] range.

Note:
Take care of not instancing this template for integer numbers, since it only works for float, double and long double.
See also:
wrapTo2Pi, wrapToPiInPlace, unwrap2PiSequence

Definition at line 434 of file math/utils.h.

References M_PI, and wrapTo2Pi().

Referenced by wrapToPiInPlace().

template<class T >
void mrpt::math::wrapToPiInPlace ( T &  a  )  [inline]

Modifies the given angle to translate it into the ]-pi,pi] range.

Note:
Take care of not instancing this template for integer numbers, since it only works for float, double and long double.
See also:
wrapToPi,wrapTo2Pi, unwrap2PiSequence

Definition at line 444 of file math/utils.h.

References wrapToPi().

template<class T >
std::vector<T> mrpt::math::zeros ( size_t  count  )  [inline]

Generates a vector of all zeros of the given length.

Definition at line 231 of file math/utils.h.




Page generated by Doxygen 1.5.7.1 for MRPT 0.6.5 SVN: at Mon Feb 23 13:25:04 EST 2009