00001 #ifndef rrel_objective_h_ 00002 #define rrel_objective_h_ 00003 //: 00004 // \file 00005 // \author Chuck Stewart (stewart@cs.rpi.edu) 00006 // \brief Abstract base class for robust objective functions. 00007 00008 #include <vnl/vnl_fwd.h> 00009 #include <vcl_vector.h> 00010 00011 //: An objective function to be minimised. 00012 // It returns a "cost" given the residuals, and thus gives a cost for 00013 // the estimate. 00014 // 00015 // Robust objective functions will use the residuals to determine 00016 // which points are inliers and which are outliers, and will 00017 // downgrade the influence of the of those samples. 00018 00019 class rrel_objective 00020 { 00021 public: 00022 //: The iterators used to pass in values. 00023 // Since we don't allow member templates, we have to fix on a 00024 // particular type of container for residuals. Using this typedef 00025 // will allow things to easily change when member templates are 00026 // allowed. 00027 typedef vcl_vector<double>::const_iterator vect_const_iter; 00028 00029 //: The iterators used to pass out values. 00030 typedef vcl_vector<double>::iterator vect_iter; 00031 00032 public: 00033 rrel_objective() {} 00034 virtual ~rrel_objective() {} 00035 00036 //: Evaluate the objective function on heteroscedastic residuals. 00037 // This version is used for heteroscedastic data, where each 00038 // residual has its own scale. Some objective functions, such as 00039 // M-estimators, will require a scale value. Others, such as Least 00040 // Median of Squares (LMS) with intercept adjustment, will require 00041 // access to the parameter vector. 00042 // 00043 // The number of scale values must, of course, equal the number of 00044 // residuals. 00045 virtual double fcn( vect_const_iter res_begin, vect_const_iter res_end, 00046 vect_const_iter scale_begin, 00047 vnl_vector<double>* param_vector ) const = 0; 00048 00049 //: Evaluate the objective function on homoscedastic residuals. 00050 // This version is used for homoscedastic data, where each residual 00051 // is distributed with a common scale. Some objective functions, 00052 // such as M-estimators, will require a scale value. Others, such 00053 // as Least Median of Squares (LMS) with intercept adjustment, will 00054 // require access to the parameter vector. 00055 // 00056 // Using the previous function for homoscedastic data would imply 00057 // the creation of a vector of equal values. Since the majority of 00058 // problems assume homoscedastic data, a "convenience" function that 00059 // avoids the scale vector is useful. 00060 virtual double fcn( vect_const_iter begin, vect_const_iter end, 00061 double scale, 00062 vnl_vector<double>* param_vector ) const = 0; 00063 00064 //: True if the objective function must have a prior scale. 00065 // For some objective functions, such as RANSAC, an estimated scale 00066 // is not enough. The problem must have a prior scale estimate. 00067 virtual bool requires_prior_scale() const = 0; 00068 00069 //: True if the objective function can estimate scale. 00070 // Some objective functions, such as MUSE, can provide an accurate 00071 // inlier scale estimate. 00072 virtual bool can_estimate_scale() const { return false; } 00073 00074 //: Scale estimate. 00075 // The result is undefined if can_estimate_scale() is false. 00076 virtual double scale( vect_const_iter /*res_begin*/, vect_const_iter /*res_end*/ ) const { return 0.0; } 00077 }; 00078 00079 #endif