00001 #ifndef vnl_levenberg_marquardt_h_
00002 #define vnl_levenberg_marquardt_h_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <vcl_iosfwd.h>
00015 #include <vnl/vnl_vector.h>
00016 #include <vnl/vnl_matrix.h>
00017 #include <vnl/vnl_nonlinear_minimizer.h>
00018
00019 class vnl_least_squares_function;
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 class vnl_levenberg_marquardt : public vnl_nonlinear_minimizer {
00032 public:
00033
00034
00035 vnl_levenberg_marquardt(vnl_least_squares_function& f) { init(&f); }
00036
00037
00038 vnl_levenberg_marquardt(vnl_least_squares_function& f,
00039 vnl_vector<double>& x) {
00040 init(&f);
00041 minimize(x);
00042 }
00043
00044 ~vnl_levenberg_marquardt();
00045
00046
00047
00048
00049 bool minimize_without_gradient(vnl_vector<double>& x);
00050 bool minimize_using_gradient (vnl_vector<double>& x);
00051
00052
00053 bool minimize(vnl_vector<double>& x) { return minimize_without_gradient(x); }
00054
00055
00056
00057
00058 void diagnose_outcome() const;
00059 void diagnose_outcome(vcl_ostream&) const;
00060
00061
00062 vnl_matrix<double> const& get_JtJ();
00063
00064 protected:
00065
00066 vnl_least_squares_function* f_;
00067 vnl_matrix<double>* fdjac_;
00068 vnl_vector<int>* ipvt_;
00069
00070 vnl_matrix<double>* covariance_;
00071 bool set_covariance_;
00072
00073 void init(vnl_least_squares_function* f);
00074
00075
00076 friend class vnl_levenberg_marquardt_Activate;
00077 static int lmdif_lsqfun(int* m, int* n, const double* x,
00078 double* fx, int* iflag);
00079 static int lmder_lsqfun(int* m, int* n, const double* x,
00080 double* fx, double* fJ, int&, int* iflag);
00081 };
00082
00083 #endif // vnl_levenberg_marquardt_h_