contrib/brl/bbas/bsta/algo/bsta_von_mises_updater.h
Go to the documentation of this file.
00001 // This is brl/bbas/bsta/algo/bsta_von_mises_updater.h
00002 #ifndef bsta_von_mises_updater_h_
00003 #define bsta_von_mises_updater_h_
00004 //:
00005 // \file
00006 // \brief Von_Mises updaters
00007 // \author Joseph L. Mundy
00008 // \date July 18, 2009
00009 //
00010 // This file contains updaters based on
00011 // Von_Mises distributions
00012 //
00013 // \verbatim
00014 //  Modifications
00015 //   (none yet)
00016 // \endverbatim
00017 //
00018 // do not remove the following text
00019 // Approved for public release, distribution unlimited (DISTAR Case 14389)
00020 //
00021 
00022 #include <bsta/bsta_von_mises.h>
00023 #include <bsta/bsta_attributes.h>
00024 #include <vcl_algorithm.h>
00025 #include <vcl_cmath.h>
00026 #include <vcl_vector.h>
00027 
00028 //: A von_mises window updater based on samples of the space of unit vectors.
00029 // Implemented only for vector dimensions 2 and 3.
00030 template <class von_mises_dist_>
00031 class bsta_von_mises_updater
00032 {
00033  public:
00034   typedef typename von_mises_dist_::math_type math_t;
00035   typedef typename von_mises_dist_::vector_type vect_t;
00036   typedef bsta_vsum_num_obs<von_mises_dist_> obs_vm_dist_;
00037   //: for compatibility with vpdl/vpdt
00038   typedef obs_vm_dist_ distribution_type;
00039   enum { data_dimension = von_mises_dist_::data_dimension };
00040   //: for compatibility with vpdl/vpdt
00041   typedef typename von_mises_dist_::field_type field_type;
00042 
00043   // Constructor
00044   // initial_kappa_ is assigned when only one sample has been observed
00045   bsta_von_mises_updater(math_t kappa= math_t(10000)):
00046     initial_kappa_(kappa){}
00047 
00048   //: The update functor assuming standard learning rate
00049   void operator ()(obs_vm_dist_& pdist, const vect_t& sample) const{
00050     pdist.num_observations += math_t(1);
00051     pdist.vector_sum += sample;
00052     this->update(pdist, pdist.vector_sum, math_t(1)/pdist.num_observations);
00053   }
00054   //: The update functor with a learning rate specified
00055   void operator ()(obs_vm_dist_& pdist, const vect_t& sample, math_t alpha) const{
00056     pdist.num_observations += math_t(1);
00057     pdist.vector_sum += sample;
00058     this->update(pdist, pdist.vector_sum, alpha);
00059   }
00060  private:
00061   void update(obs_vm_dist_& pdist, const vect_t& vsum, math_t alpha) const;
00062   math_t initial_kappa_;
00063 };
00064 
00065 
00066 #endif // bsta_von_mises_updater_h_