core/vpdl/vpdt/vpdt_mog_fitness.h
Go to the documentation of this file.
00001 // This is core/vpdl/vpdt/vpdt_mog_fitness.h
00002 #ifndef vpdt_mog_fitness_h_
00003 #define vpdt_mog_fitness_h_
00004 //:
00005 // \file
00006 // \author Matt Leotta (mleotta@lems.brown.edu)
00007 // \date March 8, 2009
00008 // \brief Ordering functions for sorting mixtures of Gaussian components
00009 
00010 #include <vpdl/vpdt/vpdt_field_traits.h>
00011 #include <vpdl/vpdt/vpdt_gaussian.h>
00012 #include <vcl_cassert.h>
00013 
00014 
00015 //: The Stauffer-Grimson ordering function of mixture component fitness
00016 //  This is a generalization to non-scalar covariance
00017 template <class gaussian_type, class Disambiguate = void>
00018 struct vpdt_mog_fitness
00019 {
00020   typedef typename gaussian_type::metric_type Metric;
00021   typedef typename vpdt_dist_traits<gaussian_type>::scalar_type T;
00022 
00023   static bool order (const gaussian_type& g1, const T& w1,
00024                      const gaussian_type& g2, const T& w2)
00025   {
00026     const unsigned int d = g1.dimension();
00027     assert(d == g2.dimension());
00028     T w1_2 = w1*w1, w2_2 = w2*w2;
00029     T v1 = w1_2, v2 = w2_2;
00030     for (unsigned int i=1; i<d; ++i){
00031       v1 *= w1_2;
00032       v2 *= w2_2;
00033     }
00034     return v1/Metric::covar_det(g1.mean,g1.covar) >
00035     v2/Metric::covar_det(g2.mean,g2.covar);
00036   }
00037 };
00038 
00039 
00040 //: helper class to check that two types are equal
00041 template <class T1, class T2>
00042 struct vpdt_is_equal;
00043 //: helper class to check that two types are equal
00044 template <class T>
00045 struct vpdt_is_equal<T,T> { typedef void type; };
00046 
00047 
00048 //: The Stauffer-Grimson ordering function of mixture component fitness
00049 //  This is the simplified (original) version that applies to scalar covariance
00050 template <class gaussian_type>
00051 struct vpdt_mog_fitness<gaussian_type,
00052                         typename vpdt_is_equal<typename vpdt_dist_traits<gaussian_type>::scalar_type,
00053                                                typename gaussian_type::covar_type>::type >
00054 {
00055   typedef typename vpdt_dist_traits<gaussian_type>::scalar_type T;
00056 
00057   static bool order (const gaussian_type& g1, const T& w1,
00058                      const gaussian_type& g2, const T& w2)
00059   {
00060     return w1*w1/g1.covar > w2*w2/g2.covar;
00061   }
00062 };
00063 
00064 
00065 #endif // vpdt_mog_fitness_h_