core/vnl/vnl_linear_system.h
Go to the documentation of this file.
00001 // This is core/vnl/vnl_linear_system.h
00002 #ifndef vnl_linear_system_h_
00003 #define vnl_linear_system_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Abstraction for a linear system of equations.
00010 // \author David Capel, capes@robots
00011 // \date   July 2000
00012 //
00013 // \verbatim
00014 //  Modifications
00015 //   LSB (Manchester) 23/1/01 Documentation tidied
00016 // \endverbatim
00017 
00018 #include <vnl/vnl_vector.h>
00019 
00020 //: Abstraction for a linear system of equations.
00021 //    vnl_linear_system provides an abstraction for a linear system
00022 //    of equations, Ax = b, to be solved by one of the iterative linear
00023 //    solvers. Access to the systems is via the pure virtual methods
00024 //    multiply() and transpose_multiply(). This procedural access scheme
00025 //    makes it possible to solve very large, sparse systems which it would
00026 //    be inefficient to store in matrix form.
00027 //
00028 //    To solve the system, use an algorithm like vnl_lsqr.
00029 class vnl_linear_system
00030 {
00031  public:
00032 
00033   vnl_linear_system(unsigned int number_of_unknowns, unsigned int number_of_residuals) :
00034     p_(number_of_unknowns), n_(number_of_residuals) {}
00035 
00036   virtual ~vnl_linear_system();
00037 
00038   //: Compute A*x,  putting result in y
00039   virtual void multiply(vnl_vector<double> const& x, vnl_vector<double>& y) const = 0;
00040 
00041   //: Compute A_transpose * y, putting result in x
00042   virtual void transpose_multiply(vnl_vector<double> const& y, vnl_vector<double>& x) const = 0;
00043 
00044   //; Put the right-hand side of the system Ax = b into b
00045   virtual void get_rhs(vnl_vector<double>& b) const = 0;
00046 
00047   //; (Optional) Apply a suitable preconditioner to x.
00048   // A preconditioner is an approximation of the inverse of A.
00049   // Common choices are Jacobi (1/diag(A'A)), Gauss-Seidel,
00050   // and incomplete LU or Cholesky decompositions.
00051   // The default implementation applies the identity.
00052   virtual void apply_preconditioner(vnl_vector<double> const& x, vnl_vector<double>& px) const;
00053 
00054   //: Return the number of unknowns
00055   unsigned int get_number_of_unknowns() const { return p_; }
00056 
00057   //: Return the number of residuals.
00058   unsigned int get_number_of_residuals() const { return n_; }
00059 
00060   //: Compute rms error for parameter vector x
00061   double get_rms_error(vnl_vector<double> const& x) const;
00062 
00063   //: Compute relative residual (|Ax - b| / |b| )for parameter vector x
00064   double get_relative_residual(vnl_vector<double> const& x) const;
00065 
00066  protected:
00067   unsigned int p_;
00068   unsigned int n_;
00069 };
00070 
00071 #endif // vnl_linear_system_h_