vpdt_mog_fitness.h
Go to the documentation of this file.
1 // This is core/vpdl/vpdt/vpdt_mog_fitness.h
2 #ifndef vpdt_mog_fitness_h_
3 #define vpdt_mog_fitness_h_
4 //:
5 // \file
6 // \author Matt Leotta (mleotta@lems.brown.edu)
7 // \date March 8, 2009
8 // \brief Ordering functions for sorting mixtures of Gaussian components
9 
12 #include <cassert>
13 #ifdef _MSC_VER
14 # include <vcl_msvc_warnings.h>
15 #endif
16 
17 
18 //: The Stauffer-Grimson ordering function of mixture component fitness
19 // This is a generalization to non-scalar covariance
20 template <class gaussian_type, class Disambiguate = void>
22 {
23  typedef typename gaussian_type::metric_type Metric;
25 
26  static bool order (const gaussian_type& g1, const T& w1,
27  const gaussian_type& g2, const T& w2)
28  {
29  const unsigned int d = g1.dimension();
30  assert(d == g2.dimension());
31  T w1_2 = w1*w1, w2_2 = w2*w2;
32  T v1 = w1_2, v2 = w2_2;
33  for (unsigned int i=1; i<d; ++i){
34  v1 *= w1_2;
35  v2 *= w2_2;
36  }
37  return v1/Metric::covar_det(g1.mean,g1.covar) >
38  v2/Metric::covar_det(g2.mean,g2.covar);
39  }
40 };
41 
42 
43 //: helper class to check that two types are equal
44 template <class T1, class T2>
46 //: helper class to check that two types are equal
47 template <class T>
48 struct vpdt_is_equal<T,T> { typedef void type; };
49 
50 
51 //: The Stauffer-Grimson ordering function of mixture component fitness
52 // This is the simplified (original) version that applies to scalar covariance
53 template <class gaussian_type>
54 struct vpdt_mog_fitness<gaussian_type,
55  typename vpdt_is_equal<typename vpdt_dist_traits<gaussian_type>::scalar_type,
56  typename gaussian_type::covar_type>::type >
57 {
59 
60  static bool order (const gaussian_type& g1, const T& w1,
61  const gaussian_type& g2, const T& w2)
62  {
63  return w1*w1/g1.covar > w2*w2/g2.covar;
64  }
65 };
66 
67 
68 #endif // vpdt_mog_fitness_h_
The distribution traits class.
static bool order(const gaussian_type &g1, const T &w1, const gaussian_type &g2, const T &w2)
helper class to check that two types are equal.
The Stauffer-Grimson ordering function of mixture component fitness.
A generic Gaussian distribution.
gaussian_type::metric_type Metric
specialized template trait classes for properties of a field type
vpdt_dist_traits< gaussian_type >::scalar_type T
vpdt_field_traits< field_type >::scalar_type scalar_type
The type used for scalar operations.