BIAS::Matrix< T > Class Template Reference
[Matrix and Vector Classes]

matrix class with arbitrary size, indexing is row major. More...

#include <Base/Math/Matrix.hh>

Inheritance diagram for BIAS::Matrix< T >:

Inheritance graph
[legend]
Collaboration diagram for BIAS::Matrix< T >:

Collaboration graph
[legend]

List of all members.

Public Types

typedef const Tconst_iterator
typedef const Tconst_reference
typedef T element_type
typedef Titerator
typedef Tpointer
typedef Treference
typedef Subscript size_type
typedef T value_type

Public Member Functions

Matrix< TAdjoint () const
 computes the adjoint matrix
Subscript dim (Subscript d) const
void GaussJordan ()
 use the Gauss Jordan Algrithm to transform the matrix to reduced row echelon form.
template<>
void GetAbsMaxMin (double &max, double &min) const
template<>
bool IsIdentity (double eps) const
bool IsIdentity (double eps=0.0) const
 Checks if the matrix a an identity.
template<>
bool IsZero (double eps) const
bool IsZero (double eps=0.0) const
 Checks if the matrix is a null matrix.
void Kronecker (Matrix< T > const B, Matrix< T > &dest) const
 Kronecker-product with matrix, result in dest.
Subscript lbound () const
 Matrix (const Vector< T > &v)
 constructs Nx1 Matrix from N-Vector
 Matrix (const TNT::Matrix< T > &A)
 Matrix (const Matrix< T > &A)
 Matrix (const int rows, const int cols, const std::string &s)
 DEPRECATED due to instantiation problem.
 Matrix (int rows, int cols, const MatrixInitType &i)
 init with standard form
 Matrix (int rows, int cols, const T value)
 assignment with a constant values for all elements (=set)
 Matrix (int rows, int cols)
 Matrix (const Matrix3x3< T > &mat)
 Matrix ()
Matrix< T > & newsize (Subscript M, Subscript N)
Subscript num_cols () const
Subscript num_rows () const
const_reference operator() (Subscript i, Subscript j) const
reference operator() (Subscript i, Subscript j)
const_reference operator() (Subscript i) const
reference operator() (Subscript i)
const Toperator[] (Subscript i) const
Toperator[] (Subscript i)
std::ostream & Print (std::ostream &s, const bool intCastOutput=false, const bool binaryOutput=false, const bool forceFullPrecision=false) const
std::istream & Read (std::istream &s, const bool intCastInput=false, const bool binaryInput=false)
 JW.
Subscript size () const
void SwapRows (const int i, const int r)
 swaps two rows
Matrix< TTranspose () const
 transpose function, storing data destination matrix
void Vec (Vector< T > &dest) const
 vec-operator returns the elements of the matrix columwise as vector
virtual ~Matrix ()
Arithmetic
void Add (const T &scalar, Matrix< T > &dest) const
 addition function, storing data destination matrix
void AddIP (const Matrix< T > &arg)
 Adds arg to this.
void AddIP (const T &scalar)
 in place addition function
void Divide (const T &scalar, Matrix< T > &dest) const
 division function, storing data destination matrix
void DivideIP (const T &scalar)
 in place division function
void GetSystemMatrix (Matrix< T > &dest) const
 compute square system matrix dest = A^T * A
void Mult (const Vector< T > &arg, Vector< T > &result) const
 matrix vector multiplication, result is not allocated
void Mult (const Matrix< T > &arg)
 in Place matrix multiplication this is equal to M = M * arg, but faster
void Mult (const Matrix< T > &arg, Matrix< T > &result) const
 matrix multiplication, result is not allocated
void Multiply (const T &scalar, Matrix< T > &dest) const
 multiplication function, storing data destination matrix
void MultiplyIP (const T &scalar)
 in place multiplication function
void MultLeft (const Vector< T > &arg, Vector< T > &result) const
 vector matrix multiplication result=arg*this.
void MultLeft (const Matrix< T > &arg)
 in Place matrix multiplication this is equal to M = arg*M, but faster
Matrix< T > & operator= (const Matrix< T > &mat)
Matrix< T > & operator= (const TNT::Matrix< T > &mat)
 assignment operators calling corresponding operator from base class if appropriate
void Sub (const T &scalar, Matrix< T > &dest) const
 substraction function, storing data destination matrix
void SubIP (const T &scalar)
 in place subtraction function
void SubIP (const Matrix< T > &arg)
 Subtracts arg from this
this -= arg.
Input / Output
bool BinRead (const char *filename) const
 This method reads a matrix from a given file in binary format.
bool BinWrite (const char *filename) const
 This method writes a matrix to a given file in binary format.
bool Load (const std::string &filename)
 method to load directly from a given filename.
bool Save (const std::string &filename) const
 method to save directly to a given filename.
int WriteMatlab (std::ostream &ostr, const std::string &name) const
 Write the matrix in Matlab format to the given stream.
Set Functions
virtual void clear ()
 stl conform interface destroys Matrix JW
void Fill (const T &scalar)
 Takes the elements of a Vector and put them as diagonal elements into a matrix.
void MakeSymmetric ()
 componentwise: this = 0.5(this + this^T) yields symmetric matrix only allowed for square shaped matrices
void SetIdentity ()
 Converts matrix to identity matrix.
void SetZero ()
 Sets all values to zero.
Get Functions
T DetSquare () const
void GetAbsMaxMin (T &max, T &min) const
 return biggest and smallest absolute values
Vector< TGetCol (const int &col) const
 return a copy of column "col", zero based counting
unsigned int GetCols () const
const TGetData () const
TGetData ()
 get the pointer to the data array of the matrix (for faster direct memeory access)
T ** GetDataArray ()
const T ** GetDataArray () const
 returns zero based arry for data access
T ** GetDataArray1 () const
 returns 1 based array to data access
TGetDataLast ()
const TGetDataLast () const
 Get a pointer to the last data element Do not use this on unitilized matrices with <= on pointers because on an unitilized matrix GetData() will be NULL and last Element < (typically FFFFF8) We don't want an if here for performance reasons of the innerst loop.
T GetMax () const
 Returns the maximum value of the matrix elements.
void GetMaxMin (T &max, T &min) const
 return biggest and smallest entry
T GetMean () const
 Returns the mean value of the matrix elements.
T GetMin () const
 Returns the minimum value of the matrix elements.
int GetNumElements () const
 Returns the total number of elements.
Vector< TGetRow (const int &row) const
 return a copy of row "row" of this matrix, zero based counting
unsigned int GetRows () const
double NormFrobenius () const
 Return Frobenius norm = sqrt(trace(A^t * A)).
T NormL1 () const
 Return the L1 norm: |a| + |b| + |c| + .
double NormL2 () const
 Return the L2 norm: a^2 + b^2 + c^2 + .
void Set (const int row, const int col, const Vector< T > &data)
 Copies the contents of data into this at the position indicated by row and col.
void Set (const int row, const int col, const Matrix< T > &data)
 Copies the contents of data into this at the position indicated by row and col.
void SetCol (const int row, const Vector< T > &data)
 set a col of matrix from vector
void SetRow (const int row, const Vector< T > &data)
 set a row of matrix from vector
void SetTranspose (const int row, const int col, const Vector< T > &data)
 Copies the contents of data into this at the position indicated by row and col.
T Trace () const
Scaling and Normalization
T Normalize ()
 Normalizes the matrix by the entry with the biggest absolute value by dividing all elements with this one.
void NormalizeCols ()
 Normalizes each coloumn to L_2 norm one.
void NormalizeColsToOne (const int norm_row_index)
 divides each column of the matrix through the element norm_row_index.
void NormalizeRows ()
 Normalizes each row to L2 norm one.
void NormalizeRowsToOne (const int norm_col_index)
 divides each row of the matrix through the element norm_col_index.
void ScaleCol (int NoCol, T scale)
 Scales column NoCol with scale.
void ScaleRow (int NoRow, T scale)
 Scales row NoRow with scale.

Protected Member Functions

void copy (const T *v)
void destroy ()
void initialize (Subscript M, Subscript N)
void set (const T &val)

Protected Attributes

Subscript m_
Subscript mn_
Subscript n_
T ** row_
T ** rowm1_
Tv_
Tvm1_

Related Functions

(Note that these are not member functions.)

template<class T >
void Conv (const Matrix< T > &left, const Matrix< T > &right, Matrix< T > &res)
 zero padded convolution of two matrices
template<class T >
bool operator!= (const Matrix< T > &argl, const Matrix< T > &argr)
template<class T >
Vector< Toperator* (const Matrix< T > &A, const Vector< T > &x)
template<class T >
Matrix< Toperator* (const Matrix< T > &A, const Matrix< T > &B)
template<class T >
Matrix< Toperator* (const Matrix3x3< T > &argLeft, const Matrix< T > &argMat)
template<class T >
Matrix< Toperator* (const T &scalar, const Matrix< T > &mat)
template<class T >
Matrix< Toperator* (const Matrix< T > &mat, const T &scalar)
template<class T >
Matrix< T > & operator*= (Matrix< T > &mat, const T &scalar)
template<class T >
Matrix< Toperator+ (const Matrix< T > &A, const Matrix< T > &B)
template<class T >
Matrix< Toperator+ (const T &scalar, const Matrix< T > &mat)
template<class T >
Matrix< Toperator+ (const Matrix< T > &mat, const T &scalar)
template<class T >
Matrix< T > & operator+= (Matrix< T > &mat, const Matrix< T > &arg)
template<class T >
Matrix< T > & operator+= (Matrix< T > &mat, const T &scalar)
 operators
template<class T >
Matrix< Toperator- (const Matrix< T > &A, const Matrix< T > &B)
template<class T >
Matrix< Toperator- (const T &scalar, const Matrix< T > &mat)
template<class T >
Matrix< Toperator- (const Matrix< T > &mat, const T &scalar)
template<class T >
Matrix< T > & operator-= (Matrix< T > &mat, const T &scalar)
template<class T >
Matrix< T > & operator-= (Matrix< T > &mat, const Matrix< T > &arg)
template<class T >
Matrix< Toperator/ (const Matrix< T > &mat, const T &scalar)
template<class T >
Matrix< T > & operator/= (Matrix< T > &mat, const T &scalar)
template<class T >
std::ostream & operator<< (std::ostream &s, const Matrix< T > &A)
std::ostream & operator<< (std::ostream &s, const Matrix< unsigned char > &A)
std::ostream & operator<< (std::ostream &s, const Matrix< char > &A)
template<class T >
bool operator== (const Matrix< T > &argl, const Matrix< T > &argr)
template<class T >
std::istream & operator>> (std::istream &s, Matrix< T > &A)
std::istream & operator>> (std::istream &s, Matrix< char > &A)
std::istream & operator>> (std::istream &s, Matrix< unsigned char > &A)


Detailed Description

template<class T = double>
class BIAS::Matrix< T >

matrix class with arbitrary size, indexing is row major.


Access the data by M[row][col].

class Matrix is the matrix class that should be used by common BIAS algorithms and data structures with arbitrary size

Access the data simply by M[row][col].

It is derived from TNT::Matrix to inherit the basic operations and algorithm. special implementations should be done here and NOT in TNT:Matrix because the true 'base' Matrix class "TNT::Matrix" should be interchangeable and aside from this maintained by NIST.

Note the specialized fixed size classes Matrix3x3, Matrix3x4, ... with more efficient memory layout.

moved from MIP to BIAS (11/05/2002) operators are no longer class members, they are defined outside the class.

Author:
Jan Woetzel, woelk

Definition at line 86 of file Matrix.hh.


Member Typedef Documentation

template<class T >
typedef const T* TNT::Matrix< T >::const_iterator [inherited]

Definition at line 77 of file cmat.h.

template<class T >
typedef const T& TNT::Matrix< T >::const_reference [inherited]

Definition at line 78 of file cmat.h.

template<class T >
typedef T TNT::Matrix< T >::element_type [inherited]

Definition at line 73 of file cmat.h.

template<class T >
typedef T* TNT::Matrix< T >::iterator [inherited]

Definition at line 75 of file cmat.h.

template<class T >
typedef T* TNT::Matrix< T >::pointer [inherited]

Definition at line 74 of file cmat.h.

template<class T >
typedef T& TNT::Matrix< T >::reference [inherited]

Definition at line 76 of file cmat.h.

template<class T >
typedef Subscript TNT::Matrix< T >::size_type [inherited]

Definition at line 71 of file cmat.h.

template<class T >
typedef T TNT::Matrix< T >::value_type [inherited]

Definition at line 72 of file cmat.h.


Constructor & Destructor Documentation

template<class T >
BIAS::Matrix< T >::~Matrix (  )  [inline, virtual]

Reimplemented from TNT::Matrix< T >.

Definition at line 60 of file Matrix.cpp.

template<class T = double>
BIAS::Matrix< T >::Matrix (  )  [inline]

Reimplemented from TNT::Matrix< T >.

Definition at line 91 of file Matrix.hh.

template<class T >
BIAS::Matrix< T >::Matrix ( const Matrix3x3< T > &  mat  )  [inline, explicit]

Definition at line 69 of file Matrix.cpp.

References r.

template<class T = double>
BIAS::Matrix< T >::Matrix ( int  rows,
int  cols 
) [inline]

Author:
Jan Woetzel

Definition at line 97 of file Matrix.hh.

template<class T = double>
BIAS::Matrix< T >::Matrix ( int  rows,
int  cols,
const T  value 
) [inline]

assignment with a constant values for all elements (=set)

Author:
Jan Woetzel

Definition at line 101 of file Matrix.hh.

template<class T = double>
BIAS::Matrix< T >::Matrix ( int  rows,
int  cols,
const MatrixInitType i 
) [inline]

init with standard form

Author:
koeser

Definition at line 106 of file Matrix.hh.

template<class T >
BIAS::Matrix< T >::Matrix ( const int  rows,
const int  cols,
const std::string &  s 
) [inline, explicit]

DEPRECATED due to instantiation problem.

Author:
Jan Woetzel replacement for the above to be called as Matrix<>(2,3, "1 2 3 4 5 6")

Jan Woetzel

Definition at line 64 of file Matrix.cpp.

template<class T = double>
BIAS::Matrix< T >::Matrix ( const Matrix< T > &  A  )  [inline]

Author:
Jan Woetzel

Definition at line 130 of file Matrix.hh.

template<class T = double>
BIAS::Matrix< T >::Matrix ( const TNT::Matrix< T > &  A  )  [inline]

Author:
Jan Woetzel

Reimplemented from TNT::Matrix< T >.

Definition at line 133 of file Matrix.hh.

template<class T = double>
BIAS::Matrix< T >::Matrix ( const Vector< T > &  v  )  [inline]

constructs Nx1 Matrix from N-Vector

Definition at line 136 of file Matrix.hh.


Member Function Documentation

template<class T >
void BIAS::Matrix< T >::Add ( const T scalar,
Matrix< T > &  dest 
) const [inline]

addition function, storing data destination matrix

implementation

Author:
Ingo Thomsen tested

Definition at line 668 of file Matrix.hh.

References BIAS::Matrix< T >::GetData(), BIAS::Matrix< T >::GetDataLast(), TNT::Matrix< T >::newsize(), TNT::Matrix< T >::num_cols(), TNT::Matrix< T >::num_rows(), and T.

Referenced by BIAS::Matrix< T >::operator+().

template<class T >
void BIAS::Matrix< T >::AddIP ( const Matrix< T > &  arg  )  [inline]

Adds arg to this.

Author:
grest,2004

Definition at line 907 of file Matrix.hh.

References BIASABORT, BIASERR, BIAS::Matrix< T >::GetData(), TNT::Matrix< T >::num_cols(), TNT::Matrix< T >::num_rows(), TNT::Matrix< T >::size(), and T.

template<class T = double>
void BIAS::Matrix< T >::AddIP ( const T scalar  )  [inline]

in place addition function

Author:
Ingo Thomsen tested

Definition at line 339 of file Matrix.hh.

Referenced by BIAS::Matrix< T >::operator+=(), and BIAS::Matrix< T >::operator-=().

template<class T >
Matrix< T > BIAS::Matrix< T >::Adjoint (  )  const [inline]

computes the adjoint matrix

Author:
Christian Beder

Definition at line 734 of file Matrix.hh.

References BIASASSERT, BIAS::Matrix< T >::DetSquare(), j, TNT::Matrix< T >::num_cols(), TNT::Matrix< T >::num_rows(), and r.

template<class T >
bool BIAS::Matrix< T >::BinRead ( const char *  filename  )  const [inline]

This method reads a matrix from a given file in binary format.

The file is not human read-/editable but provides full precision. A dimension check is performed.

Returns:
true on success
Author:
mdunda 04 2004

Definition at line 425 of file Matrix.cpp.

References BIASERR, j, TNT::Matrix< T >::m_, TNT::Matrix< T >::n_, and T.

template<class T >
bool BIAS::Matrix< T >::BinWrite ( const char *  filename  )  const [inline]

This method writes a matrix to a given file in binary format.

The file is not human read-/editable but provides full precision.

Returns:
true on success
Author:
mdunda 04 2004

Definition at line 460 of file Matrix.cpp.

References j, TNT::Matrix< T >::m_, TNT::Matrix< T >::n_, and T.

template<class T = double>
virtual void BIAS::Matrix< T >::clear (  )  [inline, virtual]

template<class T >
void TNT::Matrix< T >::copy ( const T v  )  [inline, protected, inherited]

template<class T >
void TNT::Matrix< T >::destroy (  )  [inline, protected, inherited]

template<class T = double>
T BIAS::Matrix< T >::DetSquare (  )  const [inline]

Author:
koeser
Warning:
very slow, generic implementation (order "n!"), better to use matrix decomposition (see BIAS/MathAlgo/Lapack.hh)

Definition at line 293 of file Matrix.hh.

Referenced by BIAS::Matrix< T >::Adjoint(), and BIAS::Matrix< EP_TYPE >::DetSquare().

template<class T >
Subscript TNT::Matrix< T >::dim ( Subscript  d  )  const [inline, inherited]

Definition at line 309 of file cmat.h.

template<class T >
void BIAS::Matrix< T >::Divide ( const T scalar,
Matrix< T > &  dest