00001 // This is mul/vpdfl/vpdfl_sampler_base.h 00002 #ifndef vpdfl_sampler_base_h 00003 #define vpdfl_sampler_base_h 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \author Ian Scott 00010 // \date 19-Apr-2001 00011 // \brief Base class for Multi-Variate random sampler classes. 00012 00013 #include <vnl/vnl_vector.h> 00014 #include <vcl_string.h> 00015 #include <vcl_vector.h> 00016 #include <vcl_iosfwd.h> 00017 00018 //======================================================================= 00019 00020 class vpdfl_pdf_base; 00021 00022 //: Base class for Multi-Variate Random Sampler classes. 00023 // This is really a multivariate random number generator whose 00024 // outputs have the PDF of the relevant vpdfl_pdf_base. 00025 // Sampler objects should only exist as long as their pdf object, 00026 // and are not meant to be persistent. 00027 00028 class vpdfl_sampler_base 00029 { 00030 protected: 00031 const vpdfl_pdf_base *pdf_model_; 00032 public: 00033 00034 // Dflt ctor 00035 vpdfl_sampler_base(); 00036 00037 // Destructor 00038 virtual ~vpdfl_sampler_base(); 00039 00040 //: PDF of which this is an instance 00041 const vpdfl_pdf_base& model() const; 00042 00043 //: Set model for which this is an instance 00044 virtual void set_model(const vpdfl_pdf_base&); 00045 00046 //: Draw random sample from distribution 00047 virtual void sample(vnl_vector<double>& x)=0; 00048 00049 //: Fill x with samples drawn from distribution 00050 virtual void get_samples(vcl_vector<vnl_vector<double> >& x); 00051 00052 //: Fill x with samples possibly chosen so as to represent the distribution 00053 // Generate a set of pseudo-random samples, chosen so as to be suitable 00054 // to represent the distribution. This is meant to be used for estimating 00055 // continuous integrals with sampled approximations. Where there are 00056 // multiple peaks (e.g. kernel or mixture models), it is preferred that 00057 // the number of samples from each component is roughly proportional 00058 // to the weight for the component. When small numbers are requested, 00059 // this can be done explicitly. 00060 // The default is simply to call sample() for each element of x 00061 virtual void regular_samples(vcl_vector<vnl_vector<double> >& x); 00062 00063 //: Fill x with samples possibly chosen so as to represent the distribution 00064 // As regular_samples(x), but p[i] is set to p(x[i]) 00065 virtual void regular_samples_and_prob(vcl_vector<vnl_vector<double> >& x, 00066 vnl_vector<double>& p); 00067 00068 //: Reseeds the internal random number generator 00069 // To achieve quasi-random initialisation use; 00070 // \code 00071 // #include <vcl_ctime.h> 00072 // .. 00073 // sampler.reseed(vcl_time(0)); 00074 // \endcode 00075 virtual void reseed(unsigned long)=0; 00076 00077 00078 //: Name of the class 00079 virtual vcl_string is_a() const; 00080 00081 //: Does the name of the class match the argument? 00082 virtual bool is_class(vcl_string const& s) const; 00083 00084 //: Create a copy on the heap and return base class pointer 00085 virtual vpdfl_sampler_base* clone() const = 0; 00086 00087 //: Print class to os 00088 virtual void print_summary(vcl_ostream& os) const; 00089 }; 00090 00091 00092 //: Stream output operator for class reference 00093 void vsl_print_summary(vcl_ostream& os,const vpdfl_sampler_base& b); 00094 00095 //: Stream output operator for class pointer 00096 void vsl_print_summary(vcl_ostream& os,const vpdfl_sampler_base* b); 00097 00098 00099 #endif // vpdfl_sampler_base_h