GestureRecognitionToolkit  Version: 0.1.0
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
MatrixFloat Class Reference
Inheritance diagram for MatrixFloat:
Matrix< Float >

Public Member Functions

 MatrixFloat ()
 
 MatrixFloat (const unsigned int rows, const unsigned int cols)
 
 MatrixFloat (const MatrixFloat &rhs)
 
 MatrixFloat (const Matrix< Float > &rhs)
 
virtual ~MatrixFloat ()
 
MatrixFloatoperator= (const MatrixFloat &rhs)
 
MatrixFloatoperator= (const Matrix< Float > &rhs)
 
MatrixFloatoperator= (const Vector< VectorFloat > &rhs)
 
VectorFloat getRow (const unsigned int r) const
 
VectorFloat getCol (const unsigned int c) const
 
bool save (const std::string &filename) const
 
bool load (const std::string &filename, const char seperator= ',')
 
bool saveToCSVFile (const std::string &filename) const
 
bool loadFromCSVFile (const std::string &filename, const char seperator= ',')
 
bool print (const std::string title="") const
 
bool transpose ()
 
bool scale (const Float minTarget, const Float maxTarget)
 
bool scale (const Vector< MinMax > &ranges, const Float minTarget, const Float maxTarget)
 
bool znorm (const Float alpha=0.001)
 
MatrixFloat multiple (const Float value) const
 
VectorFloat multiple (const VectorFloat &b) const
 
MatrixFloat multiple (const MatrixFloat &b) const
 
bool multiple (const MatrixFloat &a, const MatrixFloat &b, const bool aTranspose=false)
 
bool add (const MatrixFloat &b)
 
bool add (const MatrixFloat &a, const MatrixFloat &b)
 
bool subtract (const MatrixFloat &b)
 
bool subtract (const MatrixFloat &a, const MatrixFloat &b)
 
Float getMinValue () const
 
Float getMaxValue () const
 
VectorFloat getMean () const
 
VectorFloat getStdDev () const
 
MatrixFloat getCovarianceMatrix () const
 
Vector< MinMaxgetRanges () const
 
Float getTrace () const
 
- Public Member Functions inherited from Matrix< Float >
 Matrix ()
 
 Matrix (const unsigned int rows, const unsigned int cols)
 
 Matrix (const Matrix &rhs)
 
 Matrix (const Vector< Vector< Float > > &data)
 
virtual ~Matrix ()
 
Matrixoperator= (const Matrix &rhs)
 
Float * operator[] (const unsigned int r)
 
const Float * operator[] (const unsigned int r) const
 
Vector< Float > getRowVector (const unsigned int r) const
 
Vector< Float > getColVector (const unsigned int c) const
 
Vector< Float > getConcatenatedVector (const bool concatByRow=true) const
 
virtual bool resize (const unsigned int r, const unsigned int c)
 
virtual bool copy (const Matrix< Float > &rhs)
 
bool setAllValues (const Float &value)
 
bool setAll (const Float &value)
 
bool setRowVector (const Vector< Float > &row, const unsigned int rowIndex)
 
bool setColVector (const Vector< Float > &column, const unsigned int colIndex)
 
bool push_back (const Vector< Float > &sample)
 
bool reserve (const unsigned int capacity)
 
void clear ()
 
unsigned int getNumRows () const
 
unsigned int getNumCols () const
 
unsigned int getCapacity () const
 
unsigned int getSize () const
 
Float ** getDataPointer () const
 
Float * getData () const
 

Protected Member Functions

Float stringToFloat (const std::string &value)
 

Protected Attributes

WarningLog warningLog
 
ErrorLog errorLog
 
- Protected Attributes inherited from Matrix< Float >
unsigned int rows
 The number of rows in the Matrix.
 
unsigned int cols
 The number of columns in the Matrix.
 
unsigned int size
 Stores rows * cols.
 
unsigned int capacity
 The capacity of the Matrix, this will be the number of rows, not the actual memory size.
 
Float * dataPtr
 A pointer to the raw data.
 
Float ** rowPtr
 A pointer to each row in the data.
 
ErrorLog errorLog
 

Detailed Description

Definition at line 36 of file MatrixFloat.h.

Constructor & Destructor Documentation

GRT_BEGIN_NAMESPACE MatrixFloat::MatrixFloat ( )

Default Constructor

Definition at line 25 of file MatrixFloat.cpp.

MatrixFloat::MatrixFloat ( const unsigned int  rows,
const unsigned int  cols 
)

Constructor, sets the size of the matrix to [rows cols]

Parameters
constUINT rows: sets the number of rows in the matrix, must be a value greater than zero
constUINT cols: sets the number of columns in the matrix, must be a value greater than zero

Definition at line 33 of file MatrixFloat.cpp.

MatrixFloat::MatrixFloat ( const MatrixFloat rhs)

Copy Constructor, copies the values from the rhs MatrixFloat to this MatrixFloat instance

Parameters
constMatrixFloat &rhs: the MatrixFloat from which the values will be copied

Definition at line 42 of file MatrixFloat.cpp.

MatrixFloat::MatrixFloat ( const Matrix< Float > &  rhs)

Copy Constructor, copies the values from the rhs Matrix to this MatrixFloat instance

Parameters
constMatrix< Float > &rhs: the Matrix from which the values will be copied

Definition at line 50 of file MatrixFloat.cpp.

MatrixFloat::~MatrixFloat ( )
virtual

Destructor, cleans up any memory

Definition at line 58 of file MatrixFloat.cpp.

Member Function Documentation

bool MatrixFloat::add ( const MatrixFloat b)

Adds the input matrix data (b) to this matrix (a), giving: a = a + b. This rows and cols of b must match that of this matrix.

Parameters
athe matrix to multiple with b
bthe matrix to multiple with a
aTransposea flag to indicate if matrix a should be transposed
Returns
true if the operation was completed successfully, false otherwise

Definition at line 310 of file MatrixFloat.cpp.

bool MatrixFloat::add ( const MatrixFloat a,
const MatrixFloat b 
)

Adds the input matrix data (a) to the input matrix (b), storing the data in this matrix (c) giving: c = a + b. The rows and cols in a and b must match. This will resize the current matrix if needed.

Parameters
athe matrix to add with b
bthe matrix to add with a
Returns
true if the operation was completed successfully, false otherwise

Definition at line 334 of file MatrixFloat.cpp.

VectorFloat MatrixFloat::getCol ( const unsigned int  c) const
inline

Gets a column vector [rows 1] from the Matrix at the column index c

Parameters
cthe index of the column, this should be in the range [0 cols-1]
Returns
returns a column vector from the Matrix at the column index c

Definition at line 113 of file MatrixFloat.h.

MatrixFloat MatrixFloat::getCovarianceMatrix ( ) const

Gets the covariance matrix of this matrix and returns this as a MatrixFloat.

Returns
a MatrixFloat with the covariance matrix of this matrix

Definition at line 473 of file MatrixFloat.cpp.

Float MatrixFloat::getMaxValue ( ) const

Gets the ranges max value throughout the entire matrix.

Returns
a Float value containing the maximum matrix value

Definition at line 436 of file MatrixFloat.cpp.

VectorFloat MatrixFloat::getMean ( ) const

Gets the mean of each column in the matrix and returns this as a VectorFloat.

Returns
a VectorFloat with the mean of each column

Definition at line 444 of file MatrixFloat.cpp.

Float MatrixFloat::getMinValue ( ) const

Gets the ranges min value throughout the entire matrix.

Returns
a Float value containing the minimum matrix value

Definition at line 428 of file MatrixFloat.cpp.

Vector< MinMax > MatrixFloat::getRanges ( ) const

Gets the ranges (min and max values) of each column in the matrix.

Returns
a vector with the ranges (min and max values) of each column in the matrix

Definition at line 491 of file MatrixFloat.cpp.

VectorFloat MatrixFloat::getRow ( const unsigned int  r) const
inline

Gets a row vector [1 cols] from the Matrix at the row index r

Parameters
rthe index of the row, this should be in the range [0 rows-1]
Returns
returns a row vector from the Matrix at the row index r

Definition at line 100 of file MatrixFloat.h.

VectorFloat MatrixFloat::getStdDev ( ) const

Gets the standard deviation of each column in the matrix and returns this as a VectorFloat.

Returns
a VectorFloat with the standard deviation of each column

Definition at line 459 of file MatrixFloat.cpp.

Float MatrixFloat::getTrace ( ) const

Gets the trace of this matrix.

Returns
the trace of this matrix as a Float

Definition at line 504 of file MatrixFloat.cpp.

bool MatrixFloat::load ( const std::string &  filename,
const char  seperator = ',' 
)

Loads a matrix from a CSV file. This assumes that the data has been saved as rows and columns in the CSV file and that there are an equal number of columns per row.

This replaces the deprecated loadFromCSVFile function.

Parameters
filenamethe name of the CSV file
Returns
returns true or false, indicating if the data was loaded successful

Definition at line 532 of file MatrixFloat.cpp.

bool MatrixFloat::loadFromCSVFile ( const std::string &  filename,
const char  seperator = ',' 
)

Loads a matrix from a CSV file. This assumes that the data has been saved as rows and columns in the CSV file and that there are an equal number of columns per row.

Parameters
filenamethe name of the CSV file
Returns
returns true or false, indicating if the data was loaded successful

Definition at line 640 of file MatrixFloat.cpp.

MatrixFloat MatrixFloat::multiple ( const Float  value) const

Performs the multiplication of the data by the scalar value.

Returns
returns a new MatrixFloat with the results from the multiplcation

Definition at line 190 of file MatrixFloat.cpp.

VectorFloat MatrixFloat::multiple ( const VectorFloat b) const

Performs the multiplcation of this matrix (a) by the vector b. This will return a new vector (c): c = a * b

Parameters
bthe vector to multiple with this matrix
Returns
a VectorFloat with the results from the multiplcation

Definition at line 205 of file MatrixFloat.cpp.

MatrixFloat MatrixFloat::multiple ( const MatrixFloat b) const

Performs the multiplcation of this matrix (a) by the matrix b. This will return a new matrix (c): c = a * b

Parameters
bthe matrix to multiple with this matrix
Returns
a new MatrixFloat with the results from the multiplcation

Definition at line 231 of file MatrixFloat.cpp.

bool MatrixFloat::multiple ( const MatrixFloat a,
const MatrixFloat b,
const bool  aTranspose = false 
)

Performs the multiplcation of the matrix a by the matrix b, directly storing the new data in the this matrix instance. This will resize the current matrix if needed. This makes this matrix c and gives: c = a * b, or if the aTransposed value is true: c = a' * b

Parameters
athe matrix to multiple with b
bthe matrix to multiple with a
aTransposea flag to indicate if matrix a should be transposed
Returns
true if the operation was completed successfully, false otherwise

Definition at line 260 of file MatrixFloat.cpp.

MatrixFloat & MatrixFloat::operator= ( const MatrixFloat rhs)

Defines how the data from the rhs MatrixFloat should be copied to this MatrixFloat

Parameters
rhsanother instance of a MatrixFloat
Returns
returns a reference to this instance of the MatrixFloat

Definition at line 62 of file MatrixFloat.cpp.

MatrixFloat & MatrixFloat::operator= ( const Matrix< Float > &  rhs)

Defines how the data from the rhs Matrix< Float > should be copied to this MatrixFloat

Parameters
rhsan instance of a Matrix< Float >
Returns
returns a reference to this instance of the MatrixFloat

Definition at line 70 of file MatrixFloat.cpp.

MatrixFloat & MatrixFloat::operator= ( const Vector< VectorFloat > &  rhs)

Defines how the data from the rhs Vector of VectorFloats should be copied to this MatrixFloat

Parameters
rhsa Vector of VectorFloats
Returns
returns a reference to this instance of the MatrixFloat

Definition at line 78 of file MatrixFloat.cpp.

bool MatrixFloat::print ( const std::string  title = "") const

Prints the MatrixFloat contents to std::cout

Parameters
titlesets the title of the data that will be printed to std::cout
Returns
returns true or false, indicating if the print was successful

Definition at line 101 of file MatrixFloat.cpp.

bool MatrixFloat::save ( const std::string &  filename) const

Resizes the MatrixFloat to the new size of [rows cols]

Parameters
rowsthe number of rows, must be greater than zero
colsthe number of columns, must be greater than zero
Returns
returns true or false, indicating if the resize was successful Saves the matrix to a CSV file. This replaces the deprecated saveToCSVFile function.
Parameters
filenamethe name of the CSV file
Returns
returns true or false, indicating if the data was saved successful

Definition at line 513 of file MatrixFloat.cpp.

bool MatrixFloat::saveToCSVFile ( const std::string &  filename) const

Saves the matrix to a CSV file.

Parameters
filenamethe name of the CSV file
Returns
returns true or false, indicating if the data was saved successful

Definition at line 636 of file MatrixFloat.cpp.

bool MatrixFloat::scale ( const Float  minTarget,
const Float  maxTarget 
)

Scales the matrix to a new range given by the min and max targets.

Returns
returns true if the matrix was scaled, false otherwise

Definition at line 134 of file MatrixFloat.cpp.

bool MatrixFloat::scale ( const Vector< MinMax > &  ranges,
const Float  minTarget,
const Float  maxTarget 
)

Scales the matrix to a new range given by the min and max targets using the ranges as the source ranges.

Returns
returns true if the matrix was scaled, false otherwise

Definition at line 143 of file MatrixFloat.cpp.

bool MatrixFloat::subtract ( const MatrixFloat b)

Subtracts the input matrix data (b) from this matrix (a), giving: a = a - b. This rows and cols of b must match that of this matrix.

Parameters
athe matrix to subtract from this instance
Returns
true if the operation was completed successfully, false otherwise

Definition at line 367 of file MatrixFloat.cpp.

bool MatrixFloat::subtract ( const MatrixFloat a,
const MatrixFloat b 
)

Subtracts the input matrix data (b) from this matrix (a), giving (c): c = a - b. This rows and cols of b must match that of this matrix. This will resize the current matrix if needed.

Parameters
athe matrix to subtract with b
bthe matrix to subtract from a
Returns
true if the operation was completed successfully, false otherwise

Definition at line 394 of file MatrixFloat.cpp.

bool MatrixFloat::transpose ( )

Transposes the data.

Returns
returns true or false, indicating if the transpose was successful

Definition at line 118 of file MatrixFloat.cpp.

bool MatrixFloat::znorm ( const Float  alpha = 0.001)

Normalizes each row in the matrix by subtracting the row mean and dividing by the row standard deviation. A small amount (alpha) is added to the standard deviation to stop the normalization from exploding.

Parameters
alphaa small value that will be added to the standard deviation
Returns
returns true if the matrix was normalized, false otherwise

Definition at line 159 of file MatrixFloat.cpp.


The documentation for this class was generated from the following files: