contrib/brl/bbas/bsta/bsta_sampler.h
Go to the documentation of this file.
00001 // This is brl/bbas/bsta/bsta_sampler.h
00002 #ifndef bsta_sampler_h_
00003 #define bsta_sampler_h_
00004 //:
00005 // \file
00006 // \brief Various sampling techniques to aid bsta library
00007 // \author Ozge C. Ozcanli
00008 // \date December 09, 2008
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   Ozge C. Ozcanli - Dec 09, 2008 - Added an algorithm to sample from a "set of samples with given probabilities"
00013 //   Daniel E. Crispell - Feb. 22, 2010 - Added versions of functions that allow user to provide own vnl_random object
00014 // \endverbatim
00015 
00016 #include <vcl_vector.h>
00017 #include <vcl_utility.h>
00018 #include <vnl/vnl_random.h>
00019 #include <bsta/bsta_joint_histogram.h>
00020 
00021 template <class T>
00022 class bsta_sampler
00023 {
00024  public:
00025   //: put cnt samples into output vector wrt given probabilities
00026   //  The sum of probabilities should sum to 1 otherwise return false
00027   static bool sample(vcl_vector<T>& samples, vcl_vector<float>& p,
00028                      unsigned cnt, vcl_vector<T>& out);
00029 
00030   //: put cnt samples into output vector wrt given probabilities
00031   //  The sum of probabilities should sum to 1 otherwise return false.
00032   //  User provides seeded random generator
00033   static bool sample(vcl_vector<T>& samples, vcl_vector<float>& p,
00034                      unsigned cnt, vcl_vector<T>& out, vnl_random &rng);
00035 
00036   //: sample from a joint histogram treating it as a discrete prob distribution
00037   static bool sample(const bsta_joint_histogram<float>& jh, unsigned cnt, vcl_vector<vcl_pair<float, float> >& out);
00038 
00039   //: sample from a joint histogram treating it as a discrete prob distribution
00040   // User provides seeded random generator
00041   static bool sample(const bsta_joint_histogram<float>& jh, unsigned cnt, vcl_vector<vcl_pair<float, float> >& out, vnl_random &rng);
00042 
00043   //: sample in the decreasing order of likelihood (i.e. the most likely bin will be returned as the first sample)
00044   static bool sample_in_likelihood_order(const bsta_joint_histogram<float>& jh, unsigned cnt, vcl_vector<vcl_pair<float, float> >& out);
00045 
00046   //: sample in the decreasing order of likelihood (i.e. the most likely bin will be returned as the first sample)
00047   static bool sample_in_likelihood_order(const bsta_joint_histogram<float>& jh, unsigned cnt, vcl_vector<vcl_pair<unsigned, unsigned> >& out_indices);
00048 };
00049 
00050 #endif // bsta_sampler_h_