contrib/brl/bbas/bsta/bsta_attributes.h
Go to the documentation of this file.
00001 // This is brl/bbas/bsta/bsta_attributes.h
00002 #ifndef bsta_attributes_h_
00003 #define bsta_attributes_h_
00004 //:
00005 // \file
00006 // \brief Attributes for distributions
00007 // \author Matt Leotta (mleotta@lems.brown.edu)
00008 // \date January 26, 2006
00009 //
00010 // Some algorithms require distributions to maintain additional
00011 // attributes.  Attributes inherit from a distribution and
00012 // add new functionality.
00013 //
00014 // do not remove the following text
00015 // Approved for public release, distribution unlimited (DISTAR Case 14389)
00016 //
00017 
00018 #include "bsta_distribution.h"
00019 #include <vcl_iostream.h>
00020 #include <vpdl/vpdt/vpdt_dist_traits.h>
00021 
00022 //: Adds number of observations
00023 template <class dist_>
00024 class bsta_num_obs : public dist_
00025 {
00026   typedef typename dist_::math_type T;
00027 
00028  public:
00029 
00030   typedef dist_ contained_type;
00031 
00032   //: Constructor
00033   bsta_num_obs<dist_>() : dist_(), num_observations(T(0)) {}
00034 
00035   //: Constructor - somewhat like a copy constructor
00036   bsta_num_obs<dist_>(const dist_& d, const T& n_obs = T(0))
00037     : dist_(d), num_observations(n_obs) {}
00038 
00039   //: The number of observations
00040   T num_observations;
00041 };
00042 
00043 template <class dist_>
00044 inline vcl_ostream& operator<< (vcl_ostream& os,
00045                                 bsta_num_obs<dist_> const& no)
00046 {
00047   dist_ const& dist = static_cast<dist_ const&>(no);
00048   os << "n_obs:" << no.num_observations << '\n'
00049      << dist ;
00050   return os;
00051 }
00052 
00053 //: for compatibility with vpdl/vpdt
00054 template <class dist>
00055 struct vpdt_is_mixture<bsta_num_obs<dist> >
00056 {
00057   static const bool value = vpdt_is_mixture<dist>::value;
00058 };
00059 
00060 
00061 //: maintains a vector sum and number of observations needed for the von mises distribution
00062 template <class dist_>
00063 class bsta_vsum_num_obs : public dist_
00064 {
00065   typedef typename dist_::math_type T;
00066   typedef typename dist_::vector_type vect_t;
00067 
00068  public:
00069 
00070   typedef dist_ contained_type;
00071 
00072   //: Constructor
00073   bsta_vsum_num_obs<dist_>() : dist_(), num_observations(T(0)), vector_sum(vect_t(T(0))) {}
00074 
00075   //: Constructor - somewhat like a copy constructor
00076   bsta_vsum_num_obs<dist_>(const dist_& d, const vect_t & vsum = vect_t(T(0)), const T& n_obs = T(0))
00077   : dist_(d), num_observations(n_obs), vector_sum(vsum) {}
00078 
00079   //: The number of observations
00080   T num_observations;
00081   vect_t vector_sum;
00082 };
00083 
00084 template <class dist_>
00085 inline vcl_ostream& operator<< (vcl_ostream& os,
00086                                 bsta_vsum_num_obs<dist_> const& vno)
00087 {
00088   dist_ const& dist = static_cast<dist_ const&>(vno);
00089   os << "n_obs:" << vno.num_observations << '\n'
00090      << "vector_sum:" << vno.vector_sum << '\n'
00091      << dist ;
00092   return os;
00093 }
00094 
00095 //: for compatibility with vpdl/vpdt
00096 template <class dist>
00097 struct vpdt_is_mixture<bsta_vsum_num_obs<dist> >
00098 {
00099   static const bool value = vpdt_is_mixture<dist>::value;
00100 };
00101 
00102 
00103 #endif // bsta_attributes_h_