00001 #ifndef msm_ellipsoid_limiter_h_ 00002 #define msm_ellipsoid_limiter_h_ 00003 //: 00004 // \file 00005 // \author Tim Cootes 00006 // \brief Force param.s to lie in ellipsoid defined by variances. 00007 00008 #include <msm/msm_param_limiter.h> 00009 #include <vnl/vnl_vector.h> 00010 #include <vcl_iosfwd.h> 00011 00012 //: Force param.s to lie in ellipsoid defined by variances. 00013 // An axis aligned ellipsoid is defined by the variances along 00014 // each dimension and the n_sds parameter. 00015 // If the supplied vector b is outside this ellipsoid, 00016 // b is set to the nearest point on the surface of 00017 // the ellipsoid. 00018 class msm_ellipsoid_limiter : public msm_param_limiter 00019 { 00020 private: 00021 //: Var. on each mode 00022 vnl_vector<double> mode_var_; 00023 00024 //: Max. allowed mahalanobis distance. 00025 double M_max_; 00026 00027 //: Proportion of Gaussian to be accepted 00028 // Used to set M_max when mode_var defined. 00029 double accept_prop_; 00030 00031 public: 00032 00033 msm_ellipsoid_limiter(); 00034 00035 virtual ~msm_ellipsoid_limiter() {} 00036 00037 //: Define variance on each parameter 00038 virtual void set_param_var(const vnl_vector<double>& v); 00039 00040 //: Set the limits so that a given proportion pass 00041 // Where the parameters are described by a pdf, choose 00042 // limits so that on average a proportion prop (in [0,1]) 00043 // are acceptable when using n_modes modes. If n_modes==0, 00044 // then assume all available modes to be used. 00045 virtual void set_acceptance(double prop, unsigned n_modes=0); 00046 00047 //: Apply limit to parameter vector b 00048 virtual void apply_limit(vnl_vector<double>& b) const; 00049 00050 //: Define number of SDs to limit at 00051 void set_n_sds(double n_sds); 00052 00053 //: Return square of Mahalanobis distance to origin 00054 double mahalanobis(const vnl_vector<double>& b) const; 00055 00056 //: Given initial b on ellipsoid, move on surface towards y 00057 // Finds closest point to y in tangent plane at initial b 00058 // Replaces b with normalised version of this. 00059 // Returns square of length of movement relative to smallest 00060 // mode variance. 00061 double slide_closer(vnl_vector<double>& b, 00062 const vnl_vector<double>& y) const; 00063 00064 //: Name of the class 00065 virtual vcl_string is_a() const; 00066 00067 //: Create a copy on the heap and return base class pointer 00068 virtual msm_param_limiter* clone() const; 00069 00070 //: Print class to os 00071 virtual void print_summary(vcl_ostream& os) const; 00072 00073 //: Save class to binary file stream 00074 virtual void b_write(vsl_b_ostream& bfs) const; 00075 00076 //: Load class from binary file stream 00077 virtual void b_read(vsl_b_istream& bfs); 00078 00079 //: Initialise from a text stream. 00080 // The default implementation is for attribute-less normalisers, 00081 // and throws if it finds any data in the stream. 00082 virtual void config_from_stream(vcl_istream &is); 00083 }; 00084 00085 #endif // msm_ellipsoid_limiter_h_