KrisLibrary  1.0.0
SVDecomposition.h
1 #ifndef MATH_SV_DECOMPOSITION_H
2 #define MATH_SV_DECOMPOSITION_H
3 
4 #include "MatrixTemplate.h"
5 #include "DiagonalMatrix.h"
6 
7 namespace Math {
8 
20 template <class T>
22 {
23 public:
24  typedef MatrixTemplate<T> MatrixT;
25  typedef VectorTemplate<T> VectorT;
27 
29  SVDecomposition(const MatrixT& A);
30 
31  bool set(const MatrixT& A);
32  void setIdentity(int m,int n);
33  void setZero(int m,int n);
34  void resize(int m,int n);
35  void clear();
36  void backSub(const VectorT& b, VectorT& x) const;
37  void dampedBackSub(const VectorT& b,T lambda, VectorT& x) const;
38  void nullspaceComponent(const VectorT& x,VectorT& xNull) const;
39  int getRank() const;
40  int getNull() const;
41  void getInverse(MatrixT& Ainv) const;
42  void getDampedPseudoInverse(MatrixT& Aplus,T lambda) const;
43  void getNullspace(MatrixT& N) const;
44 
46  void sortSVs();
47 
48  MatrixT U;
49  DiagonalMatrixT W;
50  MatrixT V;
51 
52  //settings
53  int maxIters;
54  T epsilon;
55 };
56 
67 template <class T>
68 class RobustSVD
69 {
70 public:
71  typedef MatrixTemplate<T> MatrixT;
72  typedef VectorTemplate<T> VectorT;
74 
75  RobustSVD();
76  RobustSVD(const MatrixT& A);
77 
78  bool set(const MatrixT& A);
79  bool setConditioned(const MatrixT& A);
80  void setIdentity(int m,int n);
81  void setZero(int m,int n);
82  void resize(int m,int n);
83  void clear();
84  void backSub(const VectorT& b, VectorT& x) const;
85  void dampedBackSub(const VectorT& b,T lambda, VectorT& x) const;
86  void nullspaceComponent(const VectorT& x,VectorT& xNull) const;
87  int getRank() const;
88  int getNull() const;
89  void getInverse(MatrixT& Ainv) const;
90  void getDampedPseudoInverse(MatrixT& Aplus,T lambda) const;
91  void getNullspace(MatrixT& N) const;
92  void calcConditioning(const MatrixT& A);
93 
94  DiagonalMatrixT Pre;
96  DiagonalMatrixT Post;
97 
98  //settings
99  T zeroElementEpsilon;
100  bool preMultiply,postMultiply;
101 };
102 
103 } //namespace Math
104 
105 #endif
void sortSVs()
sorts the singular values from highest to lowest
Definition: SVDecomposition.cpp:461
Performs a pre/postconditioned singular value decomposition.
Definition: SVDecomposition.h:68
Performs the singular value decomposition.
Definition: SVDecomposition.h:21
A matrix over the field T.
Definition: function.h:10
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12
A vector over the field T.
Definition: function.h:9
A templated diagonal matrix, represented by a vector of the entries on the diagonal.
Definition: DiagonalMatrix.h:14