contrib/mul/msm/msm_param_limiter.h
Go to the documentation of this file.
00001 #ifndef msm_param_limiter_h_
00002 #define msm_param_limiter_h_
00003 //:
00004 // \file
00005 // \author Tim Cootes
00006 // \brief Base for objects with apply limits to parameters
00007 
00008 #include <vcl_string.h>
00009 #include <vcl_memory.h>
00010 #include <vcl_iosfwd.h>
00011 #include <vsl/vsl_fwd.h>
00012 #include <vnl/vnl_fwd.h>
00013 
00014 //: Base for objects with apply limits to parameters.
00015 //  Derived classes implement apply_limit(b) function, which applies
00016 //  constraints to vector b based on variances.
00017 class msm_param_limiter
00018 {
00019  public:
00020 
00021   virtual ~msm_param_limiter() {}
00022 
00023   //: Define variance on each parameter
00024   virtual void set_param_var(const vnl_vector<double>& v)=0;
00025 
00026   //: Set the limits so that a given proportion pass
00027   //  Where the parameters are described by a pdf, choose
00028   //  limits so that on average a proportion prop (in [0,1])
00029   //  are acceptable when using n_modes modes. If n_modes==0,
00030   //  then assume all available modes to be used.
00031   virtual void set_acceptance(double prop, unsigned n_modes=0) = 0;
00032 
00033   //: Apply limit to parameter vector b
00034   virtual void apply_limit(vnl_vector<double>& b) const = 0;
00035 
00036   //: Name of the class
00037   virtual vcl_string is_a() const = 0;
00038 
00039   //: Create a copy on the heap and return base class pointer
00040   virtual msm_param_limiter* clone() const = 0;
00041 
00042   //: Print class to os
00043   virtual void print_summary(vcl_ostream& os) const=0;
00044 
00045   //: Save class to binary file stream
00046   virtual void b_write(vsl_b_ostream& bfs) const = 0;
00047 
00048   //: Load class from binary file stream
00049   virtual void b_read(vsl_b_istream& bfs) = 0;
00050 
00051   //: Create a concrete msm_param_limiter-derived object, from a text specification.
00052   static vcl_auto_ptr<msm_param_limiter> create_from_stream(vcl_istream &is);
00053 
00054   //: Initialise from a text stream.
00055   // The default implementation is for attribute-less normalisers,
00056   // and throws if it finds any data in the stream.
00057   virtual void config_from_stream(vcl_istream &is);
00058 };
00059 
00060 //: Allows derived class to be loaded by base-class pointer
00061 //  A loader object exists which is invoked by calls
00062 //  of the form "vsl_b_read(bfs,base_ptr);".  This loads derived class
00063 //  objects from the disk, places them on the heap and
00064 //  returns a base class pointer.
00065 //  In order to work the loader object requires
00066 //  an instance of each derived class that might be
00067 //  found.  This function gives the model class to
00068 //  the appropriate loader.
00069 void vsl_add_to_binary_loader(const msm_param_limiter& b);
00070 
00071 //: Binary file stream output operator for class reference
00072 void vsl_b_write(vsl_b_ostream& bfs, const msm_param_limiter& b);
00073 
00074 //: Binary file stream input operator for class reference
00075 void vsl_b_read(vsl_b_istream& bfs, msm_param_limiter& b);
00076 
00077 //: Stream output operator for class reference
00078 vcl_ostream& operator<<(vcl_ostream& os,const msm_param_limiter& b);
00079 
00080 //: Stream output operator for class pointer
00081 vcl_ostream& operator<<(vcl_ostream& os,const msm_param_limiter* b);
00082 
00083 //: Stream output operator for class reference
00084 void vsl_print_summary(vcl_ostream& os,const msm_param_limiter& b);
00085 
00086 //: Stream output operator for class reference
00087 void vsl_print_summary(vcl_ostream& os,const msm_param_limiter* b);
00088 
00089 
00090 //: Returns X such that P(chi<X | dof==n)==p
00091 // The value of Chi-Squared such that the probability
00092 // that a random variable drawn from a chi-2 distribution
00093 // is less than Chi_Squared is p.
00094 // \param p  Target probability
00095 // \param n  Number of dimensions
00096 // \param tol  Tolerance of result (default = 0.001)
00097 double msm_chi2_for_cum_prob(double p, int n, double tol=0.001);
00098 
00099 #endif // msm_param_limiter_h_
00100 
00101