GestureRecognitionToolkit  Version: 0.2.5
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 GRT_API 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 
71 
75  virtual ~MatrixFloat();
76 
83  MatrixFloat& operator=(const MatrixFloat &rhs);
84 
92 
100 
107  VectorFloat getRow(const unsigned int r) const{
108  VectorFloat rowVector(cols);
109  for(unsigned int c=0; c<cols; c++)
110  rowVector[c] = dataPtr[r*cols+c];
111  return rowVector;
112  }
113 
120  VectorFloat getCol(const unsigned int c) const{
121  VectorFloat columnVector(rows);
122  for(unsigned int r=0; r<rows; r++)
123  columnVector[r] = dataPtr[r*cols+c];
124  return columnVector;
125  }
126 
134  //virtual bool resize(const unsigned int rows,const unsigned int cols);
135 
142  bool save(const std::string &filename) const;
143 
153  bool load(const std::string &filename,const char seperator = ',');
154 
161  bool saveToCSVFile(const std::string &filename) const;
162 
170  bool loadFromCSVFile(const std::string &filename,const char seperator = ',');
171 
178  bool print(const std::string title="") const;
179 
185  bool transpose();
186 
192  bool scale(const Float minTarget,const Float maxTarget);
193 
199  bool scale(const Vector< MinMax > &ranges,const Float minTarget,const Float maxTarget);
200 
208  bool znorm(const Float alpha = 0.001);
209 
215  MatrixFloat multiple(const Float value) const;
216 
224  VectorFloat multiple(const VectorFloat &b) const;
225 
233  MatrixFloat multiple(const MatrixFloat &b) const;
234 
245  bool multiple(const MatrixFloat &a,const MatrixFloat &b,const bool aTranspose = false);
246 
256  bool add(const MatrixFloat &b);
257 
267  bool add(const MatrixFloat &a,const MatrixFloat &b);
268 
276  bool subtract(const MatrixFloat &b);
277 
287  bool subtract(const MatrixFloat &a,const MatrixFloat &b);
288 
294  Float getMinValue() const;
295 
301  Float getMaxValue() const;
302 
308  VectorFloat getMean() const;
309 
315  VectorFloat getStdDev() const;
316 
322  MatrixFloat getCovarianceMatrix() const;
323 
329  Vector< MinMax > getRanges() const;
330 
336  Float getTrace() const;
337 
338 protected:
339 
340  Float stringToFloat(const std::string &value){
341  std::stringstream s( value );
342  Float d;
343  s >> d;
344  return d;
345  }
346 
347  WarningLog warningLog;
348  ErrorLog errorLog;
349 
350 };
351 
352 GRT_END_NAMESPACE
353 
354 #endif //Header guard
The Matrix class is a basic class for storing any type of data. This class is a template and can ther...
Matrix & operator=(const Matrix &rhs)
Definition: Matrix.h:150
unsigned int rows
The number of rows in the Matrix.
Definition: Matrix.h:620
VectorFloat getCol(const unsigned int c) const
Definition: MatrixFloat.h:120
Definition: Matrix.h:39
VectorFloat getRow(const unsigned int r) const
Definition: MatrixFloat.h:107
unsigned int cols
The number of columns in the Matrix.
Definition: Matrix.h:621