00001 #ifndef rrel_trunc_quad_obj_h_ 00002 #define rrel_trunc_quad_obj_h_ 00003 00004 //: 00005 // \file 00006 // \author Chuck Stewart (stewart@cs.rpi.edu) 00007 // \author Amitha Perera (perera@cs.rpi.edu) 00008 // \brief Truncated quadratic loss function 00009 00010 #include <rrel/rrel_m_est_obj.h> 00011 00012 //: Truncated quadratic robust loss function. 00013 // The objective function for the truncated quadratic M-estimator is 00014 // \f[ 00015 // \rho(u) = 00016 // \left\{ 00017 // \begin{array}{ll} 00018 // u^2, & |u| \le T \\ T^2, & |u| > T 00019 // \end{array} 00020 // \right. 00021 // \f] 00022 // 00023 // where u is a scale-normalized residual (\f$ r/\sigma \f$) and \f$ 00024 // T \f$ is a threshold. This has been used in a number of vision 00025 // applications despite the fact that the wgt function is 00026 // discontinuous. This is the same cost function used in the MSAC 00027 // generalisation of RANSAC. 00028 00029 class rrel_trunc_quad_obj : public rrel_m_est_obj 00030 { 00031 public: 00032 //: Constructor. 00033 // \a scale_mult * scale is the truncation threshold. 00034 rrel_trunc_quad_obj( double scale_mult = 2.0 ); 00035 00036 //: Destructor. 00037 virtual ~rrel_trunc_quad_obj(); 00038 00039 //: The robust loss function for the M-estimator. 00040 virtual double rho( double u ) const; 00041 00042 //: The robust loss function for the M-estimator. 00043 // Overriding the overloaded version rho(u) hides the superclass' 00044 // implementation of this version of rho(). This implementation simply 00045 // calls the superclass' version of the same routine. 00046 // \a r is the residual and 00047 // \a s is the scale for that residual. 00048 virtual double rho( double r, double s ) const 00049 { return rrel_m_est_obj::rho(r, s); } 00050 00051 //: The weight of the residual. 00052 virtual double wgt( double u ) const; 00053 00054 //: Evaluate the objective function on heteroscedastic residuals. 00055 // Overriding the overloaded version wgt(u) hides the superclass' 00056 // implementation of this version of wgt(). This implementation simply 00057 // calls the superclass' version of the same routine. 00058 // \sa rrel_wls_obj::wgt() 00059 virtual void wgt( vect_const_iter res_begin, vect_const_iter res_end, 00060 vect_const_iter scale_begin, 00061 vect_iter wgt_begin ) const 00062 { rrel_m_est_obj::wgt(res_begin, res_end, scale_begin, wgt_begin); } 00063 00064 //: Computes the weights for homoscedastic residuals. 00065 // Overriding the overloaded version wgt(u) hides the superclass' 00066 // implementation of this version of wgt(). This implementation simply 00067 // calls the superclass' version of the same routine. 00068 // \sa rrel_wls_obj::wgt() 00069 virtual void wgt( vect_const_iter begin, vect_const_iter end, 00070 double scale, 00071 vect_iter wgt_begin ) const 00072 { rrel_m_est_obj::wgt(begin, end, scale, wgt_begin); } 00073 00074 //: The weight of the residual. 00075 // Overriding the overloaded version wgt(u) hides the superclass' 00076 // implementation of this version of wgt(). This implementation simply 00077 // calls the superclass' version of the same routine. 00078 // \a r is the residual and 00079 // \a s is the scale for that residual. 00080 virtual double wgt( double r, double s ) const 00081 { return rrel_m_est_obj::wgt(r, s); } 00082 00083 //: Fast version of the wgt(u) computation. 00084 inline double wgt_fast( double u ) const; 00085 00086 //: Fast version of the rho(u) computation. 00087 inline double rho_fast( double u ) const; 00088 00089 00090 private: 00091 //: Squared threshold. 00092 double T_sqr_; 00093 }; 00094 00095 00096 inline double 00097 rrel_trunc_quad_obj::rho_fast( double u ) const 00098 { 00099 double u_sqr = u*u; 00100 return ( u_sqr < T_sqr_ ) ? u_sqr : T_sqr_; 00101 } 00102 00103 inline double 00104 rrel_trunc_quad_obj::wgt_fast( double u ) const 00105 { 00106 return ( u*u < T_sqr_ ) ? 1 : 0.0; 00107 } 00108 00109 #endif // rrel_trunc_quad_obj_h_