00001 #ifndef rrel_cauchy_obj_h_ 00002 #define rrel_cauchy_obj_h_ 00003 00004 //: 00005 // \file 00006 // \author Amitha Perera (perera@cs.rpi.edu) 00007 // Cauchy loss function. 00008 00009 #include <rrel/rrel_m_est_obj.h> 00010 #include <vnl/vnl_math.h> 00011 00012 //: Cauchy robust loss function. 00013 // The objective function for the Cauchy M-estimator is 00014 // \f[ 00015 // \rho(u) = 0.5 \log\bigl( 1 + \frac{u^2}{c^2} \bigr), 00016 // \f] 00017 // The associated weight function is 00018 // \f[ 00019 // w(u) = \frac{1}{1 + \frac{u^2}{c^2} }, 00020 // \f] 00021 // where u is a scale-normalized residual ($r/\sigma$) and $c$ is a 00022 // tuning constant. This should be used when a more gradual 00023 // rejection of outliers is desired than something like the 00024 // Beaton-Tukey biweight. 00025 00026 class rrel_cauchy_obj : public rrel_m_est_obj 00027 { 00028 public: 00029 //: Constructor. 00030 rrel_cauchy_obj( double C ); 00031 00032 //: Destructor. 00033 virtual ~rrel_cauchy_obj(); 00034 00035 //: The robust loss function for the M-estimator. 00036 virtual double rho( double u ) const; 00037 00038 //: The robust loss function for the M-estimator. 00039 // Overriding the overloaded version rho(u) hides the superclass' 00040 // implementation of this version of rho(). This implementation simply 00041 // calls the superclass' version of the same routine. 00042 // \a r is the residual and 00043 // \a s is the scale for that residual. 00044 virtual double rho( double r, double s ) const 00045 { return rrel_m_est_obj::rho(r, s); } 00046 00047 //: The weight of the residual. 00048 virtual double wgt( double u ) const; 00049 00050 //: Evaluate the objective function on heteroscedastic residuals. 00051 // Overriding the overloaded version wgt(u) hides the superclass' 00052 // implementation of this version of wgt(). This implementation simply 00053 // calls the superclass' version of the same routine. 00054 // \sa rrel_wls_obj::wgt() 00055 virtual void wgt( vect_const_iter res_begin, vect_const_iter res_end, 00056 vect_const_iter scale_begin, 00057 vect_iter wgt_begin ) const 00058 { rrel_m_est_obj::wgt(res_begin, res_end, scale_begin, wgt_begin); } 00059 00060 //: Computes the weights for homoscedastic residuals. 00061 // Overriding the overloaded version wgt(u) hides the superclass' 00062 // implementation of this version of wgt(). This implementation simply 00063 // calls the superclass' version of the same routine. 00064 // \sa rrel_wls_obj::wgt() 00065 virtual void wgt( vect_const_iter begin, vect_const_iter end, 00066 double scale, 00067 vect_iter wgt_begin ) const 00068 { rrel_m_est_obj::wgt(begin, end, scale, wgt_begin); } 00069 00070 //: The weight of the residual. 00071 // Overriding the overloaded version wgt(u) hides the superclass' 00072 // implementation of this version of wgt(). This implementation simply 00073 // calls the superclass' version of the same routine. 00074 // \a r is the residual and 00075 // \a s is the scale for that residual. 00076 virtual double wgt( double r, double s ) const 00077 { return rrel_m_est_obj::wgt(r, s); } 00078 00079 //: Fast version of the wgt(u) computation. 00080 inline double wgt_fast( double u ) const; 00081 00082 //: Fast version of the rho(u) computation. 00083 inline double rho_fast( double u ) const; 00084 00085 00086 private: 00087 double C_; 00088 }; 00089 00090 inline double 00091 rrel_cauchy_obj::rho_fast( double u ) const 00092 { 00093 return 0.5 * vcl_log( 1 + vnl_math_sqr( u/C_ ) ); 00094 } 00095 00096 inline double 00097 rrel_cauchy_obj::wgt_fast( double u ) const 00098 { 00099 return 1.0 / ( 1 + vnl_math_sqr(u/C_) ); 00100 } 00101 00102 #endif // rrel_cauchy_obj_h_