#include <matrix.h>
Inherits Storeable.

Public Member Functions | |
| Matrix () | |
| default constructor: zero matrix (0x0) | |
| Matrix (I _m, I _n, const D *_data=0) | |
| constucts a matrix with the given size. | |
| Matrix (I _m, I _n, D def) | |
| constucts a matrix with the given size and fills it with the default value | |
| Matrix (const Matrix &c) | |
| constucts a instance on the base of a deep copy of the given matrix | |
| ~Matrix () | |
| I | getM () const |
| I | getN () const |
| I | size () const |
| D | val (I i, I j) const |
| D & | val (I i, I j) |
| D | valDef0 (I i, I j) const |
| void | set (I _m, I _n, const D *_data=0) |
| sets the size of the matrix and maybe the data if given (row-wise). | |
| void | set (const D *_data) |
| sets the data (row-wise). | |
| Matrix | row (I index) const |
| Matrix | rows (I startindex, I endindex) const |
| Matrix | column (I index) const |
| Matrix | columns (I startindex, I endindex) const |
| int | convertToBuffer (D *buffer, I len) const |
| stores the content of the matrix (row-wise) in the given buffer | |
| std::list< D > | convertToList () const |
| const double * | unsafeGetData () const |
| returns a pointer to the data. UNSAFE!!! | |
| bool | store (FILE *f) const |
| stores the Matrix into the given file stream (binary) | |
| bool | restore (FILE *f) |
| reads a Matrix from the given file stream (binary) | |
| bool | write (FILE *f) const |
| writes the Matrix into the given file stream (ascii) | |
| bool | read (FILE *f) |
| reads a Matrix from the given file stream (ascii) | |
| void | add (const Matrix &a, const Matrix &b) |
| addition: this = a + b | |
| void | add (const Matrix &a, const D &summand) |
| void | sub (const Matrix &a, const Matrix &b) |
| add scalar to each element | |
| void | mult (const Matrix &a, const Matrix &b) |
| multiplication: this = a * b | |
| void | mult (const Matrix &a, const D &fac) |
| scaling: this = a * fac | |
| void | exp (const Matrix &a, int exponent) |
| exponent, this = a^i, | |
| bool | isNulltimesNull () const |
| returns true if matrix is a 0x0 matrix | |
| bool | isVector () const |
| returns true if matrix is a vector | |
| bool | equals (const Matrix &a) const |
| bytewise comparison (compares data buffer bytewise, which implies that n1*m1 == n2*m2 but not necessarily n1==n2) | |
| Matrix | pseudoInverse (const D &lambda=10e-8) const |
| calculates the pseudoinverse, depending on the shape of the matrix the left or right pseudoinverse is used. | |
| Matrix | map (D(*fun)(D)) const |
| maps the matrix to a new matrix with all elements mapped with the given function | |
| Matrix | mapP (D param, D(*fun)(D, D)) const |
| like map but with additional double parameter for the mapping function (first argument of fun is parameter, the second is the value) | |
| Matrix | mapP (void *param, D(*fun)(void *, D)) const |
| like map but with additional arbitrary parameter for the mapping function | |
| Matrix | multrowwise (const Matrix &factors) const |
| row-wise multiplication | |
| Matrix | multcolwise (const Matrix &factors) const |
| column-wise multiplication | |
| Matrix | multMT () const |
| optimised multiplication of Matrix with its transposed: M * M^T | |
| Matrix | multTM () const |
| optimised multiplication of transpsoed of Matrix with itself: M^T * M | |
| D | elementProduct () const |
returns the product of all elements ( ) | |
| D | elementSum () const |
returns the sum of all elements ( ) | |
| Matrix | above (const Matrix &a) const |
| returns a matrix that consists of this matrix above A (number of rows is getM + a.getM()) | |
| Matrix | beside (const Matrix &a) const |
| returns a matrix that consists of this left beside A (number of columns is getN + a.getN()) | |
| Matrix & | operator= (const Matrix &c) |
| deep copy | |
| Matrix | operator+ (const Matrix &sum) const |
| sum of two matrices | |
| Matrix | operator- (const Matrix &sum) const |
| difference of two matrices | |
| Matrix | operator* (const Matrix &fac) const |
| matrix product | |
| Matrix | operator* (const D &fac) const |
| product with scalar (D) (only right side) | |
| Matrix | operator^ (int exponent) const |
| special matrix potence: | |
| Matrix | operator& (const Matrix &b) const |
| row-wise multiplication | |
| Matrix & | operator+= (const Matrix &c) |
| combined assigment operator (higher performance) | |
| Matrix & | operator-= (const Matrix &c) |
| combined assigment operator (higher performance) | |
| Matrix & | operator*= (const Matrix &c) |
| combined assigment operator (higher performance) | |
| Matrix & | operator*= (const D &fac) |
| combined assigment operator (higher performance) | |
| Matrix & | operator&= (const Matrix &c) |
| combined assigment operator (higher performance) | |
| bool | operator== (const Matrix &c) const |
| comparison operator (compares elements with tolerance distance of COMPARE_EPS) | |
| void | copy (const Matrix &c) |
| performs a deep copy of the given matrix | |
| Matrix & | toTranspose () |
| inplace transpose | |
| Matrix & | toZero () |
| inplace converts matrix to zero matrix | |
| Matrix & | toId () |
| inplace converts matrix to identity (use ^0 to get a copy version of it) | |
| Matrix & | toSum (const Matrix &a) |
| inplace addition: this = this + a | |
| Matrix & | toSum (const D &sum) |
| inplace addition: this = this + a, where a is a scalar | |
| Matrix & | toDiff (const Matrix &a) |
| inplace subtraction: this = this - a | |
| Matrix & | toMult (const Matrix &a) |
| inplace multiplication: this = this * a | |
| Matrix & | toMult (const D &fac) |
| inplace multiplication with scalar: this = this*fac | |
| Matrix & | toExp (int exponent) |
| special inplace matrix power: | |
| Matrix & | toMap (D(*fun)(D)) |
| inplace mapping of matrix elements (element-wise application) | |
| Matrix & | toMapP (D param, D(*fun)(D, D)) |
| like toMap, but with an extra double parameter for the mapping function. | |
| Matrix & | toMapP (void *param, D(*fun)(void *, D)) |
| like toMap, but with an extra arbitrary parameter for the mapping function. | |
| Matrix & | toMap2 (D(*fun)(D, D), const Matrix &b) |
| like toMap, but with 2 arguments for the mapping function. | |
| Matrix & | toMap2P (void *param, D(*fun)(void *, D, D), const Matrix &b) |
| Matrix & | toMultrowwise (const Matrix &factors) |
| Inplace row-wise multiplication. | |
| Matrix & | toMultcolwise (const Matrix &factors) |
| Inplace column-wise multiplication. | |
| Matrix & | toAbove (const Matrix &a) |
| sets the matrix a below this matrix | |
| Matrix & | toBeside (const Matrix &a) |
| sets the matrix a right beside this matrix | |
| Matrix & | toSort () |
| sorts the matrix (rowwise) | |
| Matrix & | reshape (I m, I n) |
| reshapes the matrix without destroying the data. | |
| Matrix & | pluslambdaI (double lambda) |
| adds the given value to the diagonal | |
| Matrix & | addRows (I numberRows, const D *_data=0) |
| adds one or more rows to the existing matrix and fills it with the given data | |
| Matrix & | addRows (I numberRows, const Matrix &dataMatrix) |
| same as toAbove(dataMatrix) | |
| Matrix & | addColumns (I numberColumns, const D *_data=0) |
| adds one or more columns to the existing matrix same as toBeside(Matrix(getM, numberColumns, _data)) | |
| Matrix & | addColumns (I numberColumns, const Matrix &dataMatrix) |
| same as toBeside(dataMatrix) | |
| Matrix & | removeRows (I numberRows) |
| removes one or more rows of the existing matrix, same as reshape(getM()-numberRows, getN()); | |
| Matrix & | removeColumns (I numberColumns) |
| removes one or more columns of the existing matrix resets the size of the matrix and deletes the appropiate data. | |
Static Public Member Functions | |
| static Matrix | map2 (D(*fun)(D, D), const Matrix &a, const Matrix &b) |
| binary map operator for matrices. | |
| static Matrix | map2P (void *param, D(*fun)(void *, D, D), const Matrix &a, const Matrix &b) |
| binary map operator for matrices with parameter. | |
Friends | |
| std::ostream & | operator<< (std::ostream &, const Matrix &) |
| printing operator: output format: mxn ( row0 . | |
Type D is datatype of matrix elements, which is fixed to double. Type I is the indextype of matrix elements, which is fixed to unsigned int, if AVR is not defined. There are basicly two different types of operation: Inplace operations and copy operations. Please use the latter ones unless you know what you are doing. Just in case of critical performance optimisation use the inplace operations. The most convinient way is to use the overloaded operators (like + * ...). All constructed matrices are initialised with zero elements (unless data is given). All functions perform range checks if in debug mode (NDEBUG is not defined). Please use debug the version (default) for testing
constucts a matrix with the given size and fills it with the default value
| ~Matrix | ( | ) | [inline] |
same as toBeside(dataMatrix)
| numberColumns | number of columns to add (unused) | |
| dataMatrix | matrix which contains the data of the new rows |
adds one or more columns to the existing matrix same as toBeside(Matrix(getM, numberColumns, _data))
| numberColumns | number of columns to add (this extends n) | |
| _data | data to add |
| D elementProduct | ( | ) | const |
returns the product of all elements (
)
returns the product of all elements
| D elementSum | ( | ) | const |
returns the sum of all elements (
)
returns the sum of all elements
| bool equals | ( | const Matrix & | a | ) | const |
bytewise comparison (compares data buffer bytewise, which implies that n1*m1 == n2*m2 but not necessarily n1==n2)
| I getM | ( | ) | const [inline] |
| I getN | ( | ) | const [inline] |
| bool isNulltimesNull | ( | ) | const |
| bool isVector | ( | ) | const |
returns true if matrix is a vector
maps the matrix to a new matrix with all elements mapped with the given function
binary map operator for matrices.
The resulting matrix consists of the function values applied to the elements of a and b. In haskell this would something like: map (uncurry . fun) $ zip a b
binary map operator for matrices with parameter.
The resulting matrix consists of the function values applied to the elements of a and b. In haskell this would something like: map (uncurry . (fun p)) $ zip a b
like map but with additional arbitrary parameter for the mapping function
like map but with additional double parameter for the mapping function (first argument of fun is parameter, the second is the value)
column-wise multiplication
| factors | column vector (Mx1) of factors, one for each column |
row-wise multiplication
| factors | column vector (Mx1) of factors, one for each row |
product with scalar (D) (only right side)
product with scalar (double)
| bool operator== | ( | const Matrix & | c | ) | const |
comparison operator (compares elements with tolerance distance of COMPARE_EPS)
| Matrix operator^ | ( | int | exponent | ) | const |
| Matrix & pluslambdaI | ( | double | lambda | ) |
adds the given value to the diagonal
| bool read | ( | FILE * | f | ) |
reads a Matrix from the given file stream (ascii)
| bool restore | ( | FILE * | f | ) | [virtual] |
| void set | ( | const D * | _data | ) |
sets the size of the matrix and maybe the data if given (row-wise).
If data=null then the matrix is set to zero
constructor Matrix(m,n,data)
| bool store | ( | FILE * | f | ) | const [virtual] |
add scalar to each element
subtraction: this = a - b
| Matrix & toExp | ( | int | exponent | ) |
| Matrix & toId | ( | ) |
inplace converts matrix to identity (use ^0 to get a copy version of it)
like toMap, but with 2 arguments for the mapping function.
like toMap, but with an extra arbitrary parameter for the mapping function.
like toMap, but with an extra double parameter for the mapping function.
Inplace column-wise multiplication.
| factors | column vector of factors, one for each column |
Inplace row-wise multiplication.
| factors | column vector of factors, one for each row |
| Matrix & toTranspose | ( | ) |
inplace transpose
| const double* unsafeGetData | ( | ) | const [inline] |
returns a pointer to the data. UNSAFE!!!
| bool write | ( | FILE * | f | ) | const |
writes the Matrix into the given file stream (ascii)
| std::ostream& operator<< | ( | std::ostream & | str, | |
| const Matrix & | mat | |||
| ) | [friend] |
printing operator: output format: mxn (
row0
.
.rown
) where rowX is tab seperated list of values
1.5.8