contrib/brl/bbas/bsta/bsta_detector_mixture.h
Go to the documentation of this file.
00001 // This is brl/bbas/bsta/bsta_detector_mixture.h
00002 #ifndef bsta_detector_mixture_h_
00003 #define bsta_detector_mixture_h_
00004 //:
00005 // \file
00006 // \brief Detectors applying to mixtures
00007 // \author Matt Leotta (mleotta@lems.brown.edu)
00008 // \date February 09, 2006
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   (none yet)
00013 // \endverbatim
00014 
00015 
00016 //: Apply a detector to each component in order while the total weight is below a threshold.
00017 //  Return true if any tested component matches
00018 template <class mixture_, class detector_>
00019 class bsta_top_weight_detector
00020 {
00021   public:
00022     typedef bool return_T;
00023     enum { return_dim = 1 };
00024     typedef typename mixture_::math_type T;
00025     typedef typename mixture_::vector_type vector_;
00026 
00027     // for compatibility with vpdl/vdpt
00028     typedef return_T return_type;
00029     typedef mixture_ distribution_type;
00030 
00031     //: Constructor
00032     bsta_top_weight_detector(const detector_& d, const T& w=T(0.5))
00033       : detect(d), weight_thresh(w) {}
00034 
00035     //: The main function
00036     bool operator() (const mixture_& mix, const vector_& sample, bool& result) const
00037     {
00038       T total_weight = T(0);
00039       result = false;
00040       for (unsigned int i=0; i<mix.num_components(); ++i){
00041         if (total_weight > weight_thresh)
00042           return true;
00043         if ( !detect(mix.distribution(i),sample,result) )
00044           return false;
00045         if (result)
00046           return true;
00047         total_weight += mix.weight(i);
00048       }
00049       return true;
00050     }
00051 
00052     //: The detector to apply to components
00053     detector_ detect;
00054     //: The index to detect
00055     T weight_thresh;
00056 };
00057 
00058 
00059 //: Apply a detector to each component in order while the total weight is below a threshold.
00060 // Return true if any tested component matches
00061 template <class mixture_, class detector_>
00062 class bsta_mix_any_less_index_detector
00063 {
00064   public:
00065     typedef bool return_T;
00066     enum { return_dim = 1 };
00067     typedef typename mixture_::math_type T;
00068     typedef typename mixture_::vector_type vector_;
00069 
00070     // for compatibility with vpdl/vdpt
00071     typedef return_T return_type;
00072     typedef mixture_ distribution_type;
00073 
00074     //: Constructor
00075     bsta_mix_any_less_index_detector(const detector_& d, const T& w=T(0.5))
00076       : detect(d), weight_thresh(w) {}
00077 
00078     //: The main function
00079     bool operator() (const mixture_& mix, const vector_& sample, bool& result) const
00080     {
00081       T total_weight = T(0);
00082       result = false;
00083 
00084       bool flag=false;
00085       for (unsigned int i=0; i<mix.num_components(); ++i){
00086         if (mix.weight(i) > weight_thresh)
00087         {
00088           flag=true;
00089           if ( !detect(mix.distribution(i),sample,result) )
00090             return false;
00091           if (result)
00092             return true;
00093         }
00094         //total_weight += mix.weight(i);
00095       }
00096 
00097       return !flag;
00098     }
00099 
00100     //: The detector to apply to components
00101     detector_ detect;
00102     //: The index to detect
00103     T weight_thresh;
00104 };
00105 
00106 #endif