00001 #ifndef rrel_tukey_obj_h_ 00002 #define rrel_tukey_obj_h_ 00003 //: 00004 // \file 00005 // \author Amitha Perera (perera@cs.rpi.edu) 00006 // \brief Beaton-Tukey loss function. 00007 00008 #include <rrel/rrel_m_est_obj.h> 00009 #include <vnl/vnl_math.h> 00010 00011 //: Beaton-Tukey biweight. 00012 // The cost function for the Beaton-Tukey biweight is 00013 // \f[ 00014 // \rho(u) = 00015 // \left\{ 00016 // \begin{array}{ll} 00017 // \frac{B^2}{6} ( 1 - (1-(u/B)^2)^3 ), & |u| \le B \\ B^2/6, & |u| > B 00018 // \end{array} 00019 // \right. 00020 // \f] 00021 // The associated weight function is 00022 // \f[ 00023 // w(u) = 00024 // \left\{ 00025 // \begin{array}{ll} 00026 // (1-(u/B)^2)^2, & |u| \le B \\ 0, & |u| > B 00027 // \end{array} 00028 // \right. 00029 // \f] 00030 // In this implementation, the constant \f$ \frac{B^2}{6} \f$ in \f$ 00031 // \rho \f$ is ignored, since it doesn't affect the minimum. 00032 00033 class rrel_tukey_obj : public rrel_m_est_obj 00034 { 00035 public: 00036 //: Constructor. 00037 // \a B is the normalised residual value at which the cost becomes 00038 // constant. 00039 rrel_tukey_obj( double B ); 00040 00041 //: Destructor. 00042 virtual ~rrel_tukey_obj(); 00043 00044 //: The robust loss function for the M-estimator. 00045 virtual double rho( double u ) const; 00046 00047 //: The robust loss function for the M-estimator. 00048 // Overriding the overloaded version rho(u) hides the superclass' 00049 // implementation of this version of rho(). This implementation simply 00050 // calls the superclass' version of the same routine. 00051 // \a r is the residual and 00052 // \a s is the scale for that residual. 00053 virtual double rho( double r, double s ) const 00054 { return rrel_m_est_obj::rho(r, s); } 00055 00056 //: The weight of the residual. 00057 virtual double wgt( double u ) const; 00058 00059 //: Evaluate the objective function on heteroscedastic residuals. 00060 // Overriding the overloaded version wgt(u) hides the superclass' 00061 // implementation of this version of wgt(). This implementation simply 00062 // calls the superclass' version of the same routine. 00063 // \sa rrel_wls_obj::wgt() 00064 virtual void wgt( vect_const_iter res_begin, vect_const_iter res_end, 00065 vect_const_iter scale_begin, 00066 vect_iter wgt_begin ) const 00067 { rrel_m_est_obj::wgt(res_begin, res_end, scale_begin, wgt_begin); } 00068 00069 //: Computes the weights for homoscedastic residuals. 00070 // Overriding the overloaded version wgt(u) hides the superclass' 00071 // implementation of this version of wgt(). This implementation simply 00072 // calls the superclass' version of the same routine. 00073 // \sa rrel_wls_obj::wgt() 00074 virtual void wgt( vect_const_iter begin, vect_const_iter end, 00075 double scale, 00076 vect_iter wgt_begin ) const 00077 { rrel_m_est_obj::wgt(begin, end, scale, wgt_begin); } 00078 00079 //: The weight of the residual. 00080 // Overriding the overloaded version wgt(u) hides the superclass' 00081 // implementation of this version of wgt(). This implementation simply 00082 // calls the superclass' version of the same routine. 00083 // \a r is the residual and 00084 // \a s is the scale for that residual. 00085 virtual double wgt( double r, double s ) const 00086 { return rrel_m_est_obj::wgt(r, s); } 00087 00088 //: Fast version of the wgt(u) computation. 00089 inline double wgt_fast( double u ) const; 00090 00091 //: Fast version of the rho(u) computation. 00092 inline double rho_fast( double u ) const; 00093 00094 private: 00095 double B_; 00096 }; 00097 00098 inline double 00099 rrel_tukey_obj::rho_fast( double u ) const 00100 { 00101 if ( u < -B_ || u > B_ ) 00102 return 1.0; 00103 else 00104 return 1.0 - vnl_math_cube(1.0 - vnl_math_sqr(u/B_)); 00105 } 00106 00107 inline double 00108 rrel_tukey_obj::wgt_fast( double u ) const 00109 { 00110 if ( u < -B_ || u > B_ ) 00111 return 0.0; 00112 else 00113 return vnl_math_sqr(1.0 - vnl_math_sqr(u/B_)); 00114 } 00115 00116 #endif // rrel_tukey_obj_h_