core/vnl/algo/vnl_lsqr.h
Go to the documentation of this file.
00001 // This is core/vnl/algo/vnl_lsqr.h
00002 #ifndef vnl_lsqr_h_
00003 #define vnl_lsqr_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Linear least squares
00010 //
00011 // vnl_lsqr implements an algorithm for large, sparse linear systems and
00012 // sparse, linear least squares. It is a wrapper for the LSQR algorithm
00013 // of Paige and Saunders (ACM TOMS 583). The sparse system is encapsulated
00014 // by a vnl_linear_system.
00015 //
00016 // \author David Capel, capes@robots
00017 // \date   July 2000
00018 //
00019 // \verbatim
00020 //  Modifications
00021 //   000705 capes@robots initial version.
00022 //   4/4/01 LSB (Manchester) Documentation tidied
00023 // \endverbatim
00024 //-----------------------------------------------------------------------------
00025 
00026 #include <vnl/vnl_vector.h>
00027 #include <vnl/vnl_linear_system.h>
00028 #include <vcl_iosfwd.h>
00029 
00030 //: Linear least squares
00031 //  vnl_lsqr implements an algorithm for large, sparse linear systems and
00032 //  sparse, linear least squares. It is a wrapper for the LSQR algorithm
00033 //  of Paige and Saunders (ACM TOMS 583). The sparse system is encapsulated
00034 //  by a vnl_linear_system.
00035 
00036 class vnl_lsqr
00037 {
00038  public:
00039   vnl_lsqr(vnl_linear_system& ls) :
00040     ls_(&ls), max_iter_(4*ls.get_number_of_unknowns()) {}
00041 
00042   ~vnl_lsqr();
00043 
00044   void set_max_iterations(long max_iter) { max_iter_ = max_iter; }
00045 
00046   //: Perform the minimization starting from x=0 and putting the result into x.
00047   // Return code may be translated with translate_return_code(), or the result of the
00048   // minimization may be printed in more detail with diagnose_outcome()
00049   int minimize(vnl_vector<double>& x);
00050 
00051   long get_number_of_iterations() const { return num_iter_; }
00052 
00053   //: Pontificate about the outcome of the last minimization.
00054   void diagnose_outcome(vcl_ostream& os) const;
00055 
00056   static void translate_return_code(vcl_ostream& os, int return_code);
00057 
00058   //: Return the residual norm estimate:
00059   double get_resid_norm_estimate() const { return resid_norm_estimate_; }
00060 
00061   //: Get the return code for the last minimization
00062   inline int return_code() const { return return_code_; }
00063 
00064  protected:
00065   vnl_linear_system* ls_;
00066   long max_iter_;
00067   long num_iter_;
00068   double resid_norm_estimate_;
00069   double result_norm_estimate_;
00070   double A_condition_estimate_;
00071   double result_norm_;
00072   long return_code_;
00073 
00074   static int aprod_(long* mode, long* m, long* n, double* x, double* y,
00075                     long* leniw, long* lenrw, long* iw, double* rw,
00076                     void* userdata);
00077 };
00078 
00079 #endif // vnl_lsqr_h_