contrib/mul/vpdfl/vpdfl_gaussian_builder.h
Go to the documentation of this file.
00001 // This is mul/vpdfl/vpdfl_gaussian_builder.h
00002 #ifndef vpdfl_gaussian_builder_h
00003 #define vpdfl_gaussian_builder_h
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Builders for Multi-variate gaussian PDF with arbitrary axes.
00010 // \author Tim Cootes
00011 // \date 16-Oct-98
00012 // \verbatim
00013 //  Modifications
00014 //   IMS   Converted to VXL 18 April 2000
00015 // \endverbatim
00016 //=======================================================================
00017 
00018 #include <vpdfl/vpdfl_builder_base.h>
00019 #include <vnl/vnl_fwd.h>
00020 #include <vcl_iosfwd.h>
00021 
00022 //=======================================================================
00023 
00024 class vpdfl_gaussian;
00025 
00026 //: Class to build vpdfl_gaussian objects
00027 class vpdfl_gaussian_builder : public vpdfl_builder_base
00028 {
00029   double min_var_;
00030 
00031   vpdfl_gaussian& gaussian(vpdfl_pdf_base& model) const;
00032 
00033  protected:
00034 
00035   //: Add w*v*v.transpose() to S (resizing if necessary)
00036   // By repeatedly calling this function with a new vector v and weight w
00037   // You can calculate the Sum of Squares matrix.
00038   void updateCovar(vnl_matrix<double>& S, const vnl_vector<double>& v, double w) const;
00039 
00040  public:
00041 
00042   //: Dflt ctor
00043   vpdfl_gaussian_builder();
00044 
00045   //: Destructor
00046   virtual ~vpdfl_gaussian_builder();
00047 
00048   //: Create empty model
00049   virtual vpdfl_pdf_base* new_model() const;
00050 
00051   //: Define lower threshold on variance for built models
00052   virtual void set_min_var(double min_var);
00053 
00054   //: Get lower threshold on variance for built models
00055   virtual double min_var() const;
00056 
00057   //: Build default model with given mean
00058   virtual void build(vpdfl_pdf_base& model,
00059                      const vnl_vector<double>& mean) const;
00060 
00061   //: Build model from data
00062   virtual void build(vpdfl_pdf_base& model,
00063                      mbl_data_wrapper<vnl_vector<double> >& data) const;
00064 
00065   //: Build model from weighted data
00066   virtual void weighted_build(vpdfl_pdf_base& model,
00067                               mbl_data_wrapper<vnl_vector<double> >& data,
00068                               const vcl_vector<double>& wts) const;
00069 
00070   //: Computes mean and covariance of given data
00071   void meanCovar(vnl_vector<double>& mean, vnl_matrix<double>& covar,
00072                  mbl_data_wrapper<vnl_vector<double> >& data) const;
00073 
00074   //: Build model from mean and covariance
00075   void buildFromCovar(vpdfl_gaussian& model,
00076                       const vnl_vector<double>& mean,
00077                       const vnl_matrix<double>& covar) const;
00078 
00079   //: Version number for I/O
00080   short version_no() const;
00081 
00082   //: Name of the class
00083   virtual vcl_string is_a() const;
00084 
00085   //: Does the name of the class match the argument?
00086   virtual bool is_class(vcl_string const&) const;
00087 
00088   //: Create a copy on the heap and return base class pointer
00089   virtual vpdfl_builder_base* clone() const;
00090 
00091   //: Print class to os
00092   virtual void print_summary(vcl_ostream& os) const;
00093 
00094   //: Save class to binary file stream
00095   virtual void b_write(vsl_b_ostream& bfs) const;
00096 
00097   //: Load class from binary file stream
00098   virtual void b_read(vsl_b_istream& bfs);
00099 
00100   //: Read initialisation settings from a stream.
00101   // Parameters:
00102   // \verbatim
00103   // {
00104   //   min_var: 1.0e-6
00105   // }
00106   // \endverbatim
00107   // \throw mbl_exception_parse_error if the parse fails.
00108   virtual void config_from_stream(vcl_istream & is);
00109 
00110 };
00111 
00112 #endif // vpdfl_gaussian_builder_h