00001 // This is mul/vpdfl/vpdfl_axis_gaussian.h 00002 #ifndef vpdfl_axis_gaussian_h 00003 #define vpdfl_axis_gaussian_h 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief Multi-variate Gaussian PDF, with a diagonal covariance matrix 00010 // \author Tim Cootes 00011 // \date 12-Apr-2001 00012 // \verbatim 00013 // Modifications 00014 // 19 April 2001 IMS - Moved sampling functionality into a sampler class 00015 // 20 April 2001 IMS - Implemented log_prob_thresh() 00016 // 20 April 2001 IMS - Implemented log_p_min in nearest_plausible 00017 // \endverbatim 00018 00019 #include <vpdfl/vpdfl_pdf_base.h> 00020 #include <vcl_iosfwd.h> 00021 00022 //: Multi-variate Gaussian PDF, with a diagonal covariance matrix 00023 class vpdfl_axis_gaussian : public vpdfl_pdf_base 00024 { 00025 double log_k_; 00026 vnl_vector<double> sd_; 00027 00028 void calcLogK(); 00029 void calcSD(); 00030 00031 //: Calculate (x-mu)' * Sigma^-1 * (x-mu) 00032 double dx_sigma_dx(const vnl_vector<double> &x) const; 00033 00034 public: 00035 00036 // Dflt ctor 00037 vpdfl_axis_gaussian(); 00038 00039 // Destructor 00040 virtual ~vpdfl_axis_gaussian(); 00041 00042 void set(const vnl_vector<double>& mean, const vnl_vector<double>& var); 00043 00044 //: Constant offset for log probability 00045 double log_k() const { return log_k_; } 00046 00047 //: SD for each dimension 00048 const vnl_vector<double>& sd() const { return sd_; } 00049 00050 //: Log of probability density at x 00051 virtual double log_p(const vnl_vector<double>& x) const; 00052 00053 //: Gradient and value of PDF at x 00054 // Computes gradient of PDF at x, and returns the prob at x in p 00055 virtual void gradient(vnl_vector<double>& g, 00056 const vnl_vector<double>& x, 00057 double& p) const; 00058 00059 //: Gradient and value of log(p(x)) at x 00060 // Computes gradient df/dx of f(x)=log(p(x)) at x. 00061 // Result is vector of same dimensionality as x. 00062 virtual void gradient_logp(vnl_vector<double>& g, 00063 const vnl_vector<double>& x) const; 00064 00065 //: Create a sampler object on the heap 00066 // Caller is responsible for deletion. 00067 virtual vpdfl_sampler_base* new_sampler() const; 00068 00069 //: Compute threshold for PDF to pass a given proportion 00070 virtual double log_prob_thresh(double pass_proportion) const; 00071 00072 //: Compute nearest point to x which has a density above a threshold 00073 // If log_p(x)>log_p_min then x unchanged. Otherwise x is moved 00074 // directly towards the mean (i.e. to the nearest plausible point using a 00075 // Mahalanobis distance) until log_p(x)=log_p_min. 00076 // \param x This may be modified to the nearest plausible position. 00077 // \param log_p_min lower threshold for log_p(x) 00078 virtual void nearest_plausible(vnl_vector<double>& x, double log_p_min) const; 00079 00080 //: Version number for I/O 00081 short version_no() const; 00082 00083 //: Name of the class 00084 virtual vcl_string is_a() const; 00085 00086 //: Does the name of the class match the argument? 00087 virtual bool is_class(vcl_string const& s) const; 00088 00089 //: Create a copy on the heap and return base class pointer. 00090 // Caller is responsible for deletion 00091 virtual vpdfl_pdf_base* clone() const; 00092 00093 //: Print class to os 00094 virtual void print_summary(vcl_ostream& os) const; 00095 00096 //: Save class to binary file stream 00097 virtual void b_write(vsl_b_ostream& bfs) const; 00098 00099 //: Load class from binary file stream 00100 virtual void b_read(vsl_b_istream& bfs); 00101 }; 00102 00103 #endif // vpdfl_axis_gaussian_h