contrib/rpl/rrel/rrel_lms_obj.h
Go to the documentation of this file.
00001 #ifndef rrel_lms_obj_h_
00002 #define rrel_lms_obj_h_
00003 //:
00004 // \file
00005 // \author Chuck Stewart (stewart@cs.rpi.edu)
00006 // \brief The Least-Median-of-Squares (LMS) objective function
00007 //
00008 // \verbatim
00009 //   2004-04, Charlene Tsai (tsaic@cs.rpi.edu). Added scale(.) function.
00010 // \endverbatim
00011 
00012 #include <rrel/rrel_objective.h>
00013 
00014 //: The Least-Median-of-Squares (LMS) objective function.
00015 //
00016 //  The Least-Median-of-Squares algorithm was defined in a 1984
00017 //  Journal of the American Statistical Association paper by Peter
00018 //  Rousseeuw (vol 79, pp 871-880).  (See Stewart, "Robust Parameter
00019 //  Estimation in Computer Vision", SIAM Reviews 41, Sept 1999.)  The
00020 //  class implemented here gives the objective function for that
00021 //  algorithm. The LMS objective function is the median of the squared
00022 //  residuals. This class is generalised to allow any inlier fraction
00023 //  (not just the median) from the order statistics.
00024 
00025 class rrel_lms_obj : public rrel_objective
00026 {
00027  public:
00028   //: Constructor.
00029   //  \a num_sam_inst is the minimum number of samples needed for
00030   //  a unique parameter estimate. That is, num_sam_inst should be set
00031   //  to rrel_estimation_problem::num_samples_to_instantiate(). \a
00032   //  inlier_frac is the minimum expected number of inlier
00033   //  residuals. The default value of 0.5 makes this the standard
00034   //  median objective function. In general, it should be 1 minus the
00035   //  maximum expected fraction of outliers. If the maximum expected
00036   //  fraction of outliers is not known, then the MUSE objective
00037   //  function should be used.
00038   rrel_lms_obj( unsigned int num_sam_inst, double inlier_frac=0.5 );
00039 
00040   ~rrel_lms_obj();
00041 
00042   //: Evaluate the objective function on heteroscedastic residuals.
00043   //  \sa rrel_objective::fcn.
00044   virtual double fcn( vect_const_iter res_begin, vect_const_iter res_end,
00045                       vect_const_iter /* scale is unused */,
00046                       vnl_vector<double>* = 0 /* param vector is unused */ ) const;
00047 
00048   //: Evaluate the objective function on homoscedastic residuals.
00049   //  \sa rrel_objective::fcn.
00050   virtual double fcn( vect_const_iter begin, vect_const_iter end,
00051                       double = 0 /* scale is unused */,
00052                       vnl_vector<double>* = 0 /* param vector is unused */ ) const;
00053 
00054   //: False.
00055   //  The LMS objective is based on order statistics, and does not
00056   //  require any scale parameter, estimated or otherwise.
00057   virtual bool requires_prior_scale() const
00058     { return false; }
00059 
00060   //: True. The scale is estimated as MAD (Median Absolute Deviation)
00061   //  \sa rrel_objective::can_estimate_scale.
00062   virtual bool can_estimate_scale() const { return true; }
00063 
00064   //: Scale estimate (median absolute deviation -- MAD).
00065   //  \sa rrel_util_median_abs_dev_scale(.)
00066   virtual double scale( vect_const_iter res_begin, vect_const_iter res_end ) const;
00067 
00068  protected:
00069   //: Number of samples needed for a unique fit = number of dependent residuals.
00070   unsigned int num_sam_inst_;
00071   double inlier_frac_;
00072 };
00073 
00074 #endif // rrel_lms_obj_h_