contrib/brl/bbas/bsta/algo/bsta_truth_updater.h
Go to the documentation of this file.
00001 // This is brl/bbas/bsta/algo/bsta_truth_updater.h
00002 #ifndef bsta_truth_updater_h_
00003 #define bsta_truth_updater_h_
00004 //:
00005 // \file
00006 // \brief Ground truth mixture updater
00007 // \author Matt Leotta (mleotta@lems.brown.edu)
00008 // \date July 26, 2005
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   (none yet)
00013 // \endverbatim
00014 
00015 #include <bsta/bsta_mixture.h>
00016 #include <vnl/vnl_vector_fixed.h>
00017 
00018 
00019 //: An updater for ground truth mixtures
00020 template <class dist_, class updater_>
00021 class bsta_truth_updater
00022 {
00023   public:
00024     typedef typename dist_::math_type T;
00025     typedef typename dist_::vector_type sub_vector_;
00026     typedef vnl_vector_fixed<T,dist_::dimension+1> vector_;
00027 
00028     //: for compatibility with vpdl/vpdt
00029     typedef vector_ field_type;
00030     typedef dist_ distribution_type;
00031 
00032 
00033     enum {data_dimension = dist_::dimension+1};
00034 
00035     bsta_truth_updater (const dist_& model, const updater_& updater)
00036     : model_dist_(model), updater_mbr_(updater) {}
00037 
00038     //: The main function
00039     void operator() ( bsta_mixture<dist_>& mixture, const vector_& sample ) const
00040     {
00041       // The actual sample is stored in the first n-1 dimensions
00042       sub_vector_ data(sample.data_block());
00043 
00044       // Get the index from the last dimension
00045       unsigned int index = static_cast<unsigned int>(sample[dist_::dimension]);
00046 
00047       while (mixture.num_components() <= index)
00048         mixture.insert(model_dist_,T(0));
00049 
00050       updater_mbr_(mixture.distribution(index),data);
00051     }
00052 
00053   protected:
00054 
00055     //: A model for new distributions inserted
00056     dist_ model_dist_;
00057 
00058     //: The updater applied to the components
00059     updater_ updater_mbr_;
00060 };
00061 
00062 #endif // bsta_truth_updater_h_