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