Go to the documentation of this file.00001
00002 #ifndef bsta_mixture_functors_h_
00003 #define bsta_mixture_functors_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <bsta/bsta_mixture.h>
00016
00017
00018
00019 template <class mixture_, class functor_>
00020 class bsta_top_weight_functor
00021 {
00022 public:
00023 typedef typename mixture_::math_type T;
00024 typedef typename functor_::return_T return_T;
00025 typedef return_T return_type;
00026 typedef vnl_vector_fixed<T,mixture_::dimension> vector_;
00027 enum { return_dim = functor_::return_dim };
00028
00029
00030 bsta_top_weight_functor(const T& w=T(0.5)) : functor(), weight_thresh(w) {}
00031
00032 bsta_top_weight_functor(const functor_& f, const T& w=T(0.5))
00033 : functor(f), weight_thresh(w) {}
00034
00035
00036 bool operator() (const mixture_& mix, const vector_& sample, return_T& retval) const
00037 {
00038 const unsigned int nc = mix.num_components();
00039 if (nc == 0)
00040 return false;
00041
00042 return_T temp;
00043 if ( !functor(mix.distribution(0),sample,temp) )
00044 return false;
00045 T w = mix.weight(0);
00046 T total_weight = w;
00047 retval = w * temp;
00048
00049 for (unsigned int i=1; i<nc; ++i){
00050 if (total_weight > weight_thresh)
00051 break;
00052 if ( !functor(mix.distribution(i),sample,temp) )
00053 return false;
00054 w = mix.weight(i);
00055 total_weight += w;
00056 retval += w * temp;
00057 }
00058 retval /= total_weight;
00059 return true;
00060 }
00061
00062
00063 functor_ functor;
00064
00065 T weight_thresh;
00066 };
00067
00068
00069 #endif // bsta_mixture_functors_h_