Changeset 7
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SVD.cc
r4 r7 6 6 #include <cstdlib> //To include srand() and rand() 7 7 #include <ctime> 8 using namespace THEP_CPPTOOLS;8 using namespace thep_cpp_tools; 9 9 10 10 //Constructor that can only be used for test-method -
trunk/src/SVD.h
r6 r7 10 10 11 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 12 namespace thep_cpp_tools 27 13 { 28 14 29 /** 30 Class encapsulating methods for Singular Value Decomposition 31 32 @version $Revision$ $Date$ 33 */ 15 /** 16 Class encapsulating methods for Singular Value Decomposition. 17 \n\n 18 A = Matrix to be decomposed, size MxN\n 19 U = Orthogonal matrix, size MxN\n 20 S = Diagonal matrix of singular values, size NxN\n 21 V = Orthogonal matrix, size NxN\n 22 A = U S V' = (MxN)(NxN)(NxN) = (MxN)\n 23 @version 1.0 $Revision$ $Date$ 24 */ 34 25 35 26 class SVD … … 46 37 47 38 public: 48 SVD();49 39 /** 50 Constructs a SVD object and initializes it to proper matrix51 sizes. The input matrix is copied for further use in the40 Constructs an SVD object using the matrix A as only 41 input. The input matrix is copied for further use in the 52 42 object. 53 43 */ 54 44 SVD( const gsl::matrix& ); 45 55 46 /** 56 Constructor initializing the SVD object for Solver. Solver57 requires an extra-vector paramter \a b: $Ax = b$ The $x$ vector58 will be reached using the get_x() function.59 47 Constructor initializing the SVD object for Solver. 48 Solver requires an extra-vector paramter \a b: $Ax = b$ 49 The $x$ vector will be reached using the get_x() 50 function. 60 51 @see get_x() function. 61 52 */ 53 62 54 SVD( const gsl::matrix&, const gsl::vector& b); 63 55 ~SVD(); 56 57 /** 58 This function will run the method specified by the SVDtypes. Precently 59 there are 3 SVD methods implemented and one solver. These are: \n\n 60 Unmodified: (see GSL documentation about gsl_linalg_SV_decomp function)\n 61 Modified: This method is faster when M>>N. (see GSL documentation 62 about gsl_linalg_SV_decomp_mod function)\n 63 Jakoby: Computes singular values to higer accuracy than default method 64 (see GSL documentation about gsl_linalg_SV_decomp_jacobi.\n 65 Solver: Using Unmodified to perform SVD and then solves the system \f$Ax=b\f$ 66 */ 64 67 bool process( SVDtypes stype = Unmodified ); 65 66 //The result is obtained from the Get functions below: 68 69 /** 70 Function will return the matrix U. Require that process() has been 71 executed. 72 */ 67 73 gsl::matrix get_u() const { return A_; } 74 75 /** 76 Function will return the matrix V. Require that process() has been 77 executed. 78 */ 68 79 gsl::matrix get_v() const { return V_; } 80 81 82 /** 83 Function will return the vector x containing the solution 84 \f$ x=A^{-1}b \f$. Require that process( Solver ) has been 85 executed. 86 @see Read about Solver in the bool process() function. 87 */ 88 69 89 gsl::vector get_x() const { return x_; } 90 91 /** 92 Function returning diagonal matrix S. Require that process() has been 93 executed. 94 */ 70 95 gsl::matrix get_s() const; 71 96 72 //Test-method 97 /** 98 This method will execute Default, Unmodified and Jakoby methods one at a time 99 and calculate the error, \f$ e = \left\Vert A - USV^{T} \right\Vert_{2} \f$. 100 The method will return "true" if \f$e < 10^{-10}\f$ else false. A test program 101 is available that executes this method, c++_tools/test/svd_test. No test is 102 performed for solver but the aim is to add one in the future. 103 */ 73 104 bool test(); 74 105 75 106 private: 107 SVD(); 108 76 109 gsl::matrix A_, V_; 77 110 gsl::vector s_, b_, x_;
Note: See TracChangeset
for help on using the changeset viewer.