Go to the documentation of this file.00001
00002 #ifndef vnl_least_squares_function_h_
00003 #define vnl_least_squares_function_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <vnl/vnl_vector.h>
00024 #include <vnl/vnl_matrix.h>
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 class vnl_least_squares_function
00037 {
00038 public:
00039 enum UseGradient {
00040 no_gradient,
00041 use_gradient
00042 };
00043 bool failure;
00044
00045
00046
00047
00048
00049
00050 vnl_least_squares_function(unsigned int number_of_unknowns,
00051 unsigned int number_of_residuals,
00052 UseGradient g = use_gradient)
00053 : failure(false), p_(number_of_unknowns), n_(number_of_residuals),
00054 use_gradient_(g == use_gradient)
00055 { dim_warning(p_,n_); }
00056
00057 virtual ~vnl_least_squares_function() {}
00058
00059
00060 void throw_failure() { failure = true; }
00061 void clear_failure() { failure = false; }
00062
00063
00064
00065
00066 virtual void f(vnl_vector<double> const& x, vnl_vector<double>& fx) = 0;
00067
00068
00069 virtual void gradf(vnl_vector<double> const& x, vnl_matrix<double>& jacobian);
00070
00071
00072 void fdgradf(vnl_vector<double> const& x, vnl_matrix<double>& jacobian,
00073 double stepsize);
00074
00075
00076
00077 void ffdgradf(vnl_vector<double> const& x, vnl_matrix<double>& jacobian,
00078 double stepsize);
00079
00080
00081 virtual void trace(int iteration,
00082 vnl_vector<double> const& x,
00083 vnl_vector<double> const& fx);
00084
00085
00086 double rms(vnl_vector<double> const& x);
00087
00088
00089 unsigned int get_number_of_unknowns() const { return p_; }
00090
00091
00092 unsigned int get_number_of_residuals() const { return n_; }
00093
00094
00095 bool has_gradient() const { return use_gradient_; }
00096
00097 protected:
00098 unsigned int p_;
00099 unsigned int n_;
00100 bool use_gradient_;
00101
00102 void init(unsigned int number_of_unknowns, unsigned int number_of_residuals)
00103 { p_ = number_of_unknowns; n_ = number_of_residuals; dim_warning(p_,n_); }
00104 private:
00105 void dim_warning(unsigned int n_unknowns, unsigned int n_residuals);
00106 };
00107
00108 #endif // vnl_least_squares_function_h_