MRPT logo

mrpt::math::CMatrixTemplateNumeric< T > Class Template Reference

This template class extends the class "CMatrixTemplate" with many common operations with numerical matrixes. More...

#include <mrpt/math/CMatrixTemplateNumeric.h>

Inheritance diagram for mrpt::math::CMatrixTemplateNumeric< T >:

mrpt::math::CMatrixTemplate< T >

List of all members.

Public Member Functions

template<class R >
 CMatrixTemplateNumeric (const CMatrixTemplate< R > &m)
 Copy constructor from a matrix of any type.
 CMatrixTemplateNumeric ()
 Default constructor, builds a 1x1 matrix.
 CMatrixTemplateNumeric (size_t row, size_t col)
 Constructor.
 CMatrixTemplateNumeric (const CMatrixTemplate< T > &m, const size_t cropRowCount, const size_t cropColCount)
 Copy & crop constructor, which copies the given matrix but only up to the given size.
template<typename V , size_t N>
 CMatrixTemplateNumeric (size_t row, size_t col, V(&theArray)[N])
 Constructor from a given size and a C array.
template<typename V >
 CMatrixTemplateNumeric (size_t row, size_t col, const V &theVector)
 Constructor from a given size and a STL container (std::vector, std::list,.
virtual ~CMatrixTemplateNumeric ()
 Destructor.
 CMatrixTemplateNumeric (const mrpt::poses::CPose2D &p)
 Constructor from a mrpt::poses::CPose2D, which generates a 3x1 matrix $ [x y \phi]^T $.
 CMatrixTemplateNumeric (const mrpt::poses::CPose3D &p)
 Constructor from a mrpt::poses::CPose6D, which generates a 6x1 matrix $ [x y z yaw pitch roll]^T $.
 CMatrixTemplateNumeric (const mrpt::poses::CPoint2D &p)
 Constructor from a mrpt::poses::CPoint2D, which generates a 2x1 matrix $ [x y]^T $.
 CMatrixTemplateNumeric (const mrpt::poses::CPoint3D &p)
 Constructor from a mrpt::poses::CPoint3D, which generates a 3x1 matrix $ [x y z]^T $.
template<size_t NROWS, size_t NCOLS>
 CMatrixTemplateNumeric (const CMatrixFixedNumeric< T, NROWS, NCOLS > &M)
 Copy constructor from a fixed-size matrix.
template<size_t NROWS, size_t NCOLS>
CMatrixTemplateNumericoperator= (const CMatrixFixedNumeric< T, NROWS, NCOLS > &M)
 Copy operator from a fixed-size matrix.
template<class R >
CMatrixTemplateNumeric< T > & operator= (const CMatrixTemplateNumeric< R > &m)
 Assignment operator of other types.
template<typename V , size_t N>
CMatrixTemplateNumericoperator= (V(&theArray)[N])
 Assignment operator for initializing from a C array (The matrix must be set to the correct size before invoking this asignament).
CMatrixTemplateNumeric< T > & operator= (const CMatrixTemplateNumeric< T > &m)
 Assignment operator for the same type.
void setSize (size_t row, size_t col)
 Changes the size of matrix, maintaining its previous content as possible and padding with zeros where applicable.
void resize (size_t row, size_t col)
 Changes the size of matrix, maintaining its previous content as possible and padding with zeros where applicable.
void laplacian (CMatrixTemplateNumeric< T > &ret) const
 Computes the laplacian of the matrix, useful for graph matrixes.
void svd (CMatrixTemplateNumeric< T > &U, std::vector< T > &W, CMatrixTemplateNumeric< T > &V) const
 Computes the SVD (Singular Value Decomposition) of the matrix.
void eigenVectors (CMatrixTemplateNumeric< T > &Z, CMatrixTemplateNumeric< T > &D) const
 Computes the eigenvalues/eigenvector decomposition of a symmetric matrix.
CMatrixTemplateNumeric< T > largestEigenvector (T resolution=0.01f, size_t maxIterations=6, int *out_Iterations=NULL, float *out_estimatedResolution=NULL) const
 Efficiently computes only the biggest eigenvector of the matrix using the Power Method, and returns it as a column vector.
CMatrixTemplateNumeric< T > & Sqrt ()
 Computes the sqrt of each element in the matrix, replacing current values;.
CMatrixTemplateNumeric< T > & Abs ()
 Computes the absolute value of each element in the matrix, replacing current values.
CMatrixTemplateNumeric< T > & Square ()
 Computes the square of each element in the matrix, replacing current values.
template<class F >
CMatrixTemplateNumeric< T > & applyToAllElements (F function)
 Applies a generic operation to all the elements of the matrix.
CMatrixTemplateNumeric< T > operator+ ()
 Unary operator.
CMatrixTemplateNumeric< T > operator- ()
 Unary operator.
CMatrixTemplateNumeric< T > & operator+= (const CMatrixTemplateNumeric< T > &m)
 combined addition and assignment operator
CMatrixTemplateNumeric< T > & add_At (const CMatrixTemplateNumeric< T > &m)
 Add to this matrix the transpose of A.
CMatrixTemplateNumeric< T > & add_AAt (const CMatrixTemplateNumeric< T > &m)
 Add to this matrix A and its transpose (this = this + A + At).
CMatrixTemplateNumeric< T > & add_Ac (const CMatrixTemplateNumeric< T > &m, const T c)
 Add A times a scalar c to this matrix: this = this + A * c.
CMatrixTemplateNumeric< T > & operator-= (const CMatrixTemplateNumeric< T > &m)
 combined subtraction and assignment operator
CMatrixTemplateNumeric< T > & substract_Ac (const CMatrixTemplateNumeric< T > &m, const T c)
 Substract A times a scalar c to this matrix: this = this - A * c.
CMatrixTemplateNumeric< T > & operator*= (const T &c)
 combined scalar multiplication and assignment operator
CMatrixTemplateNumeric< T > & operator*= (const CMatrixTemplateNumeric< T > &m)
 combined matrix multiplication and assignment operator
void multiply (const CMatrixTemplateNumeric< T > &m1, const CMatrixTemplateNumeric< T > &m2)
 Multiply 2 matrices and save the result in "this" object.
void multiply (const CMatrixTemplateNumeric< T > &m1, const CVectorTemplate< T > &m2)
 Multiply one matrix by a column vector and save the result in "this" object.
void multiply_ABt (const CMatrixTemplateNumeric< T > &m1, const CMatrixTemplateNumeric< T > &m2)
 Makes this = M1 * M2^T.
void multiply_AAt (const CMatrixTemplateNumeric< T > &m1)
 Makes this = M1 * M1^T, taking into account that the result is symmetric and only half the computations must be done.
void multiply_AtA (const CMatrixTemplateNumeric< T > &m1)
 Makes this = M1^T * M1, taking into account that the result is symmetric and only half the computations must be done.
void multiply_Ab (const std::vector< T > &a, std::vector< T > &out_v)
 Computes the vector v = this * a, where "a" is a column vector of the appropriate length.
void multiply_Atb (const std::vector< T > &a, std::vector< T > &out_v)
 Computes the vector v = this^T * a, where "a" is a column vector of the appropriate length.
void multiply_result_is_symmetric (const CMatrixTemplateNumeric< T > &m1, const CMatrixTemplateNumeric< T > &m2)
 Multiply 2 matrices and save the result in "this" object, for the cases in which we know in advance that the result will be a symmetrical matrix (DO NOT USE OTHERWISE!!).
void multiplySubMatrix (const CMatrixTemplateNumeric< T > &A, CMatrixTemplateNumeric< T > &outResult, const size_t &A_cols_offset, const size_t &A_rows_offset, const size_t &A_col_count)
 Matrix multiplication of this matrix with a submatrix of 'A', saving the result in a third matrix.
CMatrixTemplateNumeric< T > & operator/= (const CMatrixTemplateNumeric< T > &m)
 Dot division by another matrix (element by element division).
CMatrixTemplateNumeric< T > & operator/= (const T &c)
 combined scalar division and assignment operator
CMatrixTemplateNumeric< T > & operator+= (const T &c)
 Combined scalar addition and assignment operator.
CMatrixTemplateNumeric< T > & operator-= (const T &c)
 Combined scalar substraction and assignment operator.
CMatrixTemplateNumeric< T > & operator^= (const unsigned int &pow)
 combined power and assignment operator
void scalarPow (T s)
 Scalar power of all elements to a given power, this is diferent of ^ operator.
void zeros (const size_t &row, const size_t &col)
 Set all elements to zero.
void zeros ()
 Set all elements to zero.
void ones (const size_t &row, const size_t &col)
 Set all elements to one.
void ones ()
 Set all elements to one.
void unit (const size_t &row)
 Build an unit matrix.
void unit ()
 Build an unit matrix.
CMatrixTemplateNumeric< T > solve (const CMatrixTemplateNumeric< T > &v)
 Solve the matrix as linear equations system.
CMatrixTemplateNumeric< T > adj () const
 Computes the adjunt of matrix.
void inv (CMatrixTemplateNumeric< T > &out_inv) const
 Computes the Inverse of matrix.
CMatrixTemplateNumeric< T > inv () const
 Computes the Inverse of matrix.
void inv_fast (CMatrixTemplateNumeric< T > &out_inv)
 Computes the Inverse of matrix, DESTROYING the current matrix and returning the inverse in an user-supplied matrix.
void pseudoInverse (CMatrixTemplateNumeric< T > &out) const
 Compute the pseudo-inverse of this matrix M, given by $ ( M^\top M )^{-1} X^\top $.
CMatrixTemplateNumeric< T > pseudoInverse () const
 Compute the pseudo-inverse of this matrix M, given by $ ( M^\top M )^{-1} X^\top $.
det () const
 Computes the determinant of matrix.
size_t rank (T eps=0.0) const
 Computes the rank of the matrix using a slight variation of Gauss method.
norm () const
 Computes the norm of matrix.
cofact (size_t row, size_t col) const
 Computes the cofact.
cond ()
 Computes the cond.
bool isSingular () const
 Checks for matrix type.
bool isDiagonal () const
 Checks for matrix type.
bool isScalar () const
 Checks for matrix type.
bool isUnit () const
 Checks for matrix type.
bool isNull () const
 Checks for matrix type.
bool isSymmetric () const
 Checks for matrix type.
bool isSkewSymmetric () const
 Checks for matrix type.
bool isUpperTriangular () const
 Checks for matrix type.
bool isLowerTriangular () const
 Checks for matrix type.
void matrix_floor ()
 Round towards minus infinity modifying the matrix (by AJOGD @ JAN-2007).
void matrix_floor (CMatrixTemplateNumeric< T > &out)
 Round towards minus infinity (by AJOGD @ JAN-2007).
void matrix_ceil ()
 Round towards plus infinity (by AJOGD @ JAN-2007).
void find_index_max_value (size_t &umax, size_t &vmax, T &max_val) const
 Finds the maximum value in the matrix, and returns its position.
maximumDiagonal () const
 Finds the maximum value in the diagonal of the matrix.
maximum () const
 Finds the maximum value in the matrix.
minimum () const
 Finds the minimum value in the matrix.
void find_index_min_value (size_t &umin, size_t &vmin, T &min_val) const
 Finds the minimum value in the matrix, and returns its position.
void force_symmetry ()
 Force symmetry in the matrix (by AJOGD @ JAN-2007).
void mean (std::vector< T > &outMeanVector) const
 Computes a row with the mean values of each column in the matrix.
void meanAndStd (std::vector< T > &outMeanVector, std::vector< T > &outStdVector) const
 Computes a row with the mean values of each column in the matrix and the associated vector with the standard deviation of each column.
void meanAndStdAll (T &outMean, T &outStd) const
 Computes the mean and standard deviation of all the elements in the matrix as a whole.
void asCol (CMatrixTemplateNumeric< T > &aux) const
void asRow (CMatrixTemplateNumeric< T > &aux) const
void findElementsPassingMahalanobisThreshold (double stdTimes, std::vector< size_t > &rowIndexes, std::vector< size_t > &colIndexes, bool below=false) const
 Finds elements whose values are a given number of times above (or below) the mean, in 1D Mahalanobis distance.
void normalize (T minVal=0, T maxVal=1)
 Adjusts the range of elements in the matrix such as the minimum and maximum values being those supplied by the user.
void adjustRange (T minVal=0, T maxVal=1)
 Adjusts the range of elements in the matrix such as the minimum and maximum values being those supplied by the user.
sumAll () const
 Returns the sum of all the elements in the matrix.
sum (size_t firstRow=0, size_t firstCol=0, size_t lastRow=std::numeric_limits< size_t >::max(), size_t lastCol=std::numeric_limits< size_t >::max()) const
 Returns the sum of a given part of the matrix.
void multiplyByMatrixAndByTransposeNonSymmetric (const CMatrixTemplateNumeric< T > &C, CMatrixTemplateNumeric< T > &R, bool accumOnOutput=false, bool substractInsteadOfSum=false) const
 Computes: R = H * C * H^t , where H is this matrix.
void multiply_ABC (const CMatrixTemplateNumeric< T > &A, const CMatrixTemplateNumeric< T > &B, const CMatrixTemplateNumeric< T > &C)
 Calculate the operation S = ABC where S is this object.
void multiply_ABCt (const CMatrixTemplateNumeric< T > &A, const CMatrixTemplateNumeric< T > &B, const CMatrixTemplateNumeric< T > &C)
 Calculate the operation S = ABCt where S is this object.
void multiply_HCHt (const CMatrixTemplateNumeric< T > &C, CMatrixTemplateNumeric< T > &R, bool allowSubMatrixMultiplication=false, size_t subMatrixOffset=0, bool accumResultInOutput=false) const
 This executes the operation $ \mathbf{R} = \mathbf{H} \mathbf{C} \mathbf{H}^t $, where 'this' matrix is $ \mathbf{H} $ and $ \mathbf{C} $ is symmetric, in an efficient and numerically stable way.
multiply_HCHt_scalar (const CMatrixTemplateNumeric< T > &C) const
 An special case of multiply_HCHt for the case of the resulting matrix being a scalar (that is, a 1x1 matrix) - This method directly returns this as a scalar avoiding the construction of a 1x1 matrix.

Private Member Functions

int pivot (size_t row)
 Internal use.


Detailed Description

template<class T>
class mrpt::math::CMatrixTemplateNumeric< T >

This template class extends the class "CMatrixTemplate" with many common operations with numerical matrixes.

The template can be instanced for data types: float, double, long double

The following operators have been implemented:

Implemented Operators
Meaning
x=M(i,j)
M(i,j)=x
This () operator is used to access/change the element at i'th row, j'th column. First index is 0.
!M The matrix inverse M-1
~M The matrix transpose MT
(M^n) Power of a matrix: (M*M*M*...M) n times. Use parenthesis with this operator. Use "scalarPow" for the power of individual elements in the matrix.
M1 = M2 Assignment operator: Copy matrix M2 to M1
M1 == M2
M1 != M2
Logical comparison: Returns true or false if all elements are identical.
x * M Scalar multiplication
M1 * M2 Matrix multiplication, with the usual mathematical meaning
M1 + M2
M1 – M2
Matrixes addition and substraction.
M / x Scalar division
M1 / M2 Equivalent to (M1 * M2-1)
stream << M; Write to a binary CStream, since this class is CSerializable
stream >> M; Read from a binary CStream, since this class is CSerializable
See also this useful methods:

Definition at line 112 of file CMatrixTemplateNumeric.h.


Constructor & Destructor Documentation

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

Copy constructor from a matrix of any type.

Definition at line 118 of file CMatrixTemplateNumeric.h.

Default constructor, builds a 1x1 matrix.

template<class T >
mrpt::math::CMatrixTemplateNumeric< T >::CMatrixTemplateNumeric ( size_t  row,
size_t  col 
)

Constructor.

template<class T >
mrpt::math::CMatrixTemplateNumeric< T >::CMatrixTemplateNumeric ( const CMatrixTemplate< T > &  m,
const size_t  cropRowCount,
const size_t  cropColCount 
) [inline]

Copy & crop constructor, which copies the given matrix but only up to the given size.

Definition at line 134 of file CMatrixTemplateNumeric.h.

template<class T >
template<typename V , size_t N>
mrpt::math::CMatrixTemplateNumeric< T >::CMatrixTemplateNumeric ( size_t  row,
size_t  col,
V(&)  theArray[N] 
) [inline]

Constructor from a given size and a C array.

The array length must match cols x row.

  const double numbers[] = {
    1,2,3,
    4,5,6 };
         CMatrixDouble   M(3,2, numbers);

Definition at line 146 of file CMatrixTemplateNumeric.h.

template<class T >
template<typename V >
mrpt::math::CMatrixTemplateNumeric< T >::CMatrixTemplateNumeric ( size_t  row,
size_t  col,
const V &  theVector 
) [inline]

Constructor from a given size and a STL container (std::vector, std::list,.

..) with the initial values. The vector length must match cols x row.

Definition at line 152 of file CMatrixTemplateNumeric.h.

template<class T >
virtual mrpt::math::CMatrixTemplateNumeric< T >::~CMatrixTemplateNumeric (  )  [inline, virtual]

Destructor.

Definition at line 157 of file CMatrixTemplateNumeric.h.

template<class T >
mrpt::math::CMatrixTemplateNumeric< T >::CMatrixTemplateNumeric ( const mrpt::poses::CPose2D p  )  [explicit]

Constructor from a mrpt::poses::CPose2D, which generates a 3x1 matrix $ [x y \phi]^T $.

template<class T >
mrpt::math::CMatrixTemplateNumeric< T >::CMatrixTemplateNumeric ( const mrpt::poses::CPose3D p  )  [explicit]

Constructor from a mrpt::poses::CPose6D, which generates a 6x1 matrix $ [x y z yaw pitch roll]^T $.

template<class T >
mrpt::math::CMatrixTemplateNumeric< T >::CMatrixTemplateNumeric ( const mrpt::poses::CPoint2D p  )  [explicit]

Constructor from a mrpt::poses::CPoint2D, which generates a 2x1 matrix $ [x y]^T $.

template<class T >
mrpt::math::CMatrixTemplateNumeric< T >::CMatrixTemplateNumeric ( const mrpt::poses::CPoint3D p  )  [explicit]

Constructor from a mrpt::poses::CPoint3D, which generates a 3x1 matrix $ [x y z]^T $.

template<class T >
template<size_t NROWS, size_t NCOLS>
mrpt::math::CMatrixTemplateNumeric< T >::CMatrixTemplateNumeric ( const CMatrixFixedNumeric< T, NROWS, NCOLS > &  M  )  [inline, explicit]

Copy constructor from a fixed-size matrix.

Note:
Method implemented in CMatrixFixedNumeric.h

Definition at line 180 of file CMatrixTemplateNumeric.h.


Member Function Documentation

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::Abs (  ) 

Computes the absolute value of each element in the matrix, replacing current values.

Returns:
A reference to THIS object.

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::add_AAt ( const CMatrixTemplateNumeric< T > &  m  ) 

Add to this matrix A and its transpose (this = this + A + At).

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::add_Ac ( const CMatrixTemplateNumeric< T > &  m,
const T  c 
)

Add A times a scalar c to this matrix: this = this + A * c.

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::add_At ( const CMatrixTemplateNumeric< T > &  m  ) 

Add to this matrix the transpose of A.

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::CMatrixTemplateNumeric< T >::adj (  )  const

Computes the adjunt of matrix.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::adjustRange ( minVal = 0,
maxVal = 1 
)

Adjusts the range of elements in the matrix such as the minimum and maximum values being those supplied by the user.

template<class T >
template<class F >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::applyToAllElements ( function  )  [inline]

Applies a generic operation to all the elements of the matrix.

The passed functor object must implement the "T operator(T val)" operator.

Returns:
A reference to THIS object.

Definition at line 293 of file CMatrixTemplateNumeric.h.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::asCol ( CMatrixTemplateNumeric< T > &  aux  )  const

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::asRow ( CMatrixTemplateNumeric< T > &  aux  )  const

template<class T >
T mrpt::math::CMatrixTemplateNumeric< T >::cofact ( size_t  row,
size_t  col 
) const

Computes the cofact.

template<class T >
T mrpt::math::CMatrixTemplateNumeric< T >::cond (  ) 

Computes the cond.

template<class T >
T mrpt::math::CMatrixTemplateNumeric< T >::det (  )  const

Computes the determinant of matrix.

Note:
Efficient hard-coded solutions are implemented for 2x2 and 3x3 matrices.

Referenced by mrpt::math::normalPDF().

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::eigenVectors ( CMatrixTemplateNumeric< T > &  Z,
CMatrixTemplateNumeric< T > &  D 
) const

Computes the eigenvalues/eigenvector decomposition of a symmetric matrix.

The decomposition is: M = Z · D · ZT, where columns in Z are the eigenvectors and the diagonal matrix D contains the eigenvalues as diagonal elements, sorted in ascending order. The algorithm is taken from "Numerical recipes in C", freely available online.

Referenced by mrpt::utils::CEnhancedMetaFile::ellipseGaussian(), and mrpt::utils::CCanvas::ellipseGaussian().

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::find_index_max_value ( size_t &  umax,
size_t &  vmax,
T &  max_val 
) const

Finds the maximum value in the matrix, and returns its position.

(by AJOGD @ JAN-2007)

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::find_index_min_value ( size_t &  umin,
size_t &  vmin,
T &  min_val 
) const

Finds the minimum value in the matrix, and returns its position.

(by AJOGD @ JAN-2007)

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::findElementsPassingMahalanobisThreshold ( double  stdTimes,
std::vector< size_t > &  rowIndexes,
std::vector< size_t > &  colIndexes,
bool  below = false 
) const

Finds elements whose values are a given number of times above (or below) the mean, in 1D Mahalanobis distance.

This returns two lists with the "row" and "column" indexes (i,j) of those elements m[i][j] such as: m[i][j] > mean(matrix) + stdTimes·std(matrix) The elements below the threshold mean(matrix) - stdTimes·std(matrix) can also be obtained setting "below" to "true".

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::force_symmetry (  ) 

Force symmetry in the matrix (by AJOGD @ JAN-2007).

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::CMatrixTemplateNumeric< T >::inv (  )  const [inline]

Computes the Inverse of matrix.

Return the inverse of a matrix without modifying the original matrix

Note:
Efficient hard-coded solutions are implemented for 2x2 and 3x3 matrices.

Definition at line 448 of file CMatrixTemplateNumeric.h.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::inv ( CMatrixTemplateNumeric< T > &  out_inv  )  const

Computes the Inverse of matrix.

Return the inverse of a matrix without modifying the original matrix

Note:
Efficient hard-coded solutions are implemented for 2x2 and 3x3 matrices.

Referenced by mrpt::math::normalPDF(), and mrpt::math::operator!().

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::inv_fast ( CMatrixTemplateNumeric< T > &  out_inv  ) 

Computes the Inverse of matrix, DESTROYING the current matrix and returning the inverse in an user-supplied matrix.

Note:
Efficient hard-coded solutions are implemented for 2x2 and 3x3 matrices. By AJOGD/JLBC

Referenced by mrpt::math::CLevenbergMarquardtTempl< NUMTYPE, USERPARAM >::execute().

template<class T >
bool mrpt::math::CMatrixTemplateNumeric< T >::isDiagonal (  )  const

Checks for matrix type.

template<class T >
bool mrpt::math::CMatrixTemplateNumeric< T >::isLowerTriangular (  )  const

Checks for matrix type.

template<class T >
bool mrpt::math::CMatrixTemplateNumeric< T >::isNull (  )  const

Checks for matrix type.

template<class T >
bool mrpt::math::CMatrixTemplateNumeric< T >::isScalar (  )  const

Checks for matrix type.

template<class T >
bool mrpt::math::CMatrixTemplateNumeric< T >::isSingular (  )  const

Checks for matrix type.

template<class T >
bool mrpt::math::CMatrixTemplateNumeric< T >::isSkewSymmetric (  )  const

Checks for matrix type.

template<class T >
bool mrpt::math::CMatrixTemplateNumeric< T >::isSymmetric (  )  const

Checks for matrix type.

template<class T >
bool mrpt::math::CMatrixTemplateNumeric< T >::isUnit (  )  const

Checks for matrix type.

template<class T >
bool mrpt::math::CMatrixTemplateNumeric< T >::isUpperTriangular (  )  const

Checks for matrix type.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::laplacian ( CMatrixTemplateNumeric< T > &  ret  )  const

Computes the laplacian of the matrix, useful for graph matrixes.

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::CMatrixTemplateNumeric< T >::largestEigenvector ( resolution = 0.01f,
size_t  maxIterations = 6,
int *  out_Iterations = NULL,
float *  out_estimatedResolution = NULL 
) const

Efficiently computes only the biggest eigenvector of the matrix using the Power Method, and returns it as a column vector.

The computation time for this method, in a Pentium 4 1.4Ghz is:
T = 7.0867e-008*n2 + 1.9191e-005*n + 0.0017494 seconds
where N is the matrix size.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::matrix_ceil (  ) 

Round towards plus infinity (by AJOGD @ JAN-2007).

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::matrix_floor ( CMatrixTemplateNumeric< T > &  out  ) 

Round towards minus infinity (by AJOGD @ JAN-2007).

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::matrix_floor (  ) 

Round towards minus infinity modifying the matrix (by AJOGD @ JAN-2007).

template<class T >
T mrpt::math::CMatrixTemplateNumeric< T >::maximum (  )  const

Finds the maximum value in the matrix.

template<class T >
T mrpt::math::CMatrixTemplateNumeric< T >::maximumDiagonal (  )  const

Finds the maximum value in the diagonal of the matrix.

Referenced by mrpt::math::CLevenbergMarquardtTempl< NUMTYPE, USERPARAM >::execute().

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::mean ( std::vector< T > &  outMeanVector  )  const

Computes a row with the mean values of each column in the matrix.

See also:
meanAndStdAll

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::meanAndStd ( std::vector< T > &  outMeanVector,
std::vector< T > &  outStdVector 
) const

Computes a row with the mean values of each column in the matrix and the associated vector with the standard deviation of each column.

See also:
mean,meanAndStdAll

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::meanAndStdAll ( T &  outMean,
T &  outStd 
) const

Computes the mean and standard deviation of all the elements in the matrix as a whole.

See also:
mean,meanAndStd

template<class T >
T mrpt::math::CMatrixTemplateNumeric< T >::minimum (  )  const

Finds the minimum value in the matrix.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::multiply ( const CMatrixTemplateNumeric< T > &  m1,
const CVectorTemplate< T > &  m2 
)

Multiply one matrix by a column vector and save the result in "this" object.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::multiply ( const CMatrixTemplateNumeric< T > &  m1,
const CMatrixTemplateNumeric< T > &  m2 
)

Multiply 2 matrices and save the result in "this" object.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::multiply_AAt ( const CMatrixTemplateNumeric< T > &  m1  ) 

Makes this = M1 * M1^T, taking into account that the result is symmetric and only half the computations must be done.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::multiply_Ab ( const std::vector< T > &  a,
std::vector< T > &  out_v 
)

Computes the vector v = this * a, where "a" is a column vector of the appropriate length.

Referenced by mrpt::math::CLevenbergMarquardtTempl< NUMTYPE, USERPARAM >::execute().

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::multiply_ABC ( const CMatrixTemplateNumeric< T > &  A,
const CMatrixTemplateNumeric< T > &  B,
const CMatrixTemplateNumeric< T > &  C 
)

Calculate the operation S = ABC where S is this object.

See also:
multiply_ABCt By AJOGD

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::multiply_ABCt ( const CMatrixTemplateNumeric< T > &  A,
const CMatrixTemplateNumeric< T > &  B,
const CMatrixTemplateNumeric< T > &  C 
)

Calculate the operation S = ABCt where S is this object.

See also:
multiply_ABC

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::multiply_ABt ( const CMatrixTemplateNumeric< T > &  m1,
const CMatrixTemplateNumeric< T > &  m2 
)

Makes this = M1 * M2^T.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::multiply_AtA ( const CMatrixTemplateNumeric< T > &  m1  ) 

Makes this = M1^T * M1, taking into account that the result is symmetric and only half the computations must be done.

Referenced by mrpt::math::CLevenbergMarquardtTempl< NUMTYPE, USERPARAM >::execute().

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::multiply_Atb ( const std::vector< T > &  a,
std::vector< T > &  out_v 
)

Computes the vector v = this^T * a, where "a" is a column vector of the appropriate length.

Referenced by mrpt::math::CLevenbergMarquardtTempl< NUMTYPE, USERPARAM >::execute().

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::multiply_HCHt ( const CMatrixTemplateNumeric< T > &  C,
CMatrixTemplateNumeric< T > &  R,
bool  allowSubMatrixMultiplication = false,
size_t  subMatrixOffset = 0,
bool  accumResultInOutput = false 
) const

This executes the operation $ \mathbf{R} = \mathbf{H} \mathbf{C} \mathbf{H}^t $, where 'this' matrix is $ \mathbf{H} $ and $ \mathbf{C} $ is symmetric, in an efficient and numerically stable way.

If 'this' matrix is $ N \times M $, then $ \mathbf{C} $ must be $ M \times M $, and the result matrix $ R $ will be $ N \times N $. The result from this method is assured to be symmetric (if $ \mathbf{C} $ is symmetric), whereas executing:

                                 R = H * C * (~H);
may lead to non-symmetric matrixes due to numerical rounding errors. In addition, this method is more efficient that the code above (see the MRPT's code examples on matrixes).

If allowSubMatrixMultiplication=true, the multiplication will be performed with a $ M \times M $ submatrix of C only, with M being the number of columns of H, and C being possibly larger. This is useful in some SLAM problems. In this case, an optional offset 'subMatrixOffset' can be supplied such as a submatrix from the diagonal of C is used, starting at a given column and row index (first=0).

If accumResultInOutput=true, the contents of the output matrix will not be cleared, but added to the result of the operations. In this case it must have the correct size before calling or an exception will be raised since this probably is a bug.

See also:
multiply_HCHt_scalar

template<class T >
T mrpt::math::CMatrixTemplateNumeric< T >::multiply_HCHt_scalar ( const CMatrixTemplateNumeric< T > &  C  )  const

An special case of multiply_HCHt for the case of the resulting matrix being a scalar (that is, a 1x1 matrix) - This method directly returns this as a scalar avoiding the construction of a 1x1 matrix.

This matrix (H) must be $ 1 \times N $ or a $ N \times 1 $ matrix and C must by $ N \times N $, or an exception will be raised. Refer to multiply_HCHt for more information.

                                 return = ( H * C * (~H) ) (0,0);
See also:
multiply_HCHt

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::multiply_result_is_symmetric ( const CMatrixTemplateNumeric< T > &  m1,
const CMatrixTemplateNumeric< T > &  m2 
)

Multiply 2 matrices and save the result in "this" object, for the cases in which we know in advance that the result will be a symmetrical matrix (DO NOT USE OTHERWISE!!).

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::multiplyByMatrixAndByTransposeNonSymmetric ( const CMatrixTemplateNumeric< T > &  C,
CMatrixTemplateNumeric< T > &  R,
bool  accumOnOutput = false,
bool  substractInsteadOfSum = false 
) const

Computes: R = H * C * H^t , where H is this matrix.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::multiplySubMatrix ( const CMatrixTemplateNumeric< T > &  A,
CMatrixTemplateNumeric< T > &  outResult,
const size_t &  A_cols_offset,
const size_t &  A_rows_offset,
const size_t &  A_col_count 
)

Matrix multiplication of this matrix with a submatrix of 'A', saving the result in a third matrix.

OUT = THIS * A

template<class T >
T mrpt::math::CMatrixTemplateNumeric< T >::norm (  )  const

Computes the norm of matrix.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::normalize ( minVal = 0,
maxVal = 1 
) [inline]

Adjusts the range of elements in the matrix such as the minimum and maximum values being those supplied by the user.

This method is just a shortcut for adjustRange.

Definition at line 609 of file CMatrixTemplateNumeric.h.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::ones (  ) 

Set all elements to one.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::ones ( const size_t &  row,
const size_t &  col 
)

Set all elements to one.

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::operator*= ( const CMatrixTemplateNumeric< T > &  m  ) 

combined matrix multiplication and assignment operator

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::operator*= ( const T &  c  ) 

combined scalar multiplication and assignment operator

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::CMatrixTemplateNumeric< T >::operator+ (  ) 

Unary operator.

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::operator+= ( const T &  c  ) 

Combined scalar addition and assignment operator.

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::operator+= ( const CMatrixTemplateNumeric< T > &  m  ) 

combined addition and assignment operator

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::CMatrixTemplateNumeric< T >::operator- (  ) 

Unary operator.

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::operator-= ( const T &  c  ) 

Combined scalar substraction and assignment operator.

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::operator-= ( const CMatrixTemplateNumeric< T > &  m  ) 

combined subtraction and assignment operator

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::operator/= ( const T &  c  ) 

combined scalar division and assignment operator

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::operator/= ( const CMatrixTemplateNumeric< T > &  m  ) 

Dot division by another matrix (element by element division).

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::operator= ( const CMatrixTemplateNumeric< T > &  m  ) 

Assignment operator for the same type.

template<class T >
template<typename V , size_t N>
CMatrixTemplateNumeric& mrpt::math::CMatrixTemplateNumeric< T >::operator= ( V(&)  theArray[N]  )  [inline]

Assignment operator for initializing from a C array (The matrix must be set to the correct size before invoking this asignament).

         CMatrixDouble   M(3,2);
  const double numbers[] = {
    1,2,3,
    4,5,6 };
  M = numbers;
Refer also to the constructor with initialization data CMatrixTemplate::CMatrixTemplate

Reimplemented from mrpt::math::CMatrixTemplate< T >.

Definition at line 217 of file CMatrixTemplateNumeric.h.

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

Assignment operator of other types.

Definition at line 196 of file CMatrixTemplateNumeric.h.

template<class T >
template<size_t NROWS, size_t NCOLS>
CMatrixTemplateNumeric& mrpt::math::CMatrixTemplateNumeric< T >::operator= ( const CMatrixFixedNumeric< T, NROWS, NCOLS > &  M  )  [inline]

Copy operator from a fixed-size matrix.

Note:
Method implemented in CMatrixFixedNumeric.h

Definition at line 188 of file CMatrixTemplateNumeric.h.

Referenced by mrpt::math::CMatrixD::operator=().

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::operator^= ( const unsigned int &  pow  ) 

combined power and assignment operator

template<class T >
int mrpt::math::CMatrixTemplateNumeric< T >::pivot ( size_t  row  )  [private]

Internal use.

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::CMatrixTemplateNumeric< T >::pseudoInverse (  )  const [inline]

Compute the pseudo-inverse of this matrix M, given by $ ( M^\top M )^{-1} X^\top $.

Definition at line 464 of file CMatrixTemplateNumeric.h.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::pseudoInverse ( CMatrixTemplateNumeric< T > &  out  )  const

Compute the pseudo-inverse of this matrix M, given by $ ( M^\top M )^{-1} X^\top $.

template<class T >
size_t mrpt::math::CMatrixTemplateNumeric< T >::rank ( eps = 0.0  )  const

Computes the rank of the matrix using a slight variation of Gauss method.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::resize ( size_t  row,
size_t  col 
)

Changes the size of matrix, maintaining its previous content as possible and padding with zeros where applicable.

setSize and resize are exactly equivalent methods.

Referenced by mrpt::math::covariancesAndMean(), mrpt::math::fixedToDynMatrix(), and mrpt::monoslam::CMonoSlam::get_pkk().

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::scalarPow ( s  ) 

Scalar power of all elements to a given power, this is diferent of ^ operator.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::setSize ( size_t  row,
size_t  col 
)

Changes the size of matrix, maintaining its previous content as possible and padding with zeros where applicable.

setSize and resize are exactly equivalent methods.

Reimplemented from mrpt::math::CMatrixTemplate< T >.

Referenced by mrpt::math::chol(), mrpt::math::estimateJacobian(), mrpt::math::CLevenbergMarquardtTempl< NUMTYPE, USERPARAM >::execute(), mrpt::math::CVectorTemplate< double >::likeMatrix(), mrpt::math::CQuaternion< T >::q_normJac(), and mrpt::math::CQuaternion< T >::q_rotation_matrix().

template<class T >
CMatrixTemplateNumeric<T> mrpt::math::CMatrixTemplateNumeric< T >::solve ( const CMatrixTemplateNumeric< T > &  v  ) 

Solve the matrix as linear equations system.

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::Sqrt (  ) 

Computes the sqrt of each element in the matrix, replacing current values;.

Returns:
A reference to THIS object.

Referenced by mrpt::utils::CEnhancedMetaFile::ellipseGaussian(), and mrpt::utils::CCanvas::ellipseGaussian().

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::Square (  ) 

Computes the square of each element in the matrix, replacing current values.

Returns:
A reference to THIS object.

template<class T >
CMatrixTemplateNumeric<T>& mrpt::math::CMatrixTemplateNumeric< T >::substract_Ac ( const CMatrixTemplateNumeric< T > &  m,
const T  c 
)

Substract A times a scalar c to this matrix: this = this - A * c.

template<class T >
T mrpt::math::CMatrixTemplateNumeric< T >::sum ( size_t  firstRow = 0,
size_t  firstCol = 0,
size_t  lastRow = std::numeric_limits< size_t >::max(),
size_t  lastCol = std::numeric_limits< size_t >::max() 
) const

Returns the sum of a given part of the matrix.

The default value (std::numeric_limits<size_t>::max()) for the last column/row means to sum up to the last column/row.

See also:
sumAll

template<class T >
T mrpt::math::CMatrixTemplateNumeric< T >::sumAll (  )  const

Returns the sum of all the elements in the matrix.

See also:
sum

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::svd ( CMatrixTemplateNumeric< T > &  U,
std::vector< T > &  W,
CMatrixTemplateNumeric< T > &  V 
) const

Computes the SVD (Singular Value Decomposition) of the matrix.

If "this" matrix is named A with dimensions M x N, this method computes:
A = U * W * V'

, where U is a M x N column orthogonal matrix, W is a diagonal matrix containing the singular values, and V is a NxN matrix.
This method returns the U matrix, the N elements in the diagonal of W as a vector, and the matrix V, NOT TRANSPOSED.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::unit (  ) 

Build an unit matrix.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::unit ( const size_t &  row  ) 

Build an unit matrix.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::zeros (  ) 

Set all elements to zero.

template<class T >
void mrpt::math::CMatrixTemplateNumeric< T >::zeros ( const size_t &  row,
const size_t &  col 
)

Set all elements to zero.

Referenced by mrpt::math::meanAndCov().




Page generated by Doxygen 1.5.7.1 for MRPT 0.7.1 SVN: at Mon Aug 17 22:58:25 EDT 2009