core/vpdl/vpdt/vpdt_distribution_accessors.h
Go to the documentation of this file.
00001 // This is  core/vpdl/vpdt/vpdt_distribution_accessors.h
00002 #ifndef vpdt_distribution_accessors_h_
00003 #define vpdt_distribution_accessors_h_
00004 //:
00005 // \file
00006 // \brief Accessor functors that apply to all distributions
00007 // \author Matt Leotta (mleotta@lems.brown.edu)
00008 // \date March 15, 2009
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   (none yet)
00013 // \endverbatim
00014 
00015 #include <vpdl/vpdt/vpdt_dist_traits.h>
00016 
00017 
00018 //: An accessor to return the variable dimension of the distribution
00019 template <class dist_type>
00020 class vpdt_dimension_accessor
00021 {
00022 public:
00023   //: the functor return type
00024   typedef unsigned int return_type;
00025   //: the distribution operated on by the functor
00026   typedef dist_type distribution_type;
00027   //: is this functor valid for its distribution type
00028   static const bool valid_functor = true;
00029   
00030   //: rebind this functor to another distribution type
00031   template <class other_dist> 
00032   struct rebind {
00033     typedef vpdt_dimension_accessor<other_dist> other;
00034   };
00035   
00036   //: The main function
00037   bool operator() ( const dist_type& d, return_type& retval ) const
00038   {
00039     retval = d.dimension();
00040     return true;
00041   }
00042 };
00043 
00044 
00045 //: An accessor to return the mean of the distribution
00046 template <class dist_type>
00047 class vpdt_mean_accessor
00048 {
00049 public:
00050   //: the functor return type
00051   typedef typename dist_type::field_type return_type;
00052   //: the distribution operated on by the functor
00053   typedef dist_type distribution_type;
00054   //: is this functor valid for its distribution type
00055   static const bool valid_functor = true;
00056   
00057   //: rebind this functor to another distribution type
00058   template <class other_dist> 
00059   struct rebind {
00060     typedef vpdt_mean_accessor<other_dist> other;
00061   };
00062   
00063   //: The main function
00064   bool operator() ( const dist_type& d, return_type& retval ) const
00065   {
00066     d.compute_mean(retval);
00067     return true;
00068   }
00069 };
00070 
00071 
00072 //: An accessor to return the covariance of the distribution
00073 template <class dist_type>
00074 class vpdt_covar_accessor
00075 {
00076 public:
00077   //: the functor return type
00078   typedef typename vpdt_dist_traits<dist_type>::matrix_type return_type;
00079   //: the distribution operated on by the functor
00080   typedef dist_type distribution_type;
00081   //: is this functor valid for its distribution type
00082   static const bool valid_functor = true;
00083   
00084   //: rebind this functor to another distribution type
00085   template <class other_dist> 
00086   struct rebind {
00087     typedef vpdt_covar_accessor<other_dist> other;
00088   };
00089   
00090   //: The main function
00091   bool operator() ( const dist_type& d, return_type& retval ) const
00092   {
00093     d.compute_covar(retval);
00094     return true;
00095   }
00096 };
00097 
00098 
00099 //: An accessor to return the normalization constant of the distribution
00100 template <class dist_type>
00101 class vpdt_norm_const_accessor
00102 {
00103 public:
00104   //: the functor return type
00105   typedef typename vpdt_dist_traits<dist_type>::scalar_type return_type;
00106   //: the distribution operated on by the functor
00107   typedef dist_type distribution_type;
00108   //: is this functor valid for its distribution type
00109   static const bool valid_functor = true;
00110   
00111   //: rebind this functor to another distribution type
00112   template <class other_dist> 
00113   struct rebind {
00114     typedef vpdt_norm_const_accessor<other_dist> other;
00115   };
00116   
00117   //: The main function
00118   bool operator() ( const dist_type& d, return_type& retval ) const
00119   {
00120     retval = d.norm_const();
00121     return true;
00122   }
00123 };
00124 
00125 
00126 #endif // vpdt_distribution_accessors_h_