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.h
1 /*
2 GRT MIT License
3 Copyright (c) <2012> <Nicholas Gillian, Media Lab, MIT>
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
6 and associated documentation files (the "Software"), to deal in the Software without restriction,
7 including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in all copies or substantial
12 portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 */
20 
21 #ifndef GRT_MATRIX_FLOAT_HEADER
22 #define GRT_MATRIX_FLOAT_HEADER
23 
24 #include "Matrix.h"
25 #include "VectorFloat.h"
26 #include "../Util/MinMax.h"
27 #include "../Util/Log.h"
28 #include "../Util/DebugLog.h"
29 #include "../Util/ErrorLog.h"
30 #include "../Util/WarningLog.h"
31 #include "../Util/FileParser.h"
32 #include "../Util/ErrorLog.h"
33 
34 GRT_BEGIN_NAMESPACE
35 
36 class MatrixFloat : public Matrix< Float >{
37 public:
41  MatrixFloat();
42 
49  MatrixFloat(const unsigned int rows,const unsigned int cols);
50 
56  MatrixFloat(const MatrixFloat &rhs);
57 
63  MatrixFloat(const Matrix< Float > &rhs);
64 
68  virtual ~MatrixFloat();
69 
76  MatrixFloat& operator=(const MatrixFloat &rhs);
77 
85 
93 
100  VectorFloat getRow(const unsigned int r) const{
101  VectorFloat rowVector(cols);
102  for(unsigned int c=0; c<cols; c++)
103  rowVector[c] = dataPtr[r*cols+c];
104  return rowVector;
105  }
106 
113  VectorFloat getCol(const unsigned int c) const{
114  VectorFloat columnVector(rows);
115  for(unsigned int r=0; r<rows; r++)
116  columnVector[r] = dataPtr[r*cols+c];
117  return columnVector;
118  }
119 
127  //virtual bool resize(const unsigned int rows,const unsigned int cols);
128 
135  bool save(const std::string &filename) const;
136 
146  bool load(const std::string &filename,const char seperator = ',');
147 
154  bool saveToCSVFile(const std::string &filename) const;
155 
163  bool loadFromCSVFile(const std::string &filename,const char seperator = ',');
164 
171  bool print(const std::string title="") const;
172 
178  bool transpose();
179 
185  bool scale(const Float minTarget,const Float maxTarget);
186 
192  bool scale(const Vector< MinMax > &ranges,const Float minTarget,const Float maxTarget);
193 
201  bool znorm(const Float alpha = 0.001);
202 
208  MatrixFloat multiple(const Float value) const;
209 
217  VectorFloat multiple(const VectorFloat &b) const;
218 
226  MatrixFloat multiple(const MatrixFloat &b) const;
227 
238  bool multiple(const MatrixFloat &a,const MatrixFloat &b,const bool aTranspose = false);
239 
249  bool add(const MatrixFloat &b);
250 
260  bool add(const MatrixFloat &a,const MatrixFloat &b);
261 
269  bool subtract(const MatrixFloat &b);
270 
280  bool subtract(const MatrixFloat &a,const MatrixFloat &b);
281 
287  Float getMinValue() const;
288 
294  Float getMaxValue() const;
295 
301  VectorFloat getMean() const;
302 
308  VectorFloat getStdDev() const;
309 
316 
322  Vector< MinMax > getRanges() const;
323 
329  Float getTrace() const;
330 
331 protected:
332 
333  Float stringToFloat(const std::string &value){
334  std::stringstream s( value );
335  Float d;
336  s >> d;
337  return d;
338  }
339 
340  WarningLog warningLog;
341  ErrorLog errorLog;
342 
343 };
344 
345 GRT_END_NAMESPACE
346 
347 #endif //Header guard
bool save(const std::string &filename) const
Float getMaxValue() const
bool saveToCSVFile(const std::string &filename) const
bool load(const std::string &filename, const char seperator= ',')
bool scale(const Float minTarget, const Float maxTarget)
virtual ~MatrixFloat()
Definition: MatrixFloat.cpp:58
The Matrix class is a basic class for storing any type of data. This class is a template and can ther...
bool transpose()
bool add(const MatrixFloat &b)
bool subtract(const MatrixFloat &b)
unsigned int rows
The number of rows in the Matrix.
Definition: Matrix.h:588
bool print(const std::string title="") const
VectorFloat getMean() const
MatrixFloat & operator=(const MatrixFloat &rhs)
Definition: MatrixFloat.cpp:62
MatrixFloat getCovarianceMatrix() const
bool loadFromCSVFile(const std::string &filename, const char seperator= ',')
VectorFloat getCol(const unsigned int c) const
Definition: MatrixFloat.h:113
Float getMinValue() const
Definition: Matrix.h:39
VectorFloat getRow(const unsigned int r) const
Definition: MatrixFloat.h:100
Vector< MinMax > getRanges() const
Float * dataPtr
A pointer to the raw data.
Definition: Matrix.h:592
unsigned int cols
The number of columns in the Matrix.
Definition: Matrix.h:589
VectorFloat getStdDev() const
MatrixFloat multiple(const Float value) const
Float getTrace() const
bool znorm(const Float alpha=0.001)