Go to the documentation of this file.00001
00002 #ifndef vpdt_mixture_detector_h_
00003 #define vpdt_mixture_detector_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <vpdl/vpdt/vpdt_field_traits.h>
00016
00017
00018
00019 template <class mixture_type, class detector_type>
00020 class vpdt_mixture_any_detector
00021 {
00022 public:
00023
00024 typedef bool return_type;
00025
00026 static const unsigned int return_dim = 1;
00027
00028 typedef mixture_type distribution_type;
00029
00030
00031 typedef typename mixture_type::field_type F;
00032
00033 typedef typename vpdt_field_traits<F>::scalar_type T;
00034
00035
00036 vpdt_mixture_any_detector(const detector_type& d) : detect(d) {}
00037
00038
00039 bool operator() (const mixture_type& mix, const F& sample, bool& result) const
00040 {
00041 result = false;
00042 for (unsigned int i=0; i<mix.num_components(); ++i){
00043 if ( !detect(mix.distribution(i),sample,result) )
00044 return false;
00045 if (result)
00046 return true;
00047 }
00048 return true;
00049 }
00050
00051
00052 detector_type detect;
00053 };
00054
00055
00056
00057
00058 template <class mixture_type, class detector_type>
00059 class vpdt_mixture_all_detector
00060 {
00061 public:
00062
00063 typedef bool return_type;
00064
00065 static const unsigned int return_dim = 1;
00066
00067 typedef mixture_type distribution_type;
00068
00069
00070 typedef typename mixture_type::field_type F;
00071
00072 typedef typename vpdt_field_traits<F>::scalar_type T;
00073
00074
00075 vpdt_mixture_all_detector(const detector_type& d) : detect(d) {}
00076
00077
00078 bool operator() (const mixture_type& mix, const F& sample, bool& result) const
00079 {
00080 result = true;
00081 for (unsigned int i=0; i<mix.num_components(); ++i){
00082 if ( !detect(mix.distribution(i),sample,result) )
00083 return false;
00084 if (!result)
00085 return true;
00086 }
00087 return true;
00088 }
00089
00090
00091 detector_type detect;
00092 };
00093
00094
00095
00096
00097 template <class mixture_type, class detector_type>
00098 class vpdt_mixture_top_weight_detector
00099 {
00100 public:
00101
00102 typedef bool return_type;
00103
00104 static const unsigned int return_dim = 1;
00105
00106 typedef mixture_type distribution_type;
00107
00108
00109 typedef typename mixture_type::field_type F;
00110
00111 typedef typename vpdt_field_traits<F>::scalar_type T;
00112
00113
00114 vpdt_mixture_top_weight_detector(const detector_type& d, const T& w=T(0.5))
00115 : detect(d), weight_thresh(w) {}
00116
00117
00118 bool operator() (const mixture_type& mix, const F& sample, bool& result) const
00119 {
00120 T total_weight = T(0);
00121 result = false;
00122 for (unsigned int i=0; i<mix.num_components(); ++i){
00123 if (total_weight > weight_thresh)
00124 return true;
00125 if ( !detect(mix.distribution(i),sample,result) )
00126 return false;
00127 if (result)
00128 return true;
00129 total_weight += mix.weight(i);
00130 }
00131 return true;
00132 }
00133
00134
00135 detector_type detect;
00136
00137 T weight_thresh;
00138 };
00139
00140
00141 #endif // vpdt_mixture_detector_h_