vpdt_mixture_accessors.h
Go to the documentation of this file.
1 // This is core/vpdl/vpdt/vpdt_mixture_accessors.h
2 #ifndef vpdt_mixture_accessors_h_
3 #define vpdt_mixture_accessors_h_
4 //:
5 // \file
6 // \brief Accessor functors that apply to all mixture distributions
7 // \author Matt Leotta (mleotta@lems.brown.edu)
8 // \date March 15, 2009
9 //
10 // \verbatim
11 // Modifications
12 // (none yet)
13 // \endverbatim
14 
17 
18 
19 //: A functor to return the number of components in a mixture
20 // This is a dummy class for non-mixture types; it always fails
21 template <class mixture_type, class Disambiguate=void>
23 {
24  public:
25  //: the functor return type
26  typedef unsigned int return_type;
27  //: the distribution operated on by the functor
28  typedef mixture_type distribution_type;
29  //: is this functor valid for its distribution type
30  static const bool valid_functor = false;
31 
32  //: rebind this functor to another distribution type
33  template <class other_dist>
34  struct rebind {
36  };
37 
38  //: The main function
39  bool operator() ( const mixture_type& mix, return_type& retval ) const
40  {
41  return false;
42  }
43 };
44 
45 //
46 //: A functor to return the number of components in a mixture
47 template <class mixture_type>
48 class vpdt_num_components_accessor<mixture_type,
49  typename vpdt_enable_if<vpdt_is_mixture<mixture_type> >::type>
50 {
51  public:
52  //: the functor return type
53  typedef unsigned int return_type;
54  //: the distribution operated on by the functor
55  typedef mixture_type distribution_type;
56  //: is this functor valid for its distribution type
57  static const bool valid_functor = true;
58 
59  //: rebind this functor to another distribution type
60  template <class other_dist>
61  struct rebind {
63  };
64 
65  //: The main function
66  bool operator() ( const mixture_type& mix, return_type& retval ) const
67  {
68  retval = mix.num_components();
69  return true;
70  }
71 };
72 
73 
74 //: A functor to return the weight of the component with given index
75 template <class mixture_type, class Disambiguate=void>
77 {
78  public:
79  //: the functor return type
81  //: the distribution operated on by the functor
82  typedef mixture_type distribution_type;
83  //: is this functor valid for its distribution type
84  static const bool valid_functor = false;
85 
86  //: rebind this functor to another distribution type
87  template <class other_dist>
88  struct rebind {
90  };
91 
92  //: Constructor
93  vpdt_weight_accessor(unsigned int index = 0) {}
94 
95  //: The main function
96  bool operator() ( const mixture_type& mix, return_type& retval ) const
97  {
98  return false;
99  }
100 };
101 
102 
103 //: A functor to return the weight of the component with given index
104 template <class mixture_type>
105 class vpdt_weight_accessor<mixture_type,
106  typename vpdt_enable_if<vpdt_is_mixture<mixture_type> >::type>
107 {
108  public:
109  //: the functor return type
111  //: the distribution operated on by the functor
112  typedef mixture_type distribution_type;
113  //: is this functor valid for its distribution type
114  static const bool valid_functor = true;
115 
116  //: rebind this functor to another distribution type
117  template <class other_dist>
118  struct rebind {
120  };
121 
122  //: Constructor
123  vpdt_weight_accessor(unsigned int index = 0) : idx(index) {}
124 
125  //: The main function
126  bool operator() ( const mixture_type& mix, return_type& retval ) const
127  {
128  if (idx < mix.num_components()){
129  retval = mix.weight(idx);
130  return true;
131  }
132  return false;
133  }
134 
135  //: The component index
136  unsigned int idx;
137 };
138 
139 
140 //: A functor to apply another functor to the component with given index
141 template <class mixture_type, class accessor_type, class Disambiguate=void>
143 {
144  public:
145  //: the functor return type
146  typedef typename accessor_type::return_type return_type;
147  //: the distribution operated on by the functor
148  typedef mixture_type distribution_type;
149  //: is this functor valid for its distribution type
150  static const bool valid_functor = false;
151 
152  //: rebind this functor to another distribution type
153  template <class other_dist, class other_accessor = accessor_type>
154  struct rebind {
156  };
157 
158  //: Constructor
159  vpdt_mixture_accessor(unsigned int index = 0) {}
160 
161  //: Constructor
162  vpdt_mixture_accessor(const accessor_type& a, unsigned int index = 0) {}
163 
164  //: The main function
165  bool operator() ( const mixture_type& mix, return_type& retval ) const
166  {
167  return false;
168  }
169 };
170 
171 
172 //: A functor to apply another functor to the component with given index
173 template <class mixture_type, class accessor_type>
174 class vpdt_mixture_accessor<mixture_type,accessor_type,
175  typename vpdt_enable_if<vpdt_is_mixture<mixture_type> >::type>
176 {
177  public:
178  //: the functor return type
179  typedef typename accessor_type::return_type return_type;
180  //: the distribution operated on by the functor
181  typedef mixture_type distribution_type;
182  //: is this functor valid for its distribution type
183  static const bool valid_functor = true;
184 
185  //: rebind this functor to another distribution type
186  template <class other_dist, class other_accessor = accessor_type>
187  struct rebind {
189  };
190 
191  //: Constructor
192  vpdt_mixture_accessor(unsigned int index = 0)
193  : accessor(), idx(index) {}
194 
195  //: Constructor
196  vpdt_mixture_accessor(const accessor_type& a, unsigned int index = 0)
197  : accessor(a), idx(index) {}
198 
199  //: The main function
200  bool operator() ( const mixture_type& mix, return_type& retval ) const
201  {
202  if (idx < mix.num_components()){
203  return accessor(mix.distribution(idx),retval);
204  }
205  return false;
206  }
207 
208  //: The accessor to apply
209  accessor_type accessor;
210  //: The component index
211  unsigned int idx;
212 };
213 
214 
215 //: A specialization to make the weight accessor work as a mixture accessor
216 template <class mixture_type>
217 class vpdt_mixture_accessor<mixture_type,
218  vpdt_weight_accessor<typename mixture_type::component_type>,
219  typename vpdt_enable_if<vpdt_is_mixture<mixture_type> >::type>
220 {
221  public:
222  //: the accessor type
224  //: the functor return type
226  //: the distribution operated on by the functor
227  typedef mixture_type distribution_type;
228  //: is this functor valid for its distribution type
229  static const bool valid_functor = true;
230 
231  //: rebind this functor to another distribution type
232  template <class other_dist, class other_accessor = accessor_type>
233  struct rebind {
235  };
236 
237  //: Constructor
238  vpdt_mixture_accessor(unsigned int index = 0)
239  : idx(index) {}
240 
241  //: Constructor
242  vpdt_mixture_accessor(const accessor_type& a, unsigned int index = 0)
243  : idx(index) {}
244 
245  //: The main function
246  bool operator() ( const mixture_type& mix, return_type& retval ) const
247  {
248  if (idx < mix.num_components()){
249  retval = mix.weight(idx);
250  return true;
251  }
252  return false;
253  }
254 
255  //: The component index
256  unsigned int idx;
257 };
258 
259 
260 #endif // vpdt_mixture_accessors_h_
rebind this functor to another distribution type.
rebind this functor to another distribution type.
A functor to return the number of components in a mixture.
A functor to return the weight of the component with given index.
rebind this functor to another distribution type.
vpdt_dist_traits< mixture_type >::scalar_type return_type
the functor return type.
bool operator()(const mixture_type &mix, return_type &retval) const
The main function.
vpdt_weight_accessor< other_dist > other
bool operator()(const mixture_type &mix, return_type &retval) const
The main function.
vpdt_num_components_accessor< other_dist > other
mixture_type distribution_type
the distribution operated on by the functor.
static const bool valid_functor
is this functor valid for its distribution type.
vpdt_mixture_accessor< other_dist, other_accessor > other
unsigned int return_type
the functor return type.
vpdt_mixture_accessor(unsigned int index=0)
Constructor.
vpdt_mixture_accessor(const accessor_type &a, unsigned int index=0)
Constructor.
bool operator()(const mixture_type &mix, return_type &retval) const
The main function.
A functor to apply another functor to the component with given index.
static const bool valid_functor
is this functor valid for its distribution type.
mixture_type distribution_type
the distribution operated on by the functor.
vpdt_weight_accessor(unsigned int index=0)
Constructor.
mixture_type distribution_type
the distribution operated on by the functor.
static const bool valid_functor
is this functor valid for its distribution type.
Use static booleans to control template instantiation.
accessor_type::return_type return_type
the functor return type.
specialized template trait classes for properties of a distribution type
vpdt_field_traits< field_type >::scalar_type scalar_type
The type used for scalar operations.