source: trunk/src/SVD.h @ 11

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

Hmm...

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1// $Id: SVD.h 11 2003-06-03 16:21:31Z daniel $
2
3#ifndef _THEP_CPPTOOLS_SVD_
4#define _THEP_CPPTOOLS_SVD_
5
6// C++ tools include
7/////////////////////
8#include "matrix.h"
9#include "vector.h"
10#include <gsl/gsl_vector.h>
11
12
13// Standard includes
14////////////////////
15#include <iostream>
16#include <cmath>  
17#include <cstdlib> //To include srand() and rand()
18#include <ctime> 
19
20
21namespace thep_cpp_tools
22{ 
23
24  /**
25     Class encapsulating methods for Singular Value Decomposition.
26     \n\n
27     A = Matrix to be decomposed, size MxN\n
28     U = Orthogonal matrix, size MxN\n
29     S = Diagonal matrix of singular values, size NxN\n
30     V = Orthogonal matrix, size NxN\n
31     A = U S V' = (MxN)(NxN)(NxN) = (MxN)\n   
32     @version 1.0 $Revision: 11 $ $Date: 2003-06-03 16:21:31 +0000 (Tue, 03 Jun 2003) $
33  */
34
35  class SVD
36  {   
37    static const double MAXTOL = 1E-6;
38
39    enum SVDtypes
40      {
41  Unmodified,
42  Modified,
43  Jacobi,
44  Solver
45      };
46
47  public:
48    /**
49       The default constructor should only be used for testing!!!
50    */
51    SVD();
52
53   
54    /**
55       Constructs an SVD object using the matrix A as only
56       input. The input matrix is copied for further use in the
57       object.
58    */
59    SVD( const thep_gsl_api::matrix& );
60   
61    /**
62       Constructor initializing the SVD object for Solver. 
63       Solver requires an extra-vector paramter \a b: \f$Ax = b\f$
64       The \f$x\f$ vector will be reached using the get_x()
65       function.
66       @see get_x() function.
67    */
68
69    SVD( const thep_gsl_api::matrix&, const thep_gsl_api::vector& b);
70    ~SVD();
71
72    /**
73       This function will run the method specified by the SVDtypes. Precently
74       there are 3 SVD methods implemented and one solver. These are: \n\n
75       Unmodified: (see GSL documentation about gsl_linalg_SV_decomp function)\n
76       Modified: This method is faster when M>>N. (see GSL documentation
77       about gsl_linalg_SV_decomp_mod function)\n
78       Jacobi: Computes singular values to higer accuracy than default method
79       (see GSL documentation about gsl_linalg_SV_decomp_jacobi.\n
80       Solver: Using Unmodified to perform SVD and then solves the system \f$Ax=b\f$
81    */
82    bool process( SVDtypes stype = Unmodified );
83
84    /**
85       Function will return the matrix U. Require that process() has been
86       executed.
87    */
88    thep_gsl_api::matrix get_u() const { return A_; }
89
90    /**
91       Function will return the matrix V. Require that process() has been
92       executed.
93    */
94    thep_gsl_api::matrix get_v() const { return V_; }
95
96
97    /**
98       Function will return the vector x containing the solution
99       \f$ x=A^{-1}b \f$. Require that process( Solver ) has been
100       executed. 
101       @see Read about Solver in the bool process() function.
102    */
103
104    thep_gsl_api::vector get_x() const { return x_; }
105
106    /**
107       Function returning diagonal matrix S. Require that process() has been
108       executed.
109    */
110    thep_gsl_api::matrix get_s() const;
111
112
113    /**
114       Function returning diagonal matrix S in vector form.
115    */
116    thep_gsl_api::vector get_s_vec() const { return s_; }
117
118
119    /**
120       This method will execute Default, Unmodified and Jacobi methods one at a time
121       and calculate the error, \f$ e = \left\Vert A - USV^{T} \right\Vert_{2} \f$.
122       The method will return "true" if \f$e < 10^{-6}\f$ else false. A test program
123       is available that executes this method, c++_tools/test/svd_test. No test is
124       performed for solver but the aim is to add one in the future.
125    */
126    bool test();
127   
128  private:
129
130    thep_gsl_api::matrix A_, V_;   
131    thep_gsl_api::vector s_, b_, x_;
132    bool loaded_, solver_;
133
134    //SVD methods
135    bool process_default();
136    bool process_modified();
137    bool process_jacobi();
138    bool process_solver();
139  }; 
140};
141
142#endif
Note: See TracBrowser for help on using the repository browser.