NICE
Northeastern Interactive Clustering Engine
svd_solver.h
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2016 Northeastern University
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #ifndef CPP_INCLUDE_SVD_SOLVER_H_
24 #define CPP_INCLUDE_SVD_SOLVER_H_
25 
26 #include "include/matrix.h"
27 #include "include/vector.h"
28 
29 #include "Eigen/SVD"
30 
31 
32 namespace Nice {
33 
34 // Abstract class of svd solver
35 template<typename T>
36 class SvdSolver {
37  private:
38  Eigen::JacobiSVD<Matrix<T>> svd_;
39 
40  public:
42  :
43  svd_() {}
44 
52  void Compute(const Matrix<T> &a) {
53  svd_.compute(a, Eigen::ComputeFullU|Eigen::ComputeFullV);
54  }
55 
63  Matrix<T> MatrixU() const {
64  return svd_.matrixU();
65  }
66 
74  Matrix<T> MatrixV() const {
75  return svd_.matrixV();
76  }
77 
86  return svd_.singularValues();
87  }
88 
96  int Rank(const Matrix<T> &a) {
97  Compute(a);
98  return svd_.rank();
99  }
100 };
101 
102 } // namespace Nice
103 
104 #endif // CPP_INCLUDE_SVD_SOLVER_H_
105 
void Compute(const Matrix< T > &a)
Definition: svd_solver.h:52
Definition: cpu_operations.h:36
int Rank(const Matrix< T > &a)
Definition: svd_solver.h:96
Definition: svd_solver.h:36
SvdSolver()
Definition: svd_solver.h:41
Vector< T > SingularValues() const
Definition: svd_solver.h:85
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
Definition: vector.h:31
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
Definition: matrix.h:31
Matrix< T > MatrixV() const
Definition: svd_solver.h:74
Matrix< T > MatrixU() const
Definition: svd_solver.h:63