contrib/mul/pdf1d/pdf1d_compare_to_pdf.h
Go to the documentation of this file.
00001 // This is mul/pdf1d/pdf1d_compare_to_pdf.h
00002 #ifndef pdf1d_compare_to_pdf_h
00003 #define pdf1d_compare_to_pdf_h
00004 
00005 //:
00006 // \file
00007 // \brief Base for classes with test whether data could come from a given pdf.
00008 // \author Tim Cootes
00009 
00010 #include <vsl/vsl_binary_io.h>
00011 #include <vcl_string.h>
00012 #include <pdf1d/pdf1d_pdf.h>
00013 #include <pdf1d/pdf1d_builder.h>
00014 #include <vnl/vnl_fwd.h>
00015 #include <mbl/mbl_cloneable_ptr.h>
00016 
00017 //=======================================================================
00018 
00019 //: Base for classes with test whether data could come from a given pdf.
00020 // Functions are available to test whether a set of samples are likely
00021 // to have been drawn from either a particular distribution or a given
00022 // form of distribution.
00023 class pdf1d_compare_to_pdf
00024 {
00025  protected:
00026   //: Workspace for PDFs
00027   mbl_cloneable_ptr<pdf1d_pdf> pdf_;
00028  public:
00029 
00030   //: Dflt ctor
00031   pdf1d_compare_to_pdf();
00032 
00033   //: Destructor
00034   virtual ~pdf1d_compare_to_pdf();
00035 
00036   //: Test whether data came from the given distribution
00037   virtual double compare(const double* data, int n, const pdf1d_pdf& pdf) =0;
00038 
00039   //: Test whether data came from the given distribution, using bootstrap
00040   //  Repeatedly resamples n values from data[0..n-1] and compares with
00041   //  the given pdf.  Individual comparisons are returned in B.
00042   //  \return Mean of B
00043   virtual double bootstrap_compare(vnl_vector<double>& B,
00044                                    const double* data, int n,
00045                                    const pdf1d_pdf& pdf, int n_trials);
00046 
00047   //: Test whether data has form of the given distribution
00048   //  Default behaviour is to build pdf from data and then compare data with pdf
00049   virtual double compare_form(const double* data, int n,
00050                               const pdf1d_builder& builder);
00051 
00052   //: Test whether data has form of the given distribution
00053   //  Repeatedly resamples n values from data[0..n-1] and
00054   //  calls compare_form().
00055   //  Individual comparisons are returned in B.
00056   //  \return Mean of B
00057   virtual double bootstrap_compare_form(vnl_vector<double>& B,
00058                               const double* data, int n,
00059                               const pdf1d_builder& builder, int n_trials);
00060 
00061   //: Version number for I/O
00062   short version_no() const;
00063 
00064   //: Name of the class
00065   virtual vcl_string is_a() const;
00066 
00067   //: Does the name of the class match the argument?
00068   virtual bool is_class(vcl_string const& s) const;
00069 
00070   //: Create a copy on the heap and return base class pointer
00071   virtual pdf1d_compare_to_pdf* clone() const = 0;
00072 
00073   //: Print class to os
00074   virtual void print_summary(vcl_ostream& os) const = 0;
00075 
00076   //: Save class to binary file stream
00077   virtual void b_write(vsl_b_ostream& bfs) const = 0;
00078 
00079   //: Load class from binary file stream
00080   virtual void b_read(vsl_b_istream& bfs) = 0;
00081 };
00082 
00083 //: Allows derived class to be loaded by base-class pointer
00084 //  A loader object exists which is invoked by calls
00085 //  of the form "bfs>>base_ptr;".  This loads derived class
00086 //  objects from the disk, places them on the heap and
00087 //  returns a base class pointer.
00088 //  In order to work the loader object requires
00089 //  an instance of each derived class that might be
00090 //  found.  This function gives the model class to
00091 //  the appropriate loader.
00092 void vsl_add_to_binary_loader(const pdf1d_compare_to_pdf& b);
00093 
00094 //: Binary file stream output operator for class reference
00095 void vsl_b_write(vsl_b_ostream& bfs, const pdf1d_compare_to_pdf& b);
00096 
00097 //: Binary file stream input operator for class reference
00098 void vsl_b_read(vsl_b_istream& bfs, pdf1d_compare_to_pdf& b);
00099 
00100 //: Stream output operator for class reference
00101 void vsl_print_summary(vcl_ostream& os,const pdf1d_compare_to_pdf& b);
00102 
00103 //: Stream output operator for class pointer
00104 void vsl_print_summary(vcl_ostream& os,const pdf1d_compare_to_pdf* b);
00105 
00106 //: Stream output operator for class reference
00107 vcl_ostream& operator<<(vcl_ostream& os,const pdf1d_compare_to_pdf& b);
00108 
00109 //: Stream output operator for class pointer
00110 vcl_ostream& operator<<(vcl_ostream& os,const pdf1d_compare_to_pdf* b);
00111 
00112 #endif // pdf1d_compare_to_pdf_h