1 | // $Id: SVD.h 4 2003-02-25 15:04:49Z daniel $ |
---|

2 | |
---|

3 | #ifndef _THEP_CPPTOOLS_SVD_ |
---|

4 | #define _THEP_CPPTOOLS_SVD_ |
---|

5 | |
---|

6 | //GCLwrap includes |
---|

7 | ////////////////// |
---|

8 | #include <gslwrap/matrix_double.h> |
---|

9 | #include <gslwrap/vector_double.h> |
---|

10 | |
---|

11 | |
---|

12 | |
---|

13 | ////////////////////////////////////////////////// |
---|

14 | //Class encapsulating methods for |
---|

15 | //Singular Value Decomposition |
---|

16 | // |
---|

17 | //A = Matrix to be decomposed, size MxN |
---|

18 | //U = Orthogonal matrix, size MxN |
---|

19 | //S = Diagonal matrix of singular values, size NxN |
---|

20 | //V = Orthogonal matrix, size NxN |
---|

21 | //A = U S V' = (MxN)(NxN)(NxN) = (MxN) |
---|

22 | //Note: The matrix A_ is replaced by U on |
---|

23 | // output from gsl_linalg_* method |
---|

24 | ////////////////////////////////////////////////// |
---|

25 | |
---|

26 | namespace THEP_CPPTOOLS |
---|

27 | { |
---|

28 | class SVD |
---|

29 | { |
---|

30 | static const double MAXTOL = 1E-10; |
---|

31 | |
---|

32 | enum SVDtypes |
---|

33 | { |
---|

34 | Unmodified, |
---|

35 | Modified, |
---|

36 | Jacobi, |
---|

37 | Solver |
---|

38 | }; |
---|

39 | |
---|

40 | public: |
---|

41 | SVD(); |
---|

42 | SVD( const gsl::matrix& ); |
---|

43 | SVD( const gsl::matrix&, const gsl::vector& ); |
---|

44 | ~SVD(); |
---|

45 | bool process( SVDtypes stype = Unmodified ); |
---|

46 | |
---|

47 | //The result is obtained from the Get functions below: |
---|

48 | gsl::matrix get_u() const { return A_; } |
---|

49 | gsl::matrix get_v() const { return V_; } |
---|

50 | gsl::vector get_x() const { return x_; } |
---|

51 | gsl::matrix get_s() const; |
---|

52 | |
---|

53 | //Test-method |
---|

54 | bool test(); |
---|

55 | |
---|

56 | private: |
---|

57 | gsl::matrix A_, V_; |
---|

58 | gsl::vector s_, b_, x_; |
---|

59 | bool loaded_, solver_; |
---|

60 | |
---|

61 | //SVD methods |
---|

62 | bool process_default(); |
---|

63 | bool process_modified(); |
---|

64 | bool process_jacobi(); |
---|

65 | bool process_solver(); |
---|

66 | }; |
---|

67 | }; |
---|

68 | |
---|

69 | #endif |
---|