source: trunk/src/SVD.h @ 7

Last change on this file since 7 was 7, checked in by daniel, 19 years ago

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1// $Id: SVD.h 7 2003-02-28 10:39:35Z daniel $
2
3#ifndef _THEP_CPPTOOLS_SVD_
4#define _THEP_CPPTOOLS_SVD_
5
6//GSLwrap includes
7//////////////////
8#include <gslwrap/matrix_double.h>
9#include <gslwrap/vector_double.h>
10
11
12namespace thep_cpp_tools
13{ 
14
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: 7 $ $Date: 2003-02-28 10:39:35 +0000 (Fri, 28 Feb 2003) $
24  */
25
26  class SVD
27  {   
28    static const double MAXTOL = 1E-10;
29
30    enum SVDtypes
31      {
32  Unmodified,
33  Modified,
34  Jacobi,
35  Solver
36      };
37
38  public:
39    /**
40       Constructs an SVD object using the matrix A as only
41       input. The input matrix is copied for further use in the
42       object.
43    */
44    SVD( const gsl::matrix& );
45   
46    /**
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.
51       @see get_x() function.
52    */
53
54    SVD( const gsl::matrix&, const gsl::vector& b);
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    */
67    bool process( SVDtypes stype = Unmodified );
68
69    /**
70       Function will return the matrix U. Require that process() has been
71       executed.
72    */
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    */
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
89    gsl::vector get_x() const { return x_; }
90
91    /**
92       Function returning diagonal matrix S. Require that process() has been
93       executed.
94    */
95    gsl::matrix get_s() const;
96
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    */
104    bool test();
105   
106  private:
107    SVD();
108
109    gsl::matrix A_, V_;   
110    gsl::vector s_, b_, x_;
111    bool loaded_, solver_;
112
113    //SVD methods
114    bool process_default();
115    bool process_modified();
116    bool process_jacobi();
117    bool process_solver();
118  }; 
119};
120
121#endif
Note: See TracBrowser for help on using the repository browser.