vpdt_mixture_detector.h
Go to the documentation of this file.
1 // This is core/vpdl/vpdt/vpdt_mixture_detector.h
2 #ifndef vpdt_mixture_detector_h_
3 #define vpdt_mixture_detector_h_
4 //:
5 // \file
6 // \brief Detectors applying to mixtures
7 // \author Matt Leotta (mleotta@lems.brown.edu)
8 // \date March 11, 2009
9 //
10 // \verbatim
11 // Modifications
12 // <None yet>
13 // \endverbatim
14 
16 
17 //: Apply a detector to each component to see if ANY match
18 // Return true if any component matches
19 template <class mixture_type, class detector_type>
21 {
22  public:
23  //: the functor return type
24  typedef bool return_type;
25  //: the functor return type
26  static const unsigned int return_dim = 1;
27  //: the distribution operated on by the detector
28  typedef mixture_type distribution_type;
29 
30  //: the data type to represent a point in the field
31  typedef typename mixture_type::field_type F;
32  //: define the scalar type (normally specified by template parameter T)
34 
35  //: Constructor
36  vpdt_mixture_any_detector(const detector_type& d) : detect(d) {}
37 
38  //: The main function
39  bool operator() (const mixture_type& mix, const F& sample, bool& result) const
40  {
41  result = false;
42  for (unsigned int i=0; i<mix.num_components(); ++i){
43  if ( !detect(mix.distribution(i),sample,result) )
44  return false;
45  if (result)
46  return true;
47  }
48  return true;
49  }
50 
51  //: The detector to apply to components
52  detector_type detect;
53 };
54 
55 
56 //: Apply a detector to each component to see if ALL match
57 // Return true if all components match
58 template <class mixture_type, class detector_type>
60 {
61  public:
62  //: the functor return type
63  typedef bool return_type;
64  //: the functor return type
65  static const unsigned int return_dim = 1;
66  //: the distribution operated on by the detector
67  typedef mixture_type distribution_type;
68 
69  //: the data type to represent a point in the field
70  typedef typename mixture_type::field_type F;
71  //: define the scalar type (normally specified by template parameter T)
73 
74  //: Constructor
75  vpdt_mixture_all_detector(const detector_type& d) : detect(d) {}
76 
77  //: The main function
78  bool operator() (const mixture_type& mix, const F& sample, bool& result) const
79  {
80  result = true;
81  for (unsigned int i=0; i<mix.num_components(); ++i){
82  if ( !detect(mix.distribution(i),sample,result) )
83  return false;
84  if (!result)
85  return true;
86  }
87  return true;
88  }
89 
90  //: The detector to apply to components
91  detector_type detect;
92 };
93 
94 
95 //: Apply a detector to each component in order while the total weight is below a threshold.
96 // Return true if any tested component matches
97 template <class mixture_type, class detector_type>
99 {
100  public:
101  //: the functor return type
102  typedef bool return_type;
103  //: the functor return type
104  static const unsigned int return_dim = 1;
105  //: the distribution operated on by the detector
106  typedef mixture_type distribution_type;
107 
108  //: the data type to represent a point in the field
109  typedef typename mixture_type::field_type F;
110  //: define the scalar type (normally specified by template parameter T)
112 
113  //: Constructor
114  vpdt_mixture_top_weight_detector(const detector_type& d, const T& w=T(0.5))
115  : detect(d), weight_thresh(w) {}
116 
117  //: The main function
118  bool operator() (const mixture_type& mix, const F& sample, bool& result) const
119  {
120  T total_weight = T(0);
121  result = false;
122  for (unsigned int i=0; i<mix.num_components(); ++i){
123  if (total_weight > weight_thresh)
124  return true;
125  if ( !detect(mix.distribution(i),sample,result) )
126  return false;
127  if (result)
128  return true;
129  total_weight += mix.weight(i);
130  }
131  return true;
132  }
133 
134  //: The detector to apply to components
135  detector_type detect;
136  //: The total weight threshold
138 };
139 
140 
141 #endif // vpdt_mixture_detector_h_
bool operator()(const mixture_type &mix, const F &sample, bool &result) const
The main function.
static const unsigned int return_dim
the functor return type.
Apply a detector to each component in order while the total weight is below a threshold.
detector_type detect
The detector to apply to components.
bool return_type
the functor return type.
vpdt_mixture_top_weight_detector(const detector_type &d, const T &w=T(0.5))
Constructor.
vpdt_mixture_all_detector(const detector_type &d)
Constructor.
T weight_thresh
The total weight threshold.
mixture_type distribution_type
the distribution operated on by the detector.
vpdt_field_traits< F >::scalar_type T
define the scalar type (normally specified by template parameter T).
bool return_type
the functor return type.
vpdt_field_traits< F >::scalar_type T
define the scalar type (normally specified by template parameter T).
Apply a detector to each component to see if ANY match.
mixture_type distribution_type
the distribution operated on by the detector.
static const unsigned int return_dim
the functor return type.
mixture_type::field_type F
the data type to represent a point in the field.
Apply a detector to each component to see if ALL match.
mixture_type::field_type F
the data type to represent a point in the field.
bool operator()(const mixture_type &mix, const F &sample, bool &result) const
The main function.
specialized template trait classes for properties of a field type
detector_type detect
The detector to apply to components.
detector_type detect
The detector to apply to components.
mixture_type distribution_type
the distribution operated on by the detector.
The field traits class (scalar).
vpdt_field_traits< F >::scalar_type T
define the scalar type (normally specified by template parameter T).
bool return_type
the functor return type.
static const unsigned int return_dim
the functor return type.
vpdt_mixture_any_detector(const detector_type &d)
Constructor.
mixture_type::field_type F
the data type to represent a point in the field.
bool operator()(const mixture_type &mix, const F &sample, bool &result) const
The main function.