Machine Learning Library
|
Template object implementing a matrix of single and double precision elements. More...
#include <CDenseVector.h>
Public Member Functions | |
CMatrix (int iRows=0, int iColumns=0, bool bInitialize=false) | |
CMatrix (const CMatrix< Type > &rtMatrix) | |
~CMatrix () | |
CMatrix< Type > & | operator= (const CMatrix< Type > &rtSrc) |
void | resize (int iRows, int iCols, bool bPreserveData=false) |
int | rows () const |
virtual string | className () const |
Returns the class name. More... | |
int | columns () const |
const Type & | getElement (int i, int j) const |
Type & | operator() (int i, int j) |
CMatrix< Type > | operator() (int i, int j, int rn, int cn) const |
void | insert (int i, int j, const CMatrix< Type > &rtSubmatrix) |
void | setElement (int i, int j, const Type &tValue) |
Type | determinant () const |
Type | trace () const |
Type | sumElements () const |
CDenseVector< Type > | getRow (int iRow) const |
CDenseVector< Type > | getColumn (int iColumn) const |
CDenseVector< Type > | getDiagonal () const |
Type | minElement (int &rtX, int &rtY) const |
Type | maxElement (int &rtX, int &rtY) const |
void | operator*= (Type rScalar) |
void | operator+= (Type rScalar) |
void | operator-= (Type rScalar) |
void | operator/= (Type rScalar) |
void | operator+= (const CMatrix< Type > &tM) |
void | operator-= (const CMatrix< Type > &tM) |
void | setRow (int iRow, const CDenseVector< Type > &tVec) |
void | setColumn (int iIndex, CDenseVector< Type > &tVec) |
void | setDiagonal (Type tValue) |
void | setDiagonal (CDenseVector< Type > &tDiag) |
Type | frobeniusNorm () |
CMatrix< Type > | transpose () |
bool | isNaN () const |
CMatrix< Type > | invert () const |
void | dump (ostream &stream=cout) |
bool | serialize (fstream &stream, IO_MODE=READ) |
Read/write from binary stream. More... | |
bool | serialize2 (CArchiv &tArchiv) |
void | zeros () |
void | setData (Type *ptData, bool bColumnMajorOrder=false) |
bool | exportToMatFile (const char *acPath, const char *acVarame, bool bAppend=true) |
int | importFromMatFile (const char *acPath, const char *acVarname) |
void | replicateMatrix (int iX, int iY, const CMatrix< Type > &tMat) |
Type * | _data () |
int | eig (CDenseVector< Type > &rtEigenvalues, CMatrix< Type > &rtEigenvectors, int iNum=0, TMatrixType tType=SYMETRIC) |
int | calcLUFactorization (CMatrix< Type > &rtL, CMatrix< Type > &rtU, CDenseVector< int > &rtIdx) const |
![]() | |
CObject () | |
Constructor. More... | |
virtual | ~CObject () |
Destructor. More... | |
void | setVerbose (VERBOSE_LEVEL tVerbose) |
Set the verbose level. More... | |
VERBOSE_LEVEL | verbose (void) const |
Return current verbose level. More... | |
virtual bool | isA (const char *acClass) const |
Check if the object is an instance of the class with given name. More... | |
DATATYPE | dataType () const |
Returns the template data type. More... | |
Protected Attributes | |
int | iRows |
int | iCols |
Type * | ptData |
![]() | |
unsigned char | ucVerbose |
Friends | |
CMatrix< Type > | operator+ (const CMatrix< Type > &rtMat1, const CMatrix< Type > &rtMat2) |
CMatrix< Type > | operator- (const CMatrix< Type > &rtMat1, const CMatrix< Type > &rtMat2) |
CMatrix< Type > | elementMul (const CMatrix< Type > &rtMat1, const CMatrix< Type > &rtMat2) |
CMatrix< Type > | elementDiv (const CMatrix< Type > &rtMat1, const CMatrix< Type > &rtMat2) |
CMatrix< Type > | operator* (const CMatrix< Type > &tMat1, const CMatrix< Type > &tMat2) |
CMatrix< Type > | operator+ (const CMatrix< Type > &rtMat, const Type &rtScalar) |
CMatrix< Type > | operator- (const CMatrix< Type > &rtMat, const Type &rtScalar) |
CMatrix< Type > | operator* (const CMatrix< Type > &rtMat, const Type &rtScalar) |
CMatrix< Type > | operator/ (const CMatrix< Type > &rtMat, const Type &rtScalar) |
CDenseVector< Type > | operator* (const CMatrix< Type > &rtMat, const CVector< Type > &rtVec) |
void | load (CMatrix< Type > &, char *acString) |
void | save (const CMatrix< Type > &, char *acString) |
Template object implementing a matrix of single and double precision elements.
The elements are stored in a C array in column-major order for easy utilization of LAPACK or CBLAS packages.
CMatrix< Type >::CMatrix | ( | int | iRows = 0 , |
int | iColumns = 0 , |
||
bool | bInitialize = false |
||
) |
Constructor – Create a new instance of a matrix object with given size.
iRows | Number of rows (default 0). |
iColumns | Number of columns (default 0). |
bInitialze | If true, matrix will be initialized with 0 (default: false). |
Constructor – Create a new instance of a matrix object which is a clone of a second matrix.
Reference | to matrix which will be cloned |
|
inline |
References CMatrix< Type >::ptData.
int CMatrix< Type >::calcLUFactorization | ( | CMatrix< Type > & | rtL, |
CMatrix< Type > & | rtU, | ||
CDenseVector< int > & | rtIdx | ||
) | const |
LU factorization of matrix
|
inlinevirtual |
Returns the class name.
Reimplemented from CObject< Type >.
|
inline |
Return the number of columns of the matrix.
References CMatrix< Type >::iCols.
Type CMatrix< Type >::determinant | ( | ) | const |
Calculate the determinant of the matrix
void CMatrix< Type >::dump | ( | ostream & | stream = cout | ) |
Dump matrix to stream
int CMatrix< Type >::eig | ( | CDenseVector< Type > & | rtEigenvalues, |
CMatrix< Type > & | rtEigenvectors, | ||
int | iNum = 0 , |
||
TMatrixType | tType = SYMETRIC |
||
) |
Calculate all eigenvalues and eigenvectors of the current matrix. Speifying the type of the matrix can speed-up the calculation significantly. Additionally, only the first iNum vectors can be calculated.
rtEigenvalues | Vector to be filled with eigenvalues in ascending order |
rtEigenvectors | Matrix to be filled with eigenvectors |
iNumDirections | Number of eigenvectors and eigenvalue to calculate |
tType | Matrix type |
bool CMatrix< Type >::exportToMatFile | ( | const char * | acPath, |
const char * | acVarame, | ||
bool | bAppend = true |
||
) |
Export matrix to file MAT-file (Level 1.0)
acPath | Path to MAType file |
acVarname | Variable name in MAType file |
bAppend | If the file already exists, the data is append to the file (Default: true) |
Type CMatrix< Type >::frobeniusNorm | ( | ) |
Calculates the frobenius norm
CDenseVector<Type> CMatrix< Type >::getColumn | ( | int | iColumn | ) | const |
Return a column as a CDenseVector instance.
iColumn | Index of column to return. |
CDenseVector<Type> CMatrix< Type >::getDiagonal | ( | ) | const |
Returns the diagonal of the matrix as a CDenseVector instance.
const Type& CMatrix< Type >::getElement | ( | int | i, |
int | j | ||
) | const |
Return the value of the element in row i column j.
i | Row index. |
j | Column index, |
CDenseVector<Type> CMatrix< Type >::getRow | ( | int | iRow | ) | const |
Return a row as a CDenseVector instance.
iRow | Index of row to return. |
int CMatrix< Type >::importFromMatFile | ( | const char * | acPath, |
const char * | acVarname | ||
) |
void CMatrix< Type >::insert | ( | int | i, |
int | j, | ||
const CMatrix< Type > & | rtSubmatrix | ||
) |
Insert the submatrix starting at row i column j.
i | Row offset. |
j | Column offset. |
rtSubmatrix. |
Calculates the inverse matrix using LU decomposition.
bool CMatrix< Type >::isNaN | ( | ) | const |
Look for NaN elements
Type CMatrix< Type >::maxElement | ( | int & | rtX, |
int & | rtY | ||
) | const |
Get index of max element
rtX | row index of maximal element |
rtY | column index of maximal element |
Type CMatrix< Type >::minElement | ( | int & | rtX, |
int & | rtY | ||
) | const |
Get index of min element
rtX | row index of minimal element |
rtY | column index of minimal element |
Type& CMatrix< Type >::operator() | ( | int | i, |
int | j | ||
) |
Return a reference to the element in row i column j.
i | Row index. |
j | Column index, |
CMatrix<Type> CMatrix< Type >::operator() | ( | int | i, |
int | j, | ||
int | rn, | ||
int | cn | ||
) | const |
Return the submatrix starting at row i column j with extend rn and cn.
i | Row offset. |
j | Column offset. |
rn | Row extend |
cn | Column extend |
void CMatrix< Type >::operator*= | ( | Type | rScalar | ) |
Multiply each element by a scalar
@param tScalar.
void CMatrix< Type >::operator+= | ( | Type | rScalar | ) |
Add scalar to each element
tScalar. |
Add matrix
Matrix. |
void CMatrix< Type >::operator-= | ( | Type | rScalar | ) |
Subtract from to each element
tScalar. |
Subtract matrix
Matrix. |
void CMatrix< Type >::operator/= | ( | Type | rScalar | ) |
Divied each element by tScalar
tScalar. |
Assign matrix instance to a matrix variable.
Matrix. |
void CMatrix< Type >::replicateMatrix | ( | int | iX, |
int | iY, | ||
const CMatrix< Type > & | tMat | ||
) |
Fill the matrix with a iX x iY mosaic of replicates of the matrix tMat
iX | X size of mosaic |
iY | Y size of mosaic |
tMat | Single mosaic block |
void CMatrix< Type >::resize | ( | int | iRows, |
int | iCols, | ||
bool | bPreserveData = false |
||
) |
Resize matrix.
iRows | Number of rows. |
iCols | Number of columns. |
If | true, current matrix data is preserved |
|
inline |
|
virtual |
Read/write from binary stream.
The functions handles different data types e.g for reading float objects in a double instance, etc.
fstream | Reference to binary stream |
mode | Switches between reading and writing |
Reimplemented from CObject< Type >.
Reimplemented from CObject< Type >.
void CMatrix< Type >::setColumn | ( | int | iIndex, |
CDenseVector< Type > & | tVec | ||
) |
Fill column iColumn with data given by a vector
iColumn | Index of column to fill. |
Vector | containing the new column data. |
void CMatrix< Type >::setData | ( | Type * | ptData, |
bool | bColumnMajorOrder = false |
||
) |
Fill matrix with data fromm array.
ptData | Array of size rows() * cols() with data |
bColumnMajorOrder | If true, data is assumed to be in column-major order, row-major order otherwise (default: false) |
void CMatrix< Type >::setDiagonal | ( | Type | tValue | ) |
Set each elements of the diagonal to tValue
tValue | Value. |
void CMatrix< Type >::setDiagonal | ( | CDenseVector< Type > & | tDiag | ) |
Fill matrix dagonal with data from vector
Reference | to vector with new diagonal elements |
void CMatrix< Type >::setElement | ( | int | i, |
int | j, | ||
const Type & | tValue | ||
) |
Assign a new value to the element in row i column j.
i | Row index. |
j | Column index, |
tValue | New value of element. |
void CMatrix< Type >::setRow | ( | int | iRow, |
const CDenseVector< Type > & | tVec | ||
) |
Fill row iRow with data given by a vector
iRow | Index of row to fill. |
Vector | containing the new row data. |
Referenced by CDataset< Type >::getInputMatrix(), and CDataset< Type >::getOutputMatrix().
Type CMatrix< Type >::sumElements | ( | ) | const |
Sum elements
Type CMatrix< Type >::trace | ( | ) | const |
Calculate the trace of the matrix.
Transposes the matrix.
|
inline |
Fills matrix with 0
References CMatrix< Type >::iCols, CMatrix< Type >::iRows, and CMatrix< Type >::ptData.
|
friend |
Elementwise division of two matrices with returned result.
|
friend |
Elementwise multiplication of two matrices with returned result.
|
friend |
Load matrix
|
friend |
Multiplication of two matrices with returned result.
|
friend |
Multiplication of a scalar with each element with returned result.
|
friend |
Vector matrix multiplication
|
friend |
Elementwise addition of two matrices with returned result.
|
friend |
Addition of a scalar to each element with returned result. ^
|
friend |
Elementwise subtraction of two matrices with returned result.
|
friend |
Subtraction of a scalar from each element with returned result.
|
friend |
Division of each element by a scalar with returned result.
|
friend |
Save matrix
|
protected |
Number of columns
Referenced by CMatrix< Type >::columns(), and CMatrix< Type >::zeros().
|
protected |
Number of rows
Referenced by CMatrix< Type >::rows(), and CMatrix< Type >::zeros().
|
protected |
Data storage / column-major order
Referenced by CMatrix< Type >::_data(), and CMatrix< Type >::zeros().