Go to the documentation of this file.00001
00002 #ifndef bsta_detector_mixture_h_
00003 #define bsta_detector_mixture_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00028 typedef return_T return_type;
00029 typedef mixture_ distribution_type;
00030
00031
00032 bsta_top_weight_detector(const detector_& d, const T& w=T(0.5))
00033 : detect(d), weight_thresh(w) {}
00034
00035
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
00053 detector_ detect;
00054
00055 T weight_thresh;
00056 };
00057
00058
00059
00060
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
00071 typedef return_T return_type;
00072 typedef mixture_ distribution_type;
00073
00074
00075 bsta_mix_any_less_index_detector(const detector_& d, const T& w=T(0.5))
00076 : detect(d), weight_thresh(w) {}
00077
00078
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
00095 }
00096
00097 return !flag;
00098 }
00099
00100
00101 detector_ detect;
00102
00103 T weight_thresh;
00104 };
00105
00106 #endif