00001 // This is rpl/rrel/rrel_util.h 00002 #ifndef rrel_util_h_ 00003 #define rrel_util_h_ 00004 //: 00005 // \file 00006 // \author Chuck Stewart 00007 // \date Summer 2001 00008 00009 #include <vcl_iterator.h> 00010 00011 //: \brief Compute the median absolute deviation (MAD) scale estimate of the residuals. 00012 // 00013 // Find the median absolve deviation (MAD) scale estimate of a set of 00014 // residuals. Assume a Gaussian target distribution. The input 00015 // residuals may be signed or unsigned values, but they are converted 00016 // to unsigned. The order of the residuals is destroyed. 00017 // 00018 // The iterators should be random access iterators. 00019 // 00020 // The dummy parameter is used to determine the return type: 00021 // \code 00022 // float s = rrel_util_median_abs_dev_scale( v.begin(), v.end(), 1, (float*)0 ); 00023 // \endcode 00024 // 00025 template <class O, class RanIter> 00026 O 00027 rrel_util_median_abs_dev_scale( const RanIter& begin, const RanIter& end, int dof, O* ); 00028 00029 //: Convenience function. 00030 // Calls the other rrel_util_median_abs_dev_scale() with a return type 00031 // of double. 00032 // 00033 template <class T> 00034 double 00035 rrel_util_median_abs_dev_scale( const T& begin, const T& end, int dof=1 ) 00036 { 00037 return rrel_util_median_abs_dev_scale( begin, end, dof, (double*)0 ); 00038 } 00039 00040 //: \brief Compute the scale using robustly weighted residuals. 00041 // 00042 // Compute the scale using robustly weighted residuals. The dummy 00043 // parameter is used to determine the return type. Internal 00044 // calculations are also done with this type. 00045 // 00046 // The iterators should be input iterators. 00047 // 00048 // \code 00049 // float s = rrel_util_weighted_scale( r.begin(), r.end(), 00050 // w.begin(), w.end(), 1, (float*)0 ); 00051 // \endcode 00052 // 00053 template <class O, class InpIter> 00054 O 00055 rrel_util_weighted_scale( const InpIter& residuals_first, const InpIter& residuals_end, 00056 const InpIter& weights_first, int dof, O* ); 00057 00058 #if !VCL_TEMPLATE_MATCHES_TOO_OFTEN // not for compilers with overload problems 00059 00060 //: Convenience function. 00061 // Calls the other rrel_util_weighted_scale() with a return type of 00062 // double. 00063 // 00064 template <class InpIter> 00065 inline double 00066 rrel_util_weighted_scale( const InpIter& residuals_first, const InpIter& residuals_end, 00067 const InpIter& weights_first, int dof=1 ) 00068 { 00069 return rrel_util_weighted_scale( residuals_first, residuals_end, 00070 weights_first, dof, (double*)0 ); 00071 } 00072 00073 #endif 00074 00075 //: Compute the median and the scale (relative to the median). 00076 // 00077 // Find the median and then, using the median of absolute 00078 // deviations from the median, the scale. Assume a Gaussian target 00079 // distribution. Both the order and the values themselves are changed. 00080 // Random access iterators are required. 00081 // 00082 template <class T, class RanIter> 00083 void rrel_util_median_and_scale( RanIter first, RanIter last, 00084 T& median, T& scale, 00085 int dof=1 ); 00086 00087 00088 //: Compute the median and the scale (relative to the median). 00089 // 00090 // Same as rrel_util_median_and_scale(), except that the input is 00091 // copied first, and so is unchanged. 00092 // 00093 template <class T, class InpIter> 00094 void rrel_util_median_and_scale_copy( InpIter first, InpIter last, 00095 T& median, T& scale, 00096 int dof=1 ); 00097 00098 00099 //: \brief Compute the center and half width of the narrowest interval containing half the points in the residuals. 00100 // 00101 // Find the center and half width of the narrowest interval 00102 // containing half the points in the input set of residuals, accessed 00103 // through the iterators first and last. This is the "intercept 00104 // adjustment" technique of Rousseeuw (J. Amer. Stat. Assoc. 1984). 00105 // The order of the residuals is destroyed and in fact, as a side 00106 // effect, the residuals are sorted. The residuals are assumed to be 00107 // signed values. 00108 // 00109 template <class T, class RanIter> 00110 void rrel_util_intercept_adjustment( RanIter first, RanIter last, 00111 T & center, T & half_width, 00112 int dof=1 ); 00113 00114 00115 //: \brief Compute the center and half width of the narrowest interval containing half the points in the residuals. 00116 // 00117 // Same as rrel_util_intercept_adjustment(), except that the input is 00118 // copied first, and so is unchanged. 00119 // 00120 template <class T, class InpIter> 00121 void rrel_util_intercept_adjustment_copy( InpIter first, InpIter last, 00122 T & center, T & half_width, 00123 int dof=1 ); 00124 00125 00126 //: \brief Use the intercept adjustment technique to estimate the robust mean, standard deviation, and inlier fraction. 00127 // 00128 template <class T, class RanIter> 00129 void rrel_util_intercept_adjust_stats( RanIter first, RanIter last, 00130 T & robust_mean, T & robust_std, T & inlier_frac, 00131 int dof=1 ); 00132 00133 00134 //: \brief Use the intercept adjustment technique to estimate the robust mean, standard deviation, and inlier fraction. 00135 // 00136 // Same as rrel_util_intercept_adjustment_stats(), except that the input is 00137 // copied first, and so is unchanged. 00138 // 00139 template <class T, class InpIter> 00140 void rrel_util_intercept_adjust_stats_copy( InpIter first, InpIter last, 00141 T & robust_mean, T & robust_std, T & inlier_frac, 00142 int dof=1 ); 00143 00144 #if defined(VCL_GCC_32) || defined(VCL_GCC_33) || defined(VCL_GCC_34) || defined(VCL_GCC_4) 00145 # include "rrel_util.txx" 00146 #endif 00147 00148 #endif // rrel_util_h_